creation_sourcecode: {"Address.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.2;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies in extcodesize, which returns 0 for contracts in\n        // construction, since the code is only stored at the end of the\n        // constructor execution.\n\n        uint256 size;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { size := extcodesize(account) }\n        return size \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity\u0027s `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n        (bool success, ) = recipient.call{ value: amount }(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain`call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n      return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        return _functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        return _functionCallWithValue(target, data, value, errorMessage);\n    }\n\n    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {\n        require(isContract(target), \"Address: call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length \u003e 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}"},"AttoDecimal.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.6.12;\n\nimport \"./SafeMath.sol\";\n\nlibrary AttoDecimal {\n    using SafeMath for uint256;\n\n    struct Instance {\n        uint256 mantissa;\n    }\n\n    uint256 internal constant BASE = 10;\n    uint256 internal constant EXPONENTIATION = 18;\n    uint256 internal constant ONE_MANTISSA = BASE**EXPONENTIATION;\n    uint256 internal constant ONE_TENTH_MANTISSA = ONE_MANTISSA / 10;\n    uint256 internal constant HALF_MANTISSA = ONE_MANTISSA / 2;\n    uint256 internal constant SQUARED_ONE_MANTISSA = ONE_MANTISSA * ONE_MANTISSA;\n    uint256 internal constant MAX_INTEGER = uint256(-1) / ONE_MANTISSA;\n\n    function maximum() internal pure returns (Instance memory) {\n        return Instance({mantissa: uint256(-1)});\n    }\n\n    function zero() internal pure returns (Instance memory) {\n        return Instance({mantissa: 0});\n    }\n\n    function one() internal pure returns (Instance memory) {\n        return Instance({mantissa: ONE_MANTISSA});\n    }\n\n    function convert(uint256 integer) internal pure returns (Instance memory) {\n        return Instance({mantissa: integer.mul(ONE_MANTISSA)});\n    }\n\n    function compare(Instance memory a, Instance memory b) internal pure returns (int8) {\n        if (a.mantissa \u003c b.mantissa) return -1;\n        return int8(a.mantissa \u003e b.mantissa ? 1 : 0);\n    }\n\n    function compare(Instance memory a, uint256 b) internal pure returns (int8) {\n        return compare(a, convert(b));\n    }\n\n    function add(Instance memory a, Instance memory b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.add(b.mantissa)});\n    }\n\n    function add(Instance memory a, uint256 b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.add(b.mul(ONE_MANTISSA))});\n    }\n\n    function sub(Instance memory a, Instance memory b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.sub(b.mantissa)});\n    }\n\n    function sub(Instance memory a, uint256 b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.sub(b.mul(ONE_MANTISSA))});\n    }\n\n    function sub(uint256 a, Instance memory b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mul(ONE_MANTISSA).sub(b.mantissa)});\n    }\n\n    function mul(Instance memory a, Instance memory b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.mul(b.mantissa) / ONE_MANTISSA});\n    }\n\n    function mul(Instance memory a, uint256 b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.mul(b)});\n    }\n\n    function div(Instance memory a, Instance memory b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.mul(ONE_MANTISSA).div(b.mantissa)});\n    }\n\n    function div(Instance memory a, uint256 b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.mul(ONE_MANTISSA).div(b)});\n    }\n\n    function div(uint256 a, Instance memory b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mul(SQUARED_ONE_MANTISSA).div(b.mantissa)});\n    }\n\n    function div(uint256 a, uint256 b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mul(ONE_MANTISSA).div(b)});\n    }\n\n    function idiv(Instance memory a, Instance memory b) internal pure returns (uint256) {\n        return a.mantissa.div(b.mantissa);\n    }\n\n    function idiv(Instance memory a, uint256 b) internal pure returns (uint256) {\n        return a.mantissa.div(b.mul(ONE_MANTISSA));\n    }\n\n    function idiv(uint256 a, Instance memory b) internal pure returns (uint256) {\n        return a.mul(ONE_MANTISSA).div(b.mantissa);\n    }\n\n    function mod(Instance memory a, Instance memory b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.mod(b.mantissa)});\n    }\n\n    function mod(Instance memory a, uint256 b) internal pure returns (Instance memory) {\n        return Instance({mantissa: a.mantissa.mod(b.mul(ONE_MANTISSA))});\n    }\n\n    function mod(uint256 a, Instance memory b) internal pure returns (Instance memory) {\n        if (a \u003e MAX_INTEGER) return Instance({mantissa: a.mod(b.mantissa).mul(ONE_MANTISSA) % b.mantissa});\n        return Instance({mantissa: a.mul(ONE_MANTISSA).mod(b.mantissa)});\n    }\n\n    function floor(Instance memory a) internal pure returns (uint256) {\n        return a.mantissa / ONE_MANTISSA;\n    }\n\n    function ceil(Instance memory a) internal pure returns (uint256) {\n        return (a.mantissa / ONE_MANTISSA) + (a.mantissa % ONE_MANTISSA \u003e 0 ? 1 : 0);\n    }\n\n    function round(Instance memory a) internal pure returns (uint256) {\n        return (a.mantissa / ONE_MANTISSA) + ((a.mantissa / ONE_TENTH_MANTISSA) % 10 \u003e= 5 ? 1 : 0);\n    }\n\n    function eq(Instance memory a, Instance memory b) internal pure returns (bool) {\n        return a.mantissa == b.mantissa;\n    }\n\n    function eq(Instance memory a, uint256 b) internal pure returns (bool) {\n        if (b \u003e MAX_INTEGER) return false;\n        return a.mantissa == b * ONE_MANTISSA;\n    }\n\n    function gt(Instance memory a, Instance memory b) internal pure returns (bool) {\n        return a.mantissa \u003e b.mantissa;\n    }\n\n    function gt(Instance memory a, uint256 b) internal pure returns (bool) {\n        if (b \u003e MAX_INTEGER) return false;\n        return a.mantissa \u003e b * ONE_MANTISSA;\n    }\n\n    function gte(Instance memory a, Instance memory b) internal pure returns (bool) {\n        return a.mantissa \u003e= b.mantissa;\n    }\n\n    function gte(Instance memory a, uint256 b) internal pure returns (bool) {\n        if (b \u003e MAX_INTEGER) return false;\n        return a.mantissa \u003e= b * ONE_MANTISSA;\n    }\n\n    function lt(Instance memory a, Instance memory b) internal pure returns (bool) {\n        return a.mantissa \u003c b.mantissa;\n    }\n\n    function lt(Instance memory a, uint256 b) internal pure returns (bool) {\n        if (b \u003e MAX_INTEGER) return true;\n        return a.mantissa \u003c b * ONE_MANTISSA;\n    }\n\n    function lte(Instance memory a, Instance memory b) internal pure returns (bool) {\n        return a.mantissa \u003c= b.mantissa;\n    }\n\n    function lte(Instance memory a, uint256 b) internal pure returns (bool) {\n        if (b \u003e MAX_INTEGER) return true;\n        return a.mantissa \u003c= b * ONE_MANTISSA;\n    }\n\n    function isInteger(Instance memory a) internal pure returns (bool) {\n        return a.mantissa % ONE_MANTISSA == 0;\n    }\n\n    function isPositive(Instance memory a) internal pure returns (bool) {\n        return a.mantissa \u003e 0;\n    }\n\n    function isZero(Instance memory a) internal pure returns (bool) {\n        return a.mantissa == 0;\n    }\n\n    function sum(Instance[] memory array) internal pure returns (Instance memory result) {\n        uint256 length = array.length;\n        for (uint256 index = 0; index \u003c length; index++) result = add(result, array[index]);\n    }\n\n    function toTuple(Instance memory a)\n        internal\n        pure\n        returns (\n            uint256 mantissa,\n            uint256 base,\n            uint256 exponentiation\n        )\n    {\n        return (a.mantissa, BASE, EXPONENTIATION);\n    }\n}"},"Context.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address payable) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes memory) {\n        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n        return msg.data;\n    }\n}"},"ERC20.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\nimport \"./Context.sol\";\nimport \"./IERC20.sol\";\nimport \"./SafeMath.sol\";\nimport \"./Address.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin guidelines: functions revert instead\n * of returning `false` on failure. This behavior is nonetheless conventional\n * and does not conflict with the expectations of ERC20 applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn\u0027t required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20 {\n    using SafeMath for uint256;\n    using Address for address;\n\n    mapping (address =\u003e uint256) private _balances;\n\n    mapping (address =\u003e mapping (address =\u003e uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n    uint8 private _decimals;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with\n     * a default value of 18.\n     *\n     * To select a different value for {decimals}, use {_setupDecimals}.\n     *\n     * All three of these values are immutable: they can only be set once during\n     * construction.\n     */\n    constructor (string memory name, string memory symbol) public {\n        _name = name;\n        _symbol = symbol;\n        _decimals = 18;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5,05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is\n     * called.\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view returns (uint8) {\n        return _decimals;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `recipient` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n        _transfer(_msgSender(), recipient, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        _approve(_msgSender(), spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20};\n     *\n     * Requirements:\n     * - `sender` and `recipient` cannot be the zero address.\n     * - `sender` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``sender``\u0027s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {\n        _transfer(sender, recipient, amount);\n        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, \"ERC20: transfer amount exceeds allowance\"));\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, \"ERC20: decreased allowance below zero\"));\n        return true;\n    }\n\n    /**\n     * @dev Moves tokens `amount` from `sender` to `recipient`.\n     *\n     * This is internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `sender` cannot be the zero address.\n     * - `recipient` cannot be the zero address.\n     * - `sender` must have a balance of at least `amount`.\n     */\n    function _transfer(address sender, address recipient, uint256 amount) internal virtual {\n        require(sender != address(0), \"ERC20: transfer from the zero address\");\n        require(recipient != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(sender, recipient, amount);\n\n        _balances[sender] = _balances[sender].sub(amount, \"ERC20: transfer amount exceeds balance\");\n        _balances[recipient] = _balances[recipient].add(amount);\n        emit Transfer(sender, recipient, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements\n     *\n     * - `to` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply = _totalSupply.add(amount);\n        _balances[account] = _balances[account].add(amount);\n        emit Transfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        _balances[account] = _balances[account].sub(amount, \"ERC20: burn amount exceeds balance\");\n        _totalSupply = _totalSupply.sub(amount);\n        emit Transfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(address owner, address spender, uint256 amount) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Sets {decimals} to a value other than the default one of 18.\n     *\n     * WARNING: This function should only be called from the constructor. Most\n     * applications that interact with token contracts will not expect\n     * {decimals} to ever change, and may work incorrectly if it does.\n     */\n    function _setupDecimals(uint8 decimals_) internal {\n        _decimals = decimals_;\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``\u0027s tokens\n     * will be to transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``\u0027s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }\n}"},"IERC20.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller\u0027s account to `recipient`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller\u0027s tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender\u0027s allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `sender` to `recipient` using the\n     * allowance mechanism. `amount` is then deducted from the caller\u0027s\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n}"},"Math.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a \u003e= b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a \u003c b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow, so we distribute\n        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);\n    }\n}"},"ReentrancyGuard.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\ncontract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot\u0027s contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler\u0027s defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction\u0027s gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    constructor () internal {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and make it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        // On the first call to nonReentrant, _notEntered will be true\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n\n        _;\n\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n}"},"SafeERC20.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\nimport \"./IERC20.sol\";\nimport \"./SafeMath.sol\";\nimport \"./Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using SafeMath for uint256;\n    using Address for address;\n\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(IERC20 token, address spender, uint256 value) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // \u0027safeIncreaseAllowance\u0027 and \u0027safeDecreaseAllowance\u0027\n        // solhint-disable-next-line max-line-length\n        require((value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).add(value);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity\u0027s return data size checking mechanism, since\n        // we\u0027re implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        if (returndata.length \u003e 0) { // Return data is optional\n            // solhint-disable-next-line max-line-length\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}"},"SafeMath.sol":{"content":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\n/**\n * @dev Wrappers over Solidity\u0027s arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it\u0027s recommended to use it always.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity\u0027s `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c \u003e= a, \"SafeMath: addition overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity\u0027s `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        return sub(a, b, \"SafeMath: subtraction overflow\");\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity\u0027s `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b \u003c= a, errorMessage);\n        uint256 c = a - b;\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity\u0027s `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\n        // benefit is lost if \u0027b\u0027 is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        uint256 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        return div(a, b, \"SafeMath: division by zero\");\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b \u003e 0, errorMessage);\n        uint256 c = a / b;\n        // assert(a == b * c + a % b); // There is no case in which this doesn\u0027t hold\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts when dividing by zero.\n     *\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        return mod(a, b, \"SafeMath: modulo by zero\");\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts with custom message when dividing by zero.\n     *\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b != 0, errorMessage);\n        return a % b;\n    }\n}"},"StakingPool.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"./Math.sol\";\nimport \"./SafeMath.sol\";\nimport \"./ERC20.sol\";\nimport \"./IERC20.sol\";\nimport \"./SafeERC20.sol\";\nimport \"./ReentrancyGuard.sol\";\nimport \"./AttoDecimal.sol\";\nimport \"./TwoStageOwnable.sol\";\n\ncontract StakingPool is ERC20, ReentrancyGuard, TwoStageOwnable {\n    using SafeMath for uint256;\n    using SafeERC20 for IERC20;\n    using AttoDecimal for AttoDecimal.Instance;\n\n    struct Strategy {\n        uint256 endsAt;\n        uint256 perSecondReward;\n        uint256 startsAt;\n    }\n\n    struct Unstake {\n        uint256 amount;\n        uint256 applicableAt;\n    }\n\n    uint256 public constant MIN_STAKE_BALANCE = 10**18;\n\n    uint256 public claimingFeePercent;\n    uint256 public lastUpdatedAt;\n\n    uint256 private _feePool;\n    uint256 private _lockedRewards;\n    uint256 private _totalStaked;\n    uint256 private _totalUnstaked;\n    uint256 private _unstakingTime;\n    IERC20 private _stakingToken;\n\n    AttoDecimal.Instance private _defaultPrice;\n    AttoDecimal.Instance private _price;\n    Strategy private _currentStrategy;\n    Strategy private _nextStrategy;\n\n    mapping(address =\u003e Unstake) private _unstakes;\n\n    function getTimestamp() internal view virtual returns (uint256) {\n        return block.timestamp;\n    }\n\n    function feePool() public view returns (uint256) {\n        return _feePool;\n    }\n\n    function lockedRewards() public view returns (uint256) {\n        return _lockedRewards;\n    }\n\n    function totalStaked() public view returns (uint256) {\n        return _totalStaked;\n    }\n\n    function totalUnstaked() public view returns (uint256) {\n        return _totalUnstaked;\n    }\n\n    function stakingToken() public view returns (IERC20) {\n        return _stakingToken;\n    }\n\n    function unstakingTime() public view returns (uint256) {\n        return _unstakingTime;\n    }\n\n    function currentStrategy() public view returns (Strategy memory) {\n        return _currentStrategy;\n    }\n\n    function nextStrategy() public view returns (Strategy memory) {\n        return _nextStrategy;\n    }\n\n    function getUnstake(address account) public view returns (Unstake memory result) {\n        result = _unstakes[account];\n    }\n\n    function defaultPrice()\n        external\n        view\n        returns (\n            uint256 mantissa,\n            uint256 base,\n            uint256 exponentiation\n        )\n    {\n        return _defaultPrice.toTuple();\n    }\n\n    function getCurrentStrategyUnlockedRewards() public view returns (uint256 unlocked) {\n        unlocked = _getStrategyUnlockedRewards(_currentStrategy);\n    }\n\n    function getUnlockedRewards() public view returns (uint256 unlocked, bool currentStrategyEnded) {\n        unlocked = _getStrategyUnlockedRewards(_currentStrategy);\n        if (getTimestamp() \u003e= _currentStrategy.endsAt) {\n            currentStrategyEnded = true;\n            if (_nextStrategy.endsAt != 0) unlocked = unlocked.add(_getStrategyUnlockedRewards(_nextStrategy));\n        }\n    }\n\n    /// @notice Calculates price of synthetic token for current block\n    function price()\n        public\n        view\n        returns (\n            uint256 mantissa,\n            uint256 base,\n            uint256 exponentiation\n        )\n    {\n        (uint256 unlocked, ) = getUnlockedRewards();\n        uint256 totalStaked_ = _totalStaked;\n        uint256 totalSupply_ = totalSupply();\n        AttoDecimal.Instance memory result = _defaultPrice;\n        if (totalSupply_ \u003e 0) result = AttoDecimal.div(totalStaked_.add(unlocked), totalSupply_);\n        return result.toTuple();\n    }\n\n    /// @notice Returns last updated price of synthetic token\n    function priceStored()\n        public\n        view\n        returns (\n            uint256 mantissa,\n            uint256 base,\n            uint256 exponentiation\n        )\n    {\n        return _price.toTuple();\n    }\n\n    /// @notice Calculates expected result of swapping synthetic tokens for staking tokens\n    /// @param account Account that wants to swap\n    /// @param amount Minimum amount of staking tokens that should be received at swapping process\n    /// @return unstakedAmount Amount of staking tokens that should be received at swapping process\n    /// @return burnedAmount Amount of synthetic tokens that should be burned at swapping process\n    function calculateUnstake(address account, uint256 amount)\n        public\n        view\n        returns (uint256 unstakedAmount, uint256 burnedAmount)\n    {\n        (uint256 mantissa_, , ) = price();\n        return _calculateUnstake(account, amount, AttoDecimal.Instance(mantissa_));\n    }\n\n    event Claimed(\n        address indexed account,\n        uint256 requestedAmount,\n        uint256 claimedAmount,\n        uint256 feeAmount,\n        uint256 burnedAmount\n    );\n\n    event ClaimingFeePercentUpdated(uint256 feePercent);\n    event CurrentStrategyUpdated(uint256 perSecondReward, uint256 startsAt, uint256 endsAt);\n    event FeeClaimed(address indexed receiver, uint256 amount);\n    event NextStrategyUpdated(uint256 perSecondReward, uint256 startsAt, uint256 endsAt);\n    event UnstakingTimeUpdated(uint256 unstakingTime);\n    event NextStrategyRemoved();\n    event PoolDecreased(uint256 amount);\n    event PoolIncreased(address indexed payer, uint256 amount);\n    event PriceUpdated(uint256 mantissa, uint256 base, uint256 exponentiation);\n    event RewardsUnlocked(uint256 amount);\n    event Staked(address indexed account, address indexed payer, uint256 stakedAmount, uint256 mintedAmount);\n    event Unstaked(address indexed account, uint256 requestedAmount, uint256 unstakedAmount, uint256 burnedAmount);\n    event UnstakingCanceled(address indexed account, uint256 amount);\n    event Withdrawed(address indexed account, uint256 amount);\n\n    constructor(\n        string memory syntheticTokenName,\n        string memory syntheticTokenSymbol,\n        IERC20 stakingToken_,\n        address owner_,\n        uint256 claimingFeePercent_,\n        uint256 perSecondReward_,\n        uint256 startsAt_,\n        uint256 duration_,\n        uint256 unstakingTime_,\n        uint256 defaultPriceMantissa\n    ) public TwoStageOwnable(owner_) ERC20(syntheticTokenName, syntheticTokenSymbol) {\n        _defaultPrice = AttoDecimal.Instance(defaultPriceMantissa);\n        _stakingToken = stakingToken_;\n        _setClaimingFeePercent(claimingFeePercent_);\n        _validateStrategyParameters(perSecondReward_, startsAt_, duration_);\n        _setUnstakingTime(unstakingTime_);\n        _setCurrentStrategy(perSecondReward_, startsAt_, startsAt_.add(duration_));\n        lastUpdatedAt = getTimestamp();\n        _price = _defaultPrice;\n    }\n\n    /// @notice Cancels unstaking by staking locked for withdrawals tokens\n    /// @param amount Amount of locked for withdrawals tokens\n    function cancelUnstaking(uint256 amount) external onlyPositiveAmount(amount) returns (bool success) {\n        _update();\n        address caller = msg.sender;\n        Unstake storage unstake_ = _unstakes[caller];\n        uint256 unstakingAmount = unstake_.amount;\n        require(unstakingAmount \u003e= amount, \"Not enough unstaked balance\");\n        uint256 stakedAmount = _price.mul(balanceOf(caller)).floor();\n        require(stakedAmount.add(amount) \u003e= MIN_STAKE_BALANCE, \"Stake balance lt min stake\");\n        uint256 synthAmount = AttoDecimal.div(amount, _price).floor();\n        _mint(caller, synthAmount);\n        _totalStaked = _totalStaked.add(amount);\n        _totalUnstaked = _totalUnstaked.sub(amount);\n        unstake_.amount = unstakingAmount.sub(amount);\n        emit Staked(caller, address(0), amount, synthAmount);\n        emit UnstakingCanceled(caller, amount);\n        return true;\n    }\n\n    /// @notice Swaps synthetic tokens for staking tokens and immediately sends them to the caller but takes some fee\n    /// @param amount Staking tokens amount to swap for. Fee will be taked from this amount\n    /// @return claimedAmount Amount of staking tokens that was been sended to caller\n    /// @return burnedAmount Amount of synthetic tokens that was burned while swapping\n    function claim(uint256 amount)\n        external\n        onlyPositiveAmount(amount)\n        returns (uint256 claimedAmount, uint256 burnedAmount)\n    {\n        _update();\n        address caller = msg.sender;\n        (claimedAmount, burnedAmount) = _calculateUnstake(caller, amount, _price);\n        uint256 fee = claimedAmount.mul(claimingFeePercent).div(100);\n        _burn(caller, burnedAmount);\n        _totalStaked = _totalStaked.sub(claimedAmount);\n        claimedAmount = claimedAmount.sub(fee);\n        _feePool = _feePool.add(fee);\n        emit Claimed(caller, amount, claimedAmount, fee, burnedAmount);\n        _stakingToken.safeTransfer(caller, claimedAmount);\n    }\n\n    /// @notice Withdraws all staking tokens, that have been accumulated in imidiatly claiming process.\n    ///     Allowed to be called only by the owner\n    /// @return amount Amount of accumulated and withdrawed tokens\n    function claimFees() external onlyOwner returns (uint256 amount) {\n        require(_feePool \u003e 0, \"No fees\");\n        amount = _feePool;\n        _feePool = 0;\n        emit FeeClaimed(owner(), amount);\n        _stakingToken.safeTransfer(owner(), amount);\n    }\n\n    /// @notice Creates new strategy. Allowed to be called only by the owner\n    /// @param perSecondReward_ Reward that should be added to common staking tokens pool every second\n    /// @param startsAt_ Timestamp from which strategy should starts\n    /// @param duration_ Seconds count for which new strategy should be applied\n    function createNewStrategy(\n        uint256 perSecondReward_,\n        uint256 startsAt_,\n        uint256 duration_\n    ) public onlyOwner returns (bool success) {\n        _update();\n        _validateStrategyParameters(perSecondReward_, startsAt_, duration_);\n        uint256 endsAt = startsAt_.add(duration_);\n        Strategy memory strategy = Strategy({perSecondReward: perSecondReward_, startsAt: startsAt_, endsAt: endsAt});\n        if (_currentStrategy.startsAt \u003e getTimestamp()) {\n            delete _nextStrategy;\n            emit NextStrategyRemoved();\n            _currentStrategy = strategy;\n            emit CurrentStrategyUpdated(perSecondReward_, startsAt_, endsAt);\n        } else {\n            emit NextStrategyUpdated(perSecondReward_, startsAt_, endsAt);\n            _nextStrategy = strategy;\n            if (_currentStrategy.endsAt \u003e startsAt_) {\n                _currentStrategy.endsAt = startsAt_;\n                emit CurrentStrategyUpdated(_currentStrategy.perSecondReward, _currentStrategy.startsAt, startsAt_);\n            }\n        }\n        return true;\n    }\n\n    function decreasePool(uint256 amount) external onlyPositiveAmount(amount) onlyOwner returns (bool success) {\n        _update();\n        _lockedRewards = _lockedRewards.sub(amount, \"Not enough locked rewards\");\n        emit PoolDecreased(amount);\n        _stakingToken.safeTransfer(owner(), amount);\n        return true;\n    }\n\n    /// @notice Increases pool of rewards\n    /// @param amount Amount of staking tokens (in wei) that should be added to rewards pool\n    function increasePool(uint256 amount) external onlyPositiveAmount(amount) returns (bool success) {\n        _update();\n        address payer = msg.sender;\n        _lockedRewards = _lockedRewards.add(amount);\n        emit PoolIncreased(payer, amount);\n        _stakingToken.safeTransferFrom(payer, address(this), amount);\n        return true;\n    }\n\n    /// @notice Change claiming fee percent. Can be called only by the owner\n    /// @param feePercent New claiming fee percent\n    function setClaimingFeePercent(uint256 feePercent) external onlyOwner returns (bool success) {\n        _setClaimingFeePercent(feePercent);\n        return true;\n    }\n\n    /// @notice Converts staking tokens to synthetic tokens\n    /// @param amount Amount of staking tokens to be swapped\n    /// @return mintedAmount Amount of synthetic tokens that was received at swapping process\n    function stake(uint256 amount) external onlyPositiveAmount(amount) returns (uint256 mintedAmount) {\n        address staker = msg.sender;\n        return _stake(staker, staker, amount);\n    }\n\n    /// @notice Converts staking tokens to synthetic tokens and sends them to specific account\n    /// @param account Receiver of synthetic tokens\n    /// @param amount Amount of staking tokens to be swapped\n    /// @return mintedAmount Amount of synthetic tokens that was received by specified account at swapping process\n    function stakeForUser(address account, uint256 amount)\n        external\n        onlyPositiveAmount(amount)\n        returns (uint256 mintedAmount)\n    {\n        return _stake(account, msg.sender, amount);\n    }\n\n    /// @notice Swapes synthetic tokens for staking tokens and locks them for some period\n    /// @param amount Minimum amount of staking tokens that should be locked after swapping process\n    /// @return unstakedAmount Amount of staking tokens that was locked\n    /// @return burnedAmount Amount of synthetic tokens that was burned\n    function unstake(uint256 amount)\n        external\n        onlyPositiveAmount(amount)\n        returns (uint256 unstakedAmount, uint256 burnedAmount)\n    {\n        _update();\n        address caller = msg.sender;\n        (unstakedAmount, burnedAmount) = _calculateUnstake(caller, amount, _price);\n        _burn(caller, burnedAmount);\n        _totalStaked = _totalStaked.sub(unstakedAmount);\n        _totalUnstaked = _totalUnstaked.add(unstakedAmount);\n        Unstake storage unstake_ = _unstakes[caller];\n        unstake_.amount = unstake_.amount.add(unstakedAmount);\n        unstake_.applicableAt = getTimestamp().add(_unstakingTime);\n        emit Unstaked(caller, amount, unstakedAmount, burnedAmount);\n    }\n\n    /// @notice Updates price of synthetic token\n    /// @dev Automatically has been called on every contract action, that uses or can affect price\n    function update() external returns (bool success) {\n        _update();\n        return true;\n    }\n\n    /// @notice Withdraws unstaked staking tokens\n    function withdraw() external returns (bool success) {\n        address caller = msg.sender;\n        Unstake storage unstake_ = _unstakes[caller];\n        uint256 amount = unstake_.amount;\n        require(amount \u003e 0, \"Not unstaked\");\n        require(unstake_.applicableAt \u003c= getTimestamp(), \"Not released at\");\n        delete _unstakes[caller];\n        _totalUnstaked = _totalUnstaked.sub(amount);\n        emit Withdrawed(caller, amount);\n        _stakingToken.safeTransfer(caller, amount);\n        return true;\n    }\n\n    /// @notice Change unstaking time. Can be called only by the owner\n    /// @param unstakingTime_ New unstaking process duration in seconds\n    function setUnstakingTime(uint256 unstakingTime_) external onlyOwner returns (bool success) {\n        _setUnstakingTime(unstakingTime_);\n        return true;\n    }\n\n    function _getStrategyUnlockedRewards(Strategy memory strategy_) internal view returns (uint256 unlocked) {\n        uint256 timestamp = getTimestamp();\n        if (timestamp \u003c strategy_.startsAt || timestamp == lastUpdatedAt) {\n            return unlocked;\n        }\n        uint256 lastRewardedSecond = Math.max(lastUpdatedAt, strategy_.startsAt);\n        uint256 lastRewardableTimestamp = Math.min(timestamp, strategy_.endsAt);\n        if (lastRewardedSecond \u003c lastRewardableTimestamp) {\n            uint256 timeDiff = lastRewardableTimestamp.sub(lastRewardedSecond);\n            unlocked = unlocked.add(timeDiff.mul(strategy_.perSecondReward));\n        }\n    }\n\n    function _calculateUnstake(\n        address account,\n        uint256 amount,\n        AttoDecimal.Instance memory price_\n    ) internal view returns (uint256 unstakedAmount, uint256 burnedAmount) {\n        unstakedAmount = amount;\n        burnedAmount = AttoDecimal.div(amount, price_).ceil();\n        uint256 balance = balanceOf(account);\n        require(burnedAmount \u003e 0, \"Too small unstaking amount\");\n        require(balance \u003e= burnedAmount, \"Not enough synthetic tokens\");\n        uint256 remainingSyntheticBalance = balance.sub(burnedAmount);\n        uint256 remainingStake = _price.mul(remainingSyntheticBalance).floor();\n        if (remainingStake \u003c 10**18) {\n            burnedAmount = balance;\n            unstakedAmount = unstakedAmount.add(remainingStake);\n        }\n    }\n\n    function _unlockRewardsAndStake() internal {\n        (uint256 unlocked, bool currentStrategyEnded) = getUnlockedRewards();\n        if (currentStrategyEnded) {\n            _currentStrategy = _nextStrategy;\n            emit NextStrategyRemoved();\n            if (_currentStrategy.endsAt != 0) {\n                emit CurrentStrategyUpdated(\n                    _currentStrategy.perSecondReward,\n                    _currentStrategy.startsAt,\n                    _currentStrategy.endsAt\n                );\n            }\n            delete _nextStrategy;\n        }\n        unlocked = Math.min(unlocked, _lockedRewards);\n        if (unlocked \u003e 0) {\n            emit RewardsUnlocked(unlocked);\n            _lockedRewards = _lockedRewards.sub(unlocked);\n            _totalStaked = _totalStaked.add(unlocked);\n        }\n        lastUpdatedAt = getTimestamp();\n    }\n\n    function _update() internal {\n        if (getTimestamp() \u003c= lastUpdatedAt) return;\n        _unlockRewardsAndStake();\n        _updatePrice();\n    }\n\n    function _updatePrice() internal {\n        uint256 totalStaked_ = _totalStaked;\n        uint256 totalSupply_ = totalSupply();\n        if (totalSupply_ == 0) _price = _defaultPrice;\n        else _price = AttoDecimal.div(totalStaked_, totalSupply_);\n        emit PriceUpdated(_price.mantissa, AttoDecimal.BASE, AttoDecimal.EXPONENTIATION);\n    }\n\n    function _validateStrategyParameters(\n        uint256 perSecondReward,\n        uint256 startsAt,\n        uint256 duration\n    ) internal view {\n        require(duration \u003e 0, \"Duration is zero\");\n        require(startsAt \u003e= getTimestamp(), \"Starting timestamp lt current\");\n        require(perSecondReward \u003c= 188 * 10**18, \"Per second reward overflow\");\n    }\n\n    function _setClaimingFeePercent(uint256 feePercent) internal {\n        require(feePercent \u003e= 0 \u0026\u0026 feePercent \u003c= 100, \"Invalid fee percent\");\n        claimingFeePercent = feePercent;\n        emit ClaimingFeePercentUpdated(feePercent);\n    }\n\n    function _setUnstakingTime(uint256 unstakingTime_) internal {\n        _unstakingTime = unstakingTime_;\n        emit UnstakingTimeUpdated(unstakingTime_);\n    }\n\n    function _beforeTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal override {\n        _update();\n        string memory errorText = \"Minimal stake balance should be more or equal to 1 token\";\n        if (from != address(0)) {\n            uint256 fromNewBalance = _price.mul(balanceOf(from).sub(amount)).floor();\n            require(fromNewBalance \u003e= MIN_STAKE_BALANCE || fromNewBalance == 0, errorText);\n        }\n        if (to != address(0)) {\n            require(_price.mul(balanceOf(to).add(amount)).floor() \u003e= MIN_STAKE_BALANCE, errorText);\n        }\n    }\n\n    function _setCurrentStrategy(\n        uint256 perSecondReward_,\n        uint256 startsAt_,\n        uint256 endsAt_\n    ) private {\n        _currentStrategy = Strategy({perSecondReward: perSecondReward_, startsAt: startsAt_, endsAt: endsAt_});\n        emit CurrentStrategyUpdated(perSecondReward_, startsAt_, endsAt_);\n    }\n\n    function _stake(\n        address staker,\n        address payer,\n        uint256 amount\n    ) private returns (uint256 mintedAmount) {\n        _update();\n        mintedAmount = AttoDecimal.div(amount, _price).floor();\n        require(mintedAmount \u003e 0, \"Too small staking amount\");\n        _mint(staker, mintedAmount);\n        _totalStaked = _totalStaked.add(amount);\n        emit Staked(staker, payer, amount, mintedAmount);\n        _stakingToken.safeTransferFrom(payer, address(this), amount);\n    }\n\n    modifier onlyPositiveAmount(uint256 amount) {\n        require(amount \u003e 0, \"Amount is not positive\");\n        _;\n    }\n}"},"TwoStageOwnable.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.6.12;\n\nabstract contract TwoStageOwnable {\n    address private _nominatedOwner;\n    address private _owner;\n\n    function nominatedOwner() public view returns (address) {\n        return _nominatedOwner;\n    }\n\n    function owner() public view returns (address) {\n        return _owner;\n    }\n\n    event OwnerChanged(address indexed newOwner);\n    event OwnerNominated(address indexed nominatedOwner);\n\n    constructor(address owner_) internal {\n        require(owner_ != address(0), \"Owner is zero\");\n        _setOwner(owner_);\n    }\n\n    function acceptOwnership() external returns (bool success) {\n        require(msg.sender == _nominatedOwner, \"Not nominated to ownership\");\n        _setOwner(_nominatedOwner);\n        return true;\n    }\n\n    function nominateNewOwner(address owner_) external onlyOwner returns (bool success) {\n        _nominateNewOwner(owner_);\n        return true;\n    }\n\n    modifier onlyOwner {\n        require(msg.sender == _owner, \"Not owner\");\n        _;\n    }\n\n    function _nominateNewOwner(address owner_) internal {\n        if (_nominatedOwner == owner_) return;\n        require(_owner != owner_, \"Already owner\");\n        _nominatedOwner = owner_;\n        emit OwnerNominated(owner_);\n    }\n\n    function _setOwner(address newOwner) internal {\n        if (_owner == newOwner) return;\n        _owner = newOwner;\n        _nominatedOwner = address(0);\n        emit OwnerChanged(newOwner);\n    }\n}"}}