ETH Price: $3,057.63 (+1.85%)
Gas: 13 Gwei

Contract

0xEDbE438Cd865992fDB72dd252E6055A71b02BE72
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Initialize Token105757642020-08-01 19:18:511355 days ago1596309531IN
0xEDbE438C...71b02BE72
0 ETH0.001155450
Transfer Ownersh...105756942020-08-01 19:00:401355 days ago1596308440IN
0xEDbE438C...71b02BE72
0 ETH0.00154550
Initialize Token105756912020-08-01 19:00:081355 days ago1596308408IN
0xEDbE438C...71b02BE72
0 ETH0.004208850
0x60806040105694042020-07-31 20:02:341356 days ago1596225754IN
 Create: GoodMarketMaker
0 ETH0.1873915240

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
GoodMarketMaker

Compiler Version
v0.5.16+commit.9c3226ce

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2020-08-02
*/

/**
Support UBI! https://github.com/GoodDollar/GoodContracts
*/

pragma solidity >0.5.4;


/**
 * @title SafeMath
 * @dev Unsigned math operations with safety checks that revert on error
 */
library SafeMath {
    /**
    * @dev Multiplies two unsigned integers, reverts on overflow.
    */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b);

        return c;
    }

    /**
    * @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
    */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
    * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
    */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a);
        uint256 c = a - b;

        return c;
    }

    /**
    * @dev Adds two unsigned integers, reverts on overflow.
    */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a);

        return c;
    }

    /**
    * @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
    * reverts when dividing by zero.
    */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0);
        return a % b;
    }
}

/**
 * @title ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/20
 */
interface IERC20 {
    function transfer(address to, uint256 value) external returns (bool);

    function approve(address spender, uint256 value) external returns (bool);

    function transferFrom(address from, address to, uint256 value) external returns (bool);

    function totalSupply() external view returns (uint256);

    function balanceOf(address who) external view returns (uint256);

    function allowance(address owner, address spender) external view returns (uint256);

    event Transfer(address indexed from, address indexed to, uint256 value);

    event Approval(address indexed owner, address indexed spender, uint256 value);
}

/**
 * @title Standard ERC20 token
 *
 * @dev Implementation of the basic standard token.
 * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
 * Originally based on code by FirstBlood:
 * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
 *
 * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
 * all accounts just by listening to said events. Note that this isn't required by the specification, and other
 * compliant implementations may not do it.
 */
contract ERC20 is IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowed;

    uint256 private _totalSupply;

    /**
    * @dev Total number of tokens in existence
    */
    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }

    /**
    * @dev Gets the balance of the specified address.
    * @param owner The address to query the balance of.
    * @return An uint256 representing the amount owned by the passed address.
    */
    function balanceOf(address owner) public view returns (uint256) {
        return _balances[owner];
    }

    /**
     * @dev Function to check the amount of tokens that an owner allowed to a spender.
     * @param owner address The address which owns the funds.
     * @param spender address The address which will spend the funds.
     * @return A uint256 specifying the amount of tokens still available for the spender.
     */
    function allowance(address owner, address spender) public view returns (uint256) {
        return _allowed[owner][spender];
    }

    /**
    * @dev Transfer token for a specified address
    * @param to The address to transfer to.
    * @param value The amount to be transferred.
    */
    function transfer(address to, uint256 value) public returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    /**
     * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
     * Beware that changing an allowance with this method brings the risk that someone may use both the old
     * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
     * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     */
    function approve(address spender, uint256 value) public returns (bool) {
        require(spender != address(0));

        _allowed[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    /**
     * @dev Transfer tokens from one address to another.
     * Note that while this function emits an Approval event, this is not required as per the specification,
     * and other compliant implementations may not emit the event.
     * @param from address The address which you want to send tokens from
     * @param to address The address which you want to transfer to
     * @param value uint256 the amount of tokens to be transferred
     */
    function transferFrom(address from, address to, uint256 value) public returns (bool) {
        _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
        _transfer(from, to, value);
        emit Approval(from, msg.sender, _allowed[from][msg.sender]);
        return true;
    }

    /**
     * @dev Increase the amount of tokens that an owner allowed to a spender.
     * approve should be called when allowed_[_spender] == 0. To increment
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * Emits an Approval event.
     * @param spender The address which will spend the funds.
     * @param addedValue The amount of tokens to increase the allowance by.
     */
    function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
        require(spender != address(0));

        _allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue);
        emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
        return true;
    }

    /**
     * @dev Decrease the amount of tokens that an owner allowed to a spender.
     * approve should be called when allowed_[_spender] == 0. To decrement
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * Emits an Approval event.
     * @param spender The address which will spend the funds.
     * @param subtractedValue The amount of tokens to decrease the allowance by.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
        require(spender != address(0));

        _allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue);
        emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
        return true;
    }

    /**
    * @dev Transfer token for a specified addresses
    * @param from The address to transfer from.
    * @param to The address to transfer to.
    * @param value The amount to be transferred.
    */
    function _transfer(address from, address to, uint256 value) internal {
        require(to != address(0));

        _balances[from] = _balances[from].sub(value);
        _balances[to] = _balances[to].add(value);
        emit Transfer(from, to, value);
    }

    /**
     * @dev Internal function that mints an amount of the token and assigns it to
     * an account. This encapsulates the modification of balances such that the
     * proper events are emitted.
     * @param account The account that will receive the created tokens.
     * @param value The amount that will be created.
     */
    function _mint(address account, uint256 value) internal {
        require(account != address(0));

        _totalSupply = _totalSupply.add(value);
        _balances[account] = _balances[account].add(value);
        emit Transfer(address(0), account, value);
    }

    /**
     * @dev Internal function that burns an amount of the token of a given
     * account.
     * @param account The account whose tokens will be burnt.
     * @param value The amount that will be burnt.
     */
    function _burn(address account, uint256 value) internal {
        require(account != address(0));

        _totalSupply = _totalSupply.sub(value);
        _balances[account] = _balances[account].sub(value);
        emit Transfer(account, address(0), value);
    }

    /**
     * @dev Internal function that burns an amount of the token of a given
     * account, deducting from the sender's allowance for said account. Uses the
     * internal burn function.
     * Emits an Approval event (reflecting the reduced allowance).
     * @param account The account whose tokens will be burnt.
     * @param value The amount that will be burnt.
     */
    function _burnFrom(address account, uint256 value) internal {
        _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value);
        _burn(account, value);
        emit Approval(account, msg.sender, _allowed[account][msg.sender]);
    }
}

/**
 * @title ERC20Detailed token
 * @dev The decimals are only for visualization purposes.
 * All the operations are done using the smallest and indivisible token unit,
 * just as on Ethereum all the operations are done in wei.
 */
contract ERC20Detailed is IERC20 {
    string private _name;
    string private _symbol;
    uint8 private _decimals;

    constructor (string memory name, string memory symbol, uint8 decimals) public {
        _name = name;
        _symbol = symbol;
        _decimals = decimals;
    }

    /**
     * @return the name of the token.
     */
    function name() public view returns (string memory) {
        return _name;
    }

    /**
     * @return the symbol of the token.
     */
    function symbol() public view returns (string memory) {
        return _symbol;
    }

    /**
     * @return the number of decimals of the token.
     */
    function decimals() public view returns (uint8) {
        return _decimals;
    }
}

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev The Ownable constructor sets the original `owner` of the contract to the sender
     * account.
     */
    constructor () internal {
        _owner = msg.sender;
        emit OwnershipTransferred(address(0), _owner);
    }

    /**
     * @return the address of the owner.
     */
    function owner() public view returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(isOwner());
        _;
    }

    /**
     * @return true if `msg.sender` is the owner of the contract.
     */
    function isOwner() public view returns (bool) {
        return msg.sender == _owner;
    }

    /**
     * @dev Allows the current owner to relinquish control of the contract.
     * @notice Renouncing to ownership will leave the contract without an owner.
     * It will not be possible to call the functions with the `onlyOwner`
     * modifier anymore.
     */
    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Allows the current owner to transfer control of the contract to a newOwner.
     * @param newOwner The address to transfer ownership to.
     */
    function transferOwnership(address newOwner) public onlyOwner {
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers control of the contract to a newOwner.
     * @param newOwner The address to transfer ownership to.
     */
    function _transferOwnership(address newOwner) internal {
        require(newOwner != address(0));
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

/**
 * @title Reputation system
 * @dev A DAO has Reputation System which allows peers to rate other peers in order to build trust .
 * A reputation is use to assign influence measure to a DAO'S peers.
 * Reputation is similar to regular tokens but with one crucial difference: It is non-transferable.
 * The Reputation contract maintain a map of address to reputation value.
 * It provides an onlyOwner functions to mint and burn reputation _to (or _from) a specific address.
 */
contract Reputation is Ownable {

    uint8 public decimals = 18;             //Number of decimals of the smallest unit
    // Event indicating minting of reputation to an address.
    event Mint(address indexed _to, uint256 _amount);
    // Event indicating burning of reputation for an address.
    event Burn(address indexed _from, uint256 _amount);

      /// @dev `Checkpoint` is the structure that attaches a block number to a
      ///  given value, the block number attached is the one that last changed the
      ///  value
    struct Checkpoint {

    // `fromBlock` is the block number that the value was generated from
        uint128 fromBlock;

          // `value` is the amount of reputation at a specific block number
        uint128 value;
    }

      // `balances` is the map that tracks the balance of each address, in this
      //  contract when the balance changes the block number that the change
      //  occurred is also included in the map
    mapping (address => Checkpoint[]) balances;

      // Tracks the history of the `totalSupply` of the reputation
    Checkpoint[] totalSupplyHistory;

    /// @notice Constructor to create a Reputation
    constructor(
    ) public
    {
    }

    /// @dev This function makes it easy to get the total number of reputation
    /// @return The total number of reputation
    function totalSupply() public view returns (uint256) {
        return totalSupplyAt(block.number);
    }

  ////////////////
  // Query balance and totalSupply in History
  ////////////////
    /**
    * @dev return the reputation amount of a given owner
    * @param _owner an address of the owner which we want to get his reputation
    */
    function balanceOf(address _owner) public view returns (uint256 balance) {
        return balanceOfAt(_owner, block.number);
    }

      /// @dev Queries the balance of `_owner` at a specific `_blockNumber`
      /// @param _owner The address from which the balance will be retrieved
      /// @param _blockNumber The block number when the balance is queried
      /// @return The balance at `_blockNumber`
    function balanceOfAt(address _owner, uint256 _blockNumber)
    public view returns (uint256)
    {
        if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
            return 0;
          // This will return the expected balance during normal situations
        } else {
            return getValueAt(balances[_owner], _blockNumber);
        }
    }

      /// @notice Total amount of reputation at a specific `_blockNumber`.
      /// @param _blockNumber The block number when the totalSupply is queried
      /// @return The total amount of reputation at `_blockNumber`
    function totalSupplyAt(uint256 _blockNumber) public view returns(uint256) {
        if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
            return 0;
          // This will return the expected totalSupply during normal situations
        } else {
            return getValueAt(totalSupplyHistory, _blockNumber);
        }
    }

      /// @notice Generates `_amount` reputation that are assigned to `_owner`
      /// @param _user The address that will be assigned the new reputation
      /// @param _amount The quantity of reputation generated
      /// @return True if the reputation are generated correctly
    function mint(address _user, uint256 _amount) public onlyOwner returns (bool) {
        uint256 curTotalSupply = totalSupply();
        require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow
        uint256 previousBalanceTo = balanceOf(_user);
        require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
        updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
        updateValueAtNow(balances[_user], previousBalanceTo + _amount);
        emit Mint(_user, _amount);
        return true;
    }

      /// @notice Burns `_amount` reputation from `_owner`
      /// @param _user The address that will lose the reputation
      /// @param _amount The quantity of reputation to burn
      /// @return True if the reputation are burned correctly
    function burn(address _user, uint256 _amount) public onlyOwner returns (bool) {
        uint256 curTotalSupply = totalSupply();
        uint256 amountBurned = _amount;
        uint256 previousBalanceFrom = balanceOf(_user);
        if (previousBalanceFrom < amountBurned) {
            amountBurned = previousBalanceFrom;
        }
        updateValueAtNow(totalSupplyHistory, curTotalSupply - amountBurned);
        updateValueAtNow(balances[_user], previousBalanceFrom - amountBurned);
        emit Burn(_user, amountBurned);
        return true;
    }

  ////////////////
  // Internal helper functions to query and set a value in a snapshot array
  ////////////////

      /// @dev `getValueAt` retrieves the number of reputation at a given block number
      /// @param checkpoints The history of values being queried
      /// @param _block The block number to retrieve the value at
      /// @return The number of reputation being queried
    function getValueAt(Checkpoint[] storage checkpoints, uint256 _block) internal view returns (uint256) {
        if (checkpoints.length == 0) {
            return 0;
        }

          // Shortcut for the actual value
        if (_block >= checkpoints[checkpoints.length-1].fromBlock) {
            return checkpoints[checkpoints.length-1].value;
        }
        if (_block < checkpoints[0].fromBlock) {
            return 0;
        }

          // Binary search of the value in the array
        uint256 min = 0;
        uint256 max = checkpoints.length-1;
        while (max > min) {
            uint256 mid = (max + min + 1) / 2;
            if (checkpoints[mid].fromBlock<=_block) {
                min = mid;
            } else {
                max = mid-1;
            }
        }
        return checkpoints[min].value;
    }

      /// @dev `updateValueAtNow` used to update the `balances` map and the
      ///  `totalSupplyHistory`
      /// @param checkpoints The history of data being updated
      /// @param _value The new number of reputation
    function updateValueAtNow(Checkpoint[] storage checkpoints, uint256 _value) internal {
        require(uint128(_value) == _value); //check value is in the 128 bits bounderies
        if ((checkpoints.length == 0) || (checkpoints[checkpoints.length - 1].fromBlock < block.number)) {
            Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++];
            newCheckPoint.fromBlock = uint128(block.number);
            newCheckPoint.value = uint128(_value);
        } else {
            Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1];
            oldCheckPoint.value = uint128(_value);
        }
    }
}

/**
 * @title Burnable Token
 * @dev Token that can be irreversibly burned (destroyed).
 */
contract ERC20Burnable is ERC20 {
    /**
     * @dev Burns a specific amount of tokens.
     * @param value The amount of token to be burned.
     */
    function burn(uint256 value) public {
        _burn(msg.sender, value);
    }

    /**
     * @dev Burns a specific amount of tokens from the target address and decrements allowance
     * @param from address The address which you want to send tokens from
     * @param value uint256 The amount of token to be burned
     */
    function burnFrom(address from, uint256 value) public {
        _burnFrom(from, value);
    }
}

/**
 * @title DAOToken, base on zeppelin contract.
 * @dev ERC20 compatible token. It is a mintable, burnable token.
 */
contract DAOToken is ERC20, ERC20Burnable, Ownable {

    string public name;
    string public symbol;
    // solhint-disable-next-line const-name-snakecase
    uint8 public constant decimals = 18;
    uint256 public cap;

    /**
    * @dev Constructor
    * @param _name - token name
    * @param _symbol - token symbol
    * @param _cap - token cap - 0 value means no cap
    */
    constructor(string memory _name, string memory _symbol, uint256 _cap)
    public {
        name = _name;
        symbol = _symbol;
        cap = _cap;
    }

    /**
     * @dev Function to mint tokens
     * @param _to The address that will receive the minted tokens.
     * @param _amount The amount of tokens to mint.
     */
    function mint(address _to, uint256 _amount) public onlyOwner returns (bool) {
        if (cap > 0)
            require(totalSupply().add(_amount) <= cap);
        _mint(_to, _amount);
        return true;
    }
}

/**
 * Utility library of inline functions on addresses
 */
library Address {
    /**
     * Returns whether the target address is a contract
     * @dev This function will return false if invoked during the constructor of a contract,
     * as the code is not actually created until after the constructor finishes.
     * @param account address of the account to check
     * @return whether the target address is a contract
     */
    function isContract(address account) internal view returns (bool) {
        uint256 size;
        // XXX Currently there is no better way to check if there is a contract in an address
        // than to check the size of the code at that address.
        // See https://ethereum.stackexchange.com/a/14016/36603
        // for more details about how this works.
        // TODO Check this again before the Serenity release, because all addresses will be
        // contracts then.
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }
}

/*

SafeERC20 by daostack.
The code is based on a fix by SECBIT Team.

USE WITH CAUTION & NO WARRANTY

REFERENCE & RELATED READING
- https://github.com/ethereum/solidity/issues/4116
- https://medium.com/@chris_77367/explaining-unexpected-reverts-starting-with-solidity-0-4-22-3ada6e82308c
- https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
- https://gist.github.com/BrendanChou/88a2eeb80947ff00bcf58ffdafeaeb61

*/
library SafeERC20 {
    using Address for address;

    bytes4 constant private TRANSFER_SELECTOR = bytes4(keccak256(bytes("transfer(address,uint256)")));
    bytes4 constant private TRANSFERFROM_SELECTOR = bytes4(keccak256(bytes("transferFrom(address,address,uint256)")));
    bytes4 constant private APPROVE_SELECTOR = bytes4(keccak256(bytes("approve(address,uint256)")));

    function safeTransfer(address _erc20Addr, address _to, uint256 _value) internal {

        // Must be a contract addr first!
        require(_erc20Addr.isContract());

        (bool success, bytes memory returnValue) =
        // solhint-disable-next-line avoid-low-level-calls
        _erc20Addr.call(abi.encodeWithSelector(TRANSFER_SELECTOR, _to, _value));
        // call return false when something wrong
        require(success);
        //check return value
        require(returnValue.length == 0 || (returnValue.length == 32 && (returnValue[31] != 0)));
    }

    function safeTransferFrom(address _erc20Addr, address _from, address _to, uint256 _value) internal {

        // Must be a contract addr first!
        require(_erc20Addr.isContract());

        (bool success, bytes memory returnValue) =
        // solhint-disable-next-line avoid-low-level-calls
        _erc20Addr.call(abi.encodeWithSelector(TRANSFERFROM_SELECTOR, _from, _to, _value));
        // call return false when something wrong
        require(success);
        //check return value
        require(returnValue.length == 0 || (returnValue.length == 32 && (returnValue[31] != 0)));
    }

    function safeApprove(address _erc20Addr, address _spender, uint256 _value) internal {

        // Must be a contract addr first!
        require(_erc20Addr.isContract());

        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero.
        require((_value == 0) || (IERC20(_erc20Addr).allowance(address(this), _spender) == 0));

        (bool success, bytes memory returnValue) =
        // solhint-disable-next-line avoid-low-level-calls
        _erc20Addr.call(abi.encodeWithSelector(APPROVE_SELECTOR, _spender, _value));
        // call return false when something wrong
        require(success);
        //check return value
        require(returnValue.length == 0 || (returnValue.length == 32 && (returnValue[31] != 0)));
    }
}

/**
 * @title An Avatar holds tokens, reputation and ether for a controller
 */
contract Avatar is Ownable {
    using SafeERC20 for address;

    string public orgName;
    DAOToken public nativeToken;
    Reputation public nativeReputation;

    event GenericCall(address indexed _contract, bytes _data, uint _value, bool _success);
    event SendEther(uint256 _amountInWei, address indexed _to);
    event ExternalTokenTransfer(address indexed _externalToken, address indexed _to, uint256 _value);
    event ExternalTokenTransferFrom(address indexed _externalToken, address _from, address _to, uint256 _value);
    event ExternalTokenApproval(address indexed _externalToken, address _spender, uint256 _value);
    event ReceiveEther(address indexed _sender, uint256 _value);
    event MetaData(string _metaData);

    /**
    * @dev the constructor takes organization name, native token and reputation system
    and creates an avatar for a controller
    */
    constructor(string memory _orgName, DAOToken _nativeToken, Reputation _nativeReputation) public {
        orgName = _orgName;
        nativeToken = _nativeToken;
        nativeReputation = _nativeReputation;
    }

    /**
    * @dev enables an avatar to receive ethers
    */
    function() external payable {
        emit ReceiveEther(msg.sender, msg.value);
    }

    /**
    * @dev perform a generic call to an arbitrary contract
    * @param _contract  the contract's address to call
    * @param _data ABI-encoded contract call to call `_contract` address.
    * @param _value value (ETH) to transfer with the transaction
    * @return bool    success or fail
    *         bytes - the return bytes of the called contract's function.
    */
    function genericCall(address _contract, bytes memory _data, uint256 _value)
    public
    onlyOwner
    returns(bool success, bytes memory returnValue) {
      // solhint-disable-next-line avoid-call-value
        (success, returnValue) = _contract.call.value(_value)(_data);
        emit GenericCall(_contract, _data, _value, success);
    }

    /**
    * @dev send ethers from the avatar's wallet
    * @param _amountInWei amount to send in Wei units
    * @param _to send the ethers to this address
    * @return bool which represents success
    */
    function sendEther(uint256 _amountInWei, address payable _to) public onlyOwner returns(bool) {
        _to.transfer(_amountInWei);
        emit SendEther(_amountInWei, _to);
        return true;
    }

    /**
    * @dev external token transfer
    * @param _externalToken the token contract
    * @param _to the destination address
    * @param _value the amount of tokens to transfer
    * @return bool which represents success
    */
    function externalTokenTransfer(IERC20 _externalToken, address _to, uint256 _value)
    public onlyOwner returns(bool)
    {
        address(_externalToken).safeTransfer(_to, _value);
        emit ExternalTokenTransfer(address(_externalToken), _to, _value);
        return true;
    }

    /**
    * @dev external token transfer from a specific account
    * @param _externalToken the token contract
    * @param _from the account to spend token from
    * @param _to the destination address
    * @param _value the amount of tokens to transfer
    * @return bool which represents success
    */
    function externalTokenTransferFrom(
        IERC20 _externalToken,
        address _from,
        address _to,
        uint256 _value
    )
    public onlyOwner returns(bool)
    {
        address(_externalToken).safeTransferFrom(_from, _to, _value);
        emit ExternalTokenTransferFrom(address(_externalToken), _from, _to, _value);
        return true;
    }

    /**
    * @dev externalTokenApproval approve the spender address to spend a specified amount of tokens
    *      on behalf of msg.sender.
    * @param _externalToken the address of the Token Contract
    * @param _spender address
    * @param _value the amount of ether (in Wei) which the approval is referring to.
    * @return bool which represents a success
    */
    function externalTokenApproval(IERC20 _externalToken, address _spender, uint256 _value)
    public onlyOwner returns(bool)
    {
        address(_externalToken).safeApprove(_spender, _value);
        emit ExternalTokenApproval(address(_externalToken), _spender, _value);
        return true;
    }

    /**
    * @dev metaData emits an event with a string, should contain the hash of some meta data.
    * @param _metaData a string representing a hash of the meta data
    * @return bool which represents a success
    */
    function metaData(string memory _metaData) public onlyOwner returns(bool) {
        emit MetaData(_metaData);
        return true;
    }


}

/**
 * @title Roles
 * @dev Library for managing addresses assigned to a Role.
 */
library Roles {
    struct Role {
        mapping (address => bool) bearer;
    }

    /**
     * @dev give an account access to this role
     */
    function add(Role storage role, address account) internal {
        require(account != address(0));
        require(!has(role, account));

        role.bearer[account] = true;
    }

    /**
     * @dev remove an account's access to this role
     */
    function remove(Role storage role, address account) internal {
        require(account != address(0));
        require(has(role, account));

        role.bearer[account] = false;
    }

    /**
     * @dev check if an account has this role
     * @return bool
     */
    function has(Role storage role, address account) internal view returns (bool) {
        require(account != address(0));
        return role.bearer[account];
    }
}

contract PauserRole {
    using Roles for Roles.Role;

    event PauserAdded(address indexed account);
    event PauserRemoved(address indexed account);

    Roles.Role private _pausers;

    constructor () internal {
        _addPauser(msg.sender);
    }

    modifier onlyPauser() {
        require(isPauser(msg.sender));
        _;
    }

    function isPauser(address account) public view returns (bool) {
        return _pausers.has(account);
    }

    function addPauser(address account) public onlyPauser {
        _addPauser(account);
    }

    function renouncePauser() public {
        _removePauser(msg.sender);
    }

    function _addPauser(address account) internal {
        _pausers.add(account);
        emit PauserAdded(account);
    }

    function _removePauser(address account) internal {
        _pausers.remove(account);
        emit PauserRemoved(account);
    }
}

/**
 * @title Pausable
 * @dev Base contract which allows children to implement an emergency stop mechanism.
 */
contract Pausable is PauserRole {
    event Paused(address account);
    event Unpaused(address account);

    bool private _paused;

    constructor () internal {
        _paused = false;
    }

    /**
     * @return true if the contract is paused, false otherwise.
     */
    function paused() public view returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     */
    modifier whenNotPaused() {
        require(!_paused);
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     */
    modifier whenPaused() {
        require(_paused);
        _;
    }

    /**
     * @dev called by the owner to pause, triggers stopped state
     */
    function pause() public onlyPauser whenNotPaused {
        _paused = true;
        emit Paused(msg.sender);
    }

    /**
     * @dev called by the owner to unpause, returns to normal state
     */
    function unpause() public onlyPauser whenPaused {
        _paused = false;
        emit Unpaused(msg.sender);
    }
}

contract GlobalConstraintInterface {

    enum CallPhase { Pre, Post, PreAndPost }

    function pre( address _scheme, bytes32 _params, bytes32 _method ) public returns(bool);
    function post( address _scheme, bytes32 _params, bytes32 _method ) public returns(bool);
    /**
     * @dev when return if this globalConstraints is pre, post or both.
     * @return CallPhase enum indication  Pre, Post or PreAndPost.
     */
    function when() public returns(CallPhase);
}

/**
 * @title Controller contract
 * @dev A controller controls the organizations tokens ,reputation and avatar.
 * It is subject to a set of schemes and constraints that determine its behavior.
 * Each scheme has it own parameters and operation permissions.
 */
interface ControllerInterface {

    /**
     * @dev Mint `_amount` of reputation that are assigned to `_to` .
     * @param  _amount amount of reputation to mint
     * @param _to beneficiary address
     * @return bool which represents a success
    */
    function mintReputation(uint256 _amount, address _to, address _avatar)
    external
    returns(bool);

    /**
     * @dev Burns `_amount` of reputation from `_from`
     * @param _amount amount of reputation to burn
     * @param _from The address that will lose the reputation
     * @return bool which represents a success
     */
    function burnReputation(uint256 _amount, address _from, address _avatar)
    external
    returns(bool);

    /**
     * @dev mint tokens .
     * @param  _amount amount of token to mint
     * @param _beneficiary beneficiary address
     * @param _avatar address
     * @return bool which represents a success
     */
    function mintTokens(uint256 _amount, address _beneficiary, address _avatar)
    external
    returns(bool);

  /**
   * @dev register or update a scheme
   * @param _scheme the address of the scheme
   * @param _paramsHash a hashed configuration of the usage of the scheme
   * @param _permissions the permissions the new scheme will have
   * @param _avatar address
   * @return bool which represents a success
   */
    function registerScheme(address _scheme, bytes32 _paramsHash, bytes4 _permissions, address _avatar)
    external
    returns(bool);

    /**
     * @dev unregister a scheme
     * @param _avatar address
     * @param _scheme the address of the scheme
     * @return bool which represents a success
     */
    function unregisterScheme(address _scheme, address _avatar)
    external
    returns(bool);

    /**
     * @dev unregister the caller's scheme
     * @param _avatar address
     * @return bool which represents a success
     */
    function unregisterSelf(address _avatar) external returns(bool);

    /**
     * @dev add or update Global Constraint
     * @param _globalConstraint the address of the global constraint to be added.
     * @param _params the constraint parameters hash.
     * @param _avatar the avatar of the organization
     * @return bool which represents a success
     */
    function addGlobalConstraint(address _globalConstraint, bytes32 _params, address _avatar)
    external returns(bool);

    /**
     * @dev remove Global Constraint
     * @param _globalConstraint the address of the global constraint to be remove.
     * @param _avatar the organization avatar.
     * @return bool which represents a success
     */
    function removeGlobalConstraint (address _globalConstraint, address _avatar)
    external  returns(bool);

  /**
    * @dev upgrade the Controller
    *      The function will trigger an event 'UpgradeController'.
    * @param  _newController the address of the new controller.
    * @param _avatar address
    * @return bool which represents a success
    */
    function upgradeController(address _newController, Avatar _avatar)
    external returns(bool);

    /**
    * @dev perform a generic call to an arbitrary contract
    * @param _contract  the contract's address to call
    * @param _data ABI-encoded contract call to call `_contract` address.
    * @param _avatar the controller's avatar address
    * @param _value value (ETH) to transfer with the transaction
    * @return bool -success
    *         bytes  - the return value of the called _contract's function.
    */
    function genericCall(address _contract, bytes calldata _data, Avatar _avatar, uint256 _value)
    external
    returns(bool, bytes memory);

  /**
   * @dev send some ether
   * @param _amountInWei the amount of ether (in Wei) to send
   * @param _to address of the beneficiary
   * @param _avatar address
   * @return bool which represents a success
   */
    function sendEther(uint256 _amountInWei, address payable _to, Avatar _avatar)
    external returns(bool);

    /**
    * @dev send some amount of arbitrary ERC20 Tokens
    * @param _externalToken the address of the Token Contract
    * @param _to address of the beneficiary
    * @param _value the amount of ether (in Wei) to send
    * @param _avatar address
    * @return bool which represents a success
    */
    function externalTokenTransfer(IERC20 _externalToken, address _to, uint256 _value, Avatar _avatar)
    external
    returns(bool);

    /**
    * @dev transfer token "from" address "to" address
    *      One must to approve the amount of tokens which can be spend from the
    *      "from" account.This can be done using externalTokenApprove.
    * @param _externalToken the address of the Token Contract
    * @param _from address of the account to send from
    * @param _to address of the beneficiary
    * @param _value the amount of ether (in Wei) to send
    * @param _avatar address
    * @return bool which represents a success
    */
    function externalTokenTransferFrom(
    IERC20 _externalToken,
    address _from,
    address _to,
    uint256 _value,
    Avatar _avatar)
    external
    returns(bool);

    /**
    * @dev externalTokenApproval approve the spender address to spend a specified amount of tokens
    *      on behalf of msg.sender.
    * @param _externalToken the address of the Token Contract
    * @param _spender address
    * @param _value the amount of ether (in Wei) which the approval is referring to.
    * @return bool which represents a success
    */
    function externalTokenApproval(IERC20 _externalToken, address _spender, uint256 _value, Avatar _avatar)
    external
    returns(bool);

    /**
    * @dev metaData emits an event with a string, should contain the hash of some meta data.
    * @param _metaData a string representing a hash of the meta data
    * @param _avatar Avatar
    * @return bool which represents a success
    */
    function metaData(string calldata _metaData, Avatar _avatar) external returns(bool);

    /**
     * @dev getNativeReputation
     * @param _avatar the organization avatar.
     * @return organization native reputation
     */
    function getNativeReputation(address _avatar)
    external
    view
    returns(address);

    function isSchemeRegistered( address _scheme, address _avatar) external view returns(bool);

    function getSchemeParameters(address _scheme, address _avatar) external view returns(bytes32);

    function getGlobalConstraintParameters(address _globalConstraint, address _avatar) external view returns(bytes32);

    function getSchemePermissions(address _scheme, address _avatar) external view returns(bytes4);

    /**
     * @dev globalConstraintsCount return the global constraint pre and post count
     * @return uint256 globalConstraintsPre count.
     * @return uint256 globalConstraintsPost count.
     */
    function globalConstraintsCount(address _avatar) external view returns(uint, uint);

    function isGlobalConstraintRegistered(address _globalConstraint, address _avatar) external view returns(bool);
}

/* @dev abstract contract for ensuring that schemes have been registered properly
 * Allows setting zero Avatar in situations where the Avatar hasn't been created yet
 */
contract SchemeGuard is Ownable {
    Avatar avatar;
    ControllerInterface internal controller = ControllerInterface(0);

    /** @dev Constructor. only sets controller if given avatar is not null.
     * @param _avatar The avatar of the DAO.
     */
    constructor(Avatar _avatar) public {
        avatar = _avatar;

        if (avatar != Avatar(0)) {
            controller = ControllerInterface(avatar.owner());
        }
    }

    /** @dev modifier to check if caller is avatar
     */
    modifier onlyAvatar() {
        require(address(avatar) == msg.sender, "only Avatar can call this method");
        _;
    }

    /** @dev modifier to check if scheme is registered
     */
    modifier onlyRegistered() {
        require(isRegistered(), "Scheme is not registered");
        _;
    }

    /** @dev modifier to check if scheme is not registered
     */
    modifier onlyNotRegistered() {
        require(!isRegistered(), "Scheme is registered");
        _;
    }

    /** @dev modifier to check if call is a scheme that is registered
     */
    modifier onlyRegisteredCaller() {
        require(isRegistered(msg.sender), "Calling scheme is not registered");
        _;
    }

    /** @dev Function to set a new avatar and controller for scheme
     * can only be done by owner of scheme
     */
    function setAvatar(Avatar _avatar) public onlyOwner {
        avatar = _avatar;
        controller = ControllerInterface(avatar.owner());
    }

    /** @dev function to see if an avatar has been set and if this scheme is registered
     * @return true if scheme is registered
     */
    function isRegistered() public view returns (bool) {
        return isRegistered(address(this));
    }

    /** @dev function to see if an avatar has been set and if this scheme is registered
     * @return true if scheme is registered
     */
    function isRegistered(address scheme) public view returns (bool) {
        require(avatar != Avatar(0), "Avatar is not set");

        if (!(controller.isSchemeRegistered(scheme, address(avatar)))) {
            return false;
        }
        return true;
    }
}

/**
 * @title Contract managing the identity admin role
 */
contract IdentityAdminRole is Ownable {
    using Roles for Roles.Role;

    event IdentityAdminAdded(address indexed account);
    event IdentityAdminRemoved(address indexed account);

    Roles.Role private IdentityAdmins;

    /* @dev constructor. Adds caller as an admin
     */
    constructor() internal {
        _addIdentityAdmin(msg.sender);
    }

    /* @dev Modifier to check if caller is an admin
     */
    modifier onlyIdentityAdmin() {
        require(isIdentityAdmin(msg.sender), "not IdentityAdmin");
        _;
    }

    /**
     * @dev Checks if account is identity admin
     * @param account Account to check
     * @return Boolean indicating if account is identity admin
     */
    function isIdentityAdmin(address account) public view returns (bool) {
        return IdentityAdmins.has(account);
    }

    /**
     * @dev Adds a identity admin account. Is only callable by owner.
     * @param account Address to be added
     * @return true if successful
     */
    function addIdentityAdmin(address account) public onlyOwner returns (bool) {
        _addIdentityAdmin(account);
        return true;
    }

    /**
     * @dev Removes a identity admin account. Is only callable by owner.
     * @param account Address to be removed
     * @return true if successful
     */
    function removeIdentityAdmin(address account) public onlyOwner returns (bool) {
        _removeIdentityAdmin(account);
        return true;
    }

    /**
     * @dev Allows an admin to renounce their role
     */
    function renounceIdentityAdmin() public {
        _removeIdentityAdmin(msg.sender);
    }

    /**
     * @dev Internal implementation of addIdentityAdmin
     */
    function _addIdentityAdmin(address account) internal {
        IdentityAdmins.add(account);
        emit IdentityAdminAdded(account);
    }

    /**
     * @dev Internal implementation of removeIdentityAdmin
     */
    function _removeIdentityAdmin(address account) internal {
        IdentityAdmins.remove(account);
        emit IdentityAdminRemoved(account);
    }
}

/* @title Identity contract responsible for whitelisting
 * and keeping track of amount of whitelisted users
 */
contract Identity is IdentityAdminRole, SchemeGuard, Pausable {
    using Roles for Roles.Role;
    using SafeMath for uint256;

    Roles.Role private blacklist;
    Roles.Role private whitelist;
    Roles.Role private contracts;

    uint256 public whitelistedCount = 0;
    uint256 public whitelistedContracts = 0;
    uint256 public authenticationPeriod = 14;

    mapping(address => uint256) public dateAuthenticated;
    mapping(address => uint256) public dateAdded;

    mapping(address => string) public addrToDID;
    mapping(bytes32 => address) public didHashToAddress;

    event BlacklistAdded(address indexed account);
    event BlacklistRemoved(address indexed account);

    event WhitelistedAdded(address indexed account);
    event WhitelistedRemoved(address indexed account);

    event ContractAdded(address indexed account);
    event ContractRemoved(address indexed account);

    constructor() public SchemeGuard(Avatar(0)) {}

    /* @dev Sets a new value for authenticationPeriod.
     * Can only be called by Identity Administrators.
     * @param period new value for authenticationPeriod
     */
    function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused {
        authenticationPeriod = period;
    }

    /* @dev Sets the authentication date of `account`
     * to the current time.
     * Can only be called by Identity Administrators.
     * @param account address to change its auth date
     */
    function authenticate(address account)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        dateAuthenticated[account] = now;
    }

    /* @dev Adds an address as whitelisted.
     * Can only be called by Identity Administrators.
     * @param account address to add as whitelisted
     */
    function addWhitelisted(address account)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        _addWhitelisted(account);
    }

    /* @dev Adds an address as whitelisted under a specific ID
     * @param account The address to add
     * @param did the ID to add account under
     */
    function addWhitelistedWithDID(address account, string memory did)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        _addWhitelistedWithDID(account, did);
    }

    /* @dev Removes an address as whitelisted.
     * Can only be called by Identity Administrators.
     * @param account address to remove as whitelisted
     */
    function removeWhitelisted(address account)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        _removeWhitelisted(account);
    }

    /* @dev Renounces message sender from whitelisted
     */
    function renounceWhitelisted() public whenNotPaused {
        _removeWhitelisted(msg.sender);
    }

    /* @dev Returns true if given address has been added to whitelist
     * @param account the address to check
     * @return a bool indicating weather the address is present in whitelist
     */
    function isWhitelisted(address account) public view returns (bool) {
        uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days;
        return
            (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account);
    }

    /* @dev Function that gives the date the given user was added
     * @param account The address to check
     * @return The date the address was added
     */
    function lastAuthenticated(address account) public view returns (uint256) {
        return dateAuthenticated[account];
    }

    // /**
    //  *
    //  * @dev Function to transfer whitelisted privilege to another address
    //  * relocates did of sender to give address
    //  * @param account The address to transfer to
    //  */
    // function transferAccount(address account) public whenNotPaused {
    //     ERC20 token = avatar.nativeToken();
    //     require(!isBlacklisted(account), "Cannot transfer to blacklisted");
    //     require(token.balanceOf(account) == 0, "Account is already in use");
    //     require(isWhitelisted(msg.sender), "Requester need to be whitelisted");

    //     require(
    //         keccak256(bytes(addrToDID[account])) == keccak256(bytes("")),
    //         "address already has DID"
    //     );

    //     string memory did = addrToDID[msg.sender];
    //     bytes32 pHash = keccak256(bytes(did));

    //     uint256 balance = token.balanceOf(msg.sender);
    //     token.transferFrom(msg.sender, account, balance);
    //     _removeWhitelisted(msg.sender);
    //     _addWhitelisted(account);
    //     addrToDID[account] = did;
    //     didHashToAddress[pHash] = account;
    // }

    /* @dev Adds an address to blacklist.
     * Can only be called by Identity Administrators.
     * @param account address to add as blacklisted
     */
    function addBlacklisted(address account)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        blacklist.add(account);
        emit BlacklistAdded(account);
    }

    /* @dev Removes an address from blacklist
     * Can only be called by Identity Administrators.
     * @param account address to remove as blacklisted
     */
    function removeBlacklisted(address account)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        blacklist.remove(account);
        emit BlacklistRemoved(account);
    }

    /* @dev Function to add a Contract to list of contracts
     * @param account The address to add
     */
    function addContract(address account)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        require(isContract(account), "Given address is not a contract");
        contracts.add(account);
        _addWhitelisted(account);

        emit ContractAdded(account);
    }

    /* @dev Function to remove a Contract from list of contracts
     * @param account The address to add
     */
    function removeContract(address account)
        public
        onlyRegistered
        onlyIdentityAdmin
        whenNotPaused
    {
        contracts.remove(account);
        _removeWhitelisted(account);

        emit ContractRemoved(account);
    }

    /* @dev Function to check if given contract is on list of contracts.
     * @param address to check
     * @return a bool indicating if address is on list of contracts
     */
    function isDAOContract(address account) public view returns (bool) {
        return contracts.has(account);
    }

    /* @dev Internal function to add to whitelisted
     * @param account the address to add
     */
    function _addWhitelisted(address account) internal {
        whitelist.add(account);

        whitelistedCount += 1;
        dateAdded[account] = now;
        dateAuthenticated[account] = now;

        if (isContract(account)) {
            whitelistedContracts += 1;
        }

        emit WhitelistedAdded(account);
    }

    /* @dev Internal whitelisting with did function.
     * @param account the address to add
     * @param did the id to register account under
     */
    function _addWhitelistedWithDID(address account, string memory did) internal {
        bytes32 pHash = keccak256(bytes(did));
        require(didHashToAddress[pHash] == address(0), "DID already registered");

        addrToDID[account] = did;
        didHashToAddress[pHash] = account;

        _addWhitelisted(account);
    }

    /* @dev Internal function to remove from whitelisted
     * @param account the address to add
     */
    function _removeWhitelisted(address account) internal {
        whitelist.remove(account);

        whitelistedCount -= 1;
        delete dateAuthenticated[account];

        if (isContract(account)) {
            whitelistedContracts -= 1;
        }

        string memory did = addrToDID[account];
        bytes32 pHash = keccak256(bytes(did));

        delete dateAuthenticated[account];
        delete addrToDID[account];
        delete didHashToAddress[pHash];

        emit WhitelistedRemoved(account);
    }

    /* @dev Returns true if given address has been added to the blacklist
     * @param account the address to check
     * @return a bool indicating weather the address is present in the blacklist
     */
    function isBlacklisted(address account) public view returns (bool) {
        return blacklist.has(account);
    }

    /* @dev Function to see if given address is a contract
     * @return true if address is a contract
     */
    function isContract(address _addr) internal view returns (bool) {
        uint256 length;
        assembly {
            length := extcodesize(_addr)
        }
        return length > 0;
    }
}

/* @title The IdentityGuard contract
 * @dev Contract containing an identity and
 * modifiers to ensure proper access
 */
contract IdentityGuard is Ownable {
    Identity public identity;

    /* @dev Constructor. Checks if identity is a zero address
     * @param _identity The identity contract.
     */
    constructor(Identity _identity) public {
        require(_identity != Identity(0), "Supplied identity is null");
        identity = _identity;
    }

    /* @dev Modifier that requires the sender to be not blacklisted
     */
    modifier onlyNotBlacklisted() {
        require(!identity.isBlacklisted(msg.sender), "Caller is blacklisted");
        _;
    }

    /* @dev Modifier that requires the given address to be not blacklisted
     * @param _account The address to be checked
     */
    modifier requireNotBlacklisted(address _account) {
        require(!identity.isBlacklisted(_account), "Receiver is blacklisted");
        _;
    }

    /* @dev Modifier that requires the sender to be whitelisted
     */
    modifier onlyWhitelisted() {
        require(identity.isWhitelisted(msg.sender), "is not whitelisted");
        _;
    }

    /* @dev Modifier that requires the given address to be whitelisted
     * @param _account the given address
     */
    modifier requireWhitelisted(address _account) {
        require(identity.isWhitelisted(_account), "is not whitelisted");
        _;
    }

    /* @dev Modifier that requires the sender to be an approved DAO contract
     */
    modifier onlyDAOContract() {
        require(identity.isDAOContract(msg.sender), "is not whitelisted contract");
        _;
    }

    /* @dev Modifier that requires the given address to be whitelisted
     * @param _account the given address
     */
    modifier requireDAOContract(address _contract) {
        require(identity.isDAOContract(_contract), "is not whitelisted contract");
        _;
    }

    /* @dev Modifier that requires the sender to have been whitelisted
     * before or on the given date
     * @param date The time sender must have been added before
     */
    modifier onlyAddedBefore(uint256 date) {
        require(
            identity.lastAuthenticated(msg.sender) <= date,
            "Was not added within period"
        );
        _;
    }

    /* @dev Modifier that requires sender to be an identity admin
     */
    modifier onlyIdentityAdmin() {
        require(identity.isIdentityAdmin(msg.sender), "not IdentityAdmin");
        _;
    }

    /* @dev Allows owner to set a new identity contract if
     * the given identity contract has been registered as a scheme
     */
    function setIdentity(Identity _identity) public onlyOwner {
        require(_identity.isRegistered(), "Identity is not registered");
        identity = _identity;
    }
}

/**
 * @title Fee formula abstract contract
 */
contract AbstractFees is SchemeGuard {
    constructor() public SchemeGuard(Avatar(0)) {}

    function getTxFees(
        uint256 _value,
        address _sender,
        address _recipient
    ) public view returns (uint256, bool);
}

/**
 * @title Fee formula contract
 * contract that provides a function to calculate
 * fees as a percentage of any given value
 */
contract FeeFormula is AbstractFees {
    using SafeMath for uint256;

    uint256 public percentage;
    bool public constant senderPays = false;

    /**
     * @dev Constructor. Requires the given percentage parameter
     * to be less than 100.
     * @param _percentage the percentage to calculate fees of
     */
    constructor(uint256 _percentage) public {
        require(_percentage < 100, "Percentage should be <100");
        percentage = _percentage;
    }

    /**  @dev calculates the fee of given value.
     * @param _value the value of the transaction to calculate fees from
     * @param _sender address sending.
     *  @param _recipient address receiving.
     * @return the transactional fee for given value
     */
    function getTxFees(
        uint256 _value,
        address _sender,
        address _recipient
    ) public view returns (uint256, bool) {
        return (_value.mul(percentage).div(100), senderPays);
    }
}

/* @title Contract in charge of setting registered fee formula schemes to contract
 */
contract FormulaHolder is Ownable {
    AbstractFees public formula;

    /* @dev Constructor. Requires that given formula is a valid contract.
     * @param _formula The fee formula contract.
     */
    constructor(AbstractFees _formula) public {
        require(_formula != AbstractFees(0), "Supplied formula is null");
        formula = _formula;
    }

    /* @dev Sets the given fee formula contract. Is only callable by owner.
     * Reverts if formula has not been registered by DAO.
     * @param _formula the new fee formula scheme
     */
    function setFormula(AbstractFees _formula) public onlyOwner {
        _formula.isRegistered();
        formula = _formula;
    }
}

/* @title ERC677 interface
 */
interface ERC677 {
    event Transfer(address indexed from, address indexed to, uint256 value, bytes data);

    function transferAndCall(
        address,
        uint256,
        bytes calldata
    ) external returns (bool);
}

/* @title ERC677Receiver interface
 */
interface ERC677Receiver {
    function onTokenTransfer(
        address _from,
        uint256 _value,
        bytes calldata _data
    ) external returns (bool);
}

/**
 * @title Pausable token
 * @dev ERC20 modified with pausable transfers.
 **/
contract ERC20Pausable is ERC20, Pausable {
    function transfer(address to, uint256 value) public whenNotPaused returns (bool) {
        return super.transfer(to, value);
    }

    function transferFrom(address from, address to, uint256 value) public whenNotPaused returns (bool) {
        return super.transferFrom(from, to, value);
    }

    function approve(address spender, uint256 value) public whenNotPaused returns (bool) {
        return super.approve(spender, value);
    }

    function increaseAllowance(address spender, uint addedValue) public whenNotPaused returns (bool success) {
        return super.increaseAllowance(spender, addedValue);
    }

    function decreaseAllowance(address spender, uint subtractedValue) public whenNotPaused returns (bool success) {
        return super.decreaseAllowance(spender, subtractedValue);
    }
}

/* @title ERC677Token contract.
 */
contract ERC677Token is ERC677, DAOToken, ERC20Pausable {
    constructor(
        string memory _name,
        string memory _symbol,
        uint256 _cap
    ) public DAOToken(_name, _symbol, _cap) {}

    /**
     * @dev transfer token to a contract address with additional data if the recipient is a contact.
     * @param _to The address to transfer to.
     * @param _value The amount to be transferred.
     * @param _data The extra data to be passed to the receiving contract.
     * @return true if transfer is successful
     */
    function _transferAndCall(
        address _to,
        uint256 _value,
        bytes memory _data
    ) internal whenNotPaused returns (bool) {
        bool res = super.transfer(_to, _value);
        emit Transfer(msg.sender, _to, _value, _data);

        if (isContract(_to)) {
            require(contractFallback(_to, _value, _data), "Contract fallback failed");
        }
        return res;
    }

    /* @dev Contract fallback function. Is called if transferAndCall is called
     * to a contract
     */
    function contractFallback(
        address _to,
        uint256 _value,
        bytes memory _data
    ) private returns (bool) {
        ERC677Receiver receiver = ERC677Receiver(_to);
        require(
            receiver.onTokenTransfer(msg.sender, _value, _data),
            "Contract Fallback failed"
        );
        return true;
    }

    /* @dev Function to check if given address is a contract
     * @param _addr Address to check
     * @return true if given address is a contract
     */

    function isContract(address _addr) internal view returns (bool) {
        uint256 length;
        assembly {
            length := extcodesize(_addr)
        }
        return length > 0;
    }
}

contract MinterRole {
    using Roles for Roles.Role;

    event MinterAdded(address indexed account);
    event MinterRemoved(address indexed account);

    Roles.Role private _minters;

    constructor () internal {
        _addMinter(msg.sender);
    }

    modifier onlyMinter() {
        require(isMinter(msg.sender));
        _;
    }

    function isMinter(address account) public view returns (bool) {
        return _minters.has(account);
    }

    function addMinter(address account) public onlyMinter {
        _addMinter(account);
    }

    function renounceMinter() public {
        _removeMinter(msg.sender);
    }

    function _addMinter(address account) internal {
        _minters.add(account);
        emit MinterAdded(account);
    }

    function _removeMinter(address account) internal {
        _minters.remove(account);
        emit MinterRemoved(account);
    }
}

contract ERC677BridgeToken is ERC677Token, MinterRole {
    address public bridgeContract;

    constructor(
        string memory _name,
        string memory _symbol,
        uint256 _cap
    ) public ERC677Token(_name, _symbol, _cap) {}

    function setBridgeContract(address _bridgeContract) public onlyMinter {
        require(
            _bridgeContract != address(0) && isContract(_bridgeContract),
            "Invalid bridge contract"
        );
        bridgeContract = _bridgeContract;
    }
}

/**
 * @title The GoodDollar ERC677 token contract
 */
contract GoodDollar is ERC677BridgeToken, IdentityGuard, FormulaHolder {
    address feeRecipient;

    // Overrides hard-coded decimal in DAOToken
    uint256 public constant decimals = 2;

    /**
     * @dev constructor
     * @param _name The name of the token
     * @param _symbol The symbol of the token
     * @param _cap the cap of the token. no cap if 0
     * @param _formula the fee formula contract
     * @param _identity the identity contract
     * @param _feeRecipient the address that receives transaction fees
     */
    constructor(
        string memory _name,
        string memory _symbol,
        uint256 _cap,
        AbstractFees _formula,
        Identity _identity,
        address _feeRecipient
    )
        public
        ERC677BridgeToken(_name, _symbol, _cap)
        IdentityGuard(_identity)
        FormulaHolder(_formula)
    {
        feeRecipient = _feeRecipient;
    }

    /**
     * @dev Processes fees from given value and sends
     * remainder to given address
     * @param to the address to be sent to
     * @param value the value to be processed and then
     * transferred
     * @return a boolean that indicates if the operation was successful
     */
    function transfer(address to, uint256 value) public returns (bool) {
        uint256 bruttoValue = processFees(msg.sender, to, value);
        return super.transfer(to, bruttoValue);
    }

    /**
     * @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
     * @return a boolean that indicates if the operation was successful
     */
    function approve(address spender, uint256 value) public returns (bool) {
        return super.approve(spender, value);
    }

    /**
     * @dev Transfer tokens from one address to another
     * @param from The address which you want to send tokens from
     * @param to The address which you want to transfer to
     * @param value the amount of tokens to be transferred
     * @return a boolean that indicates if the operation was successful
     */
    function transferFrom(
        address from,
        address to,
        uint256 value
    ) public returns (bool) {
        uint256 bruttoValue = processFees(from, to, value);
        return super.transferFrom(from, to, bruttoValue);
    }

    /**
     * @dev Processes transfer fees and calls ERC677Token transferAndCall function
     * @param to address to transfer to
     * @param value the amount to transfer
     * @param data The data to pass to transferAndCall
     * @return a bool indicating if transfer function succeeded
     */
    function transferAndCall(
        address to,
        uint256 value,
        bytes calldata data
    ) external returns (bool) {
        uint256 bruttoValue = processFees(msg.sender, to, value);
        return super._transferAndCall(to, bruttoValue, data);
    }

    /**
     * @dev Minting function
     * @param to the address that will receive the minted tokens
     * @param value the amount of tokens to mint
     * @return a boolean that indicated if the operation was successful
     */
    function mint(address to, uint256 value)
        public
        onlyMinter
        requireNotBlacklisted(to)
        returns (bool)
    {
        if (cap > 0) {
            require(totalSupply().add(value) <= cap, "Cannot increase supply beyond cap");
        }
        super._mint(to, value);
        return true;
    }

    /**
     * @dev Burns a specific amount of tokens.
     * @param value The amount of token to be burned.
     */
    function burn(uint256 value) public onlyNotBlacklisted {
        super.burn(value);
    }

    /**
     * @dev Burns a specific amount of tokens from the target address and decrements allowance
     * @param from address The address which you want to send tokens from
     * @param value uint256 The amount of token to be burned
     */
    function burnFrom(address from, uint256 value)
        public
        onlyNotBlacklisted
        requireNotBlacklisted(from)
    {
        super.burnFrom(from, value);
    }

    /**
     * @dev Increase the amount of tokens that an owner allows a spender
     * @param spender The address which will spend the funds
     * @param addedValue The amount of tokens to increase the allowance by
     * @return a boolean that indicated if the operation was successful
     */
    function increaseAllowance(address spender, uint256 addedValue)
        public
        returns (bool)
    {
        return super.increaseAllowance(spender, addedValue);
    }

    /**
     * @dev Decrease the amount of tokens that an owner allowed to a spender
     * @param spender The address which will spend the funds
     * @param subtractedValue The amount of tokens to decrease the allowance by
     * @return a boolean that indicated if the operation was successful
     */
    function decreaseAllowance(address spender, uint256 subtractedValue)
        public
        returns (bool)
    {
        return super.decreaseAllowance(spender, subtractedValue);
    }

    /**
     * @dev Gets the current transaction fees
     * @return an uint256 that represents
     * the current transaction fees
     */
    function getFees(uint256 value) public view returns (uint256, bool) {
        return formula.getTxFees(value, address(0), address(0));
    }

    /**
     * @dev Gets the current transaction fees
     * @return an uint256 that represents
     * the current transaction fees
     */
    function getFees(
        uint256 value,
        address sender,
        address recipient
    ) public view returns (uint256, bool) {
        return formula.getTxFees(value, sender, recipient);
    }

    /**
     * @dev Sets the address that receives the transactional fees.
     * can only be called by owner
     * @param _feeRecipient The new address to receive transactional fees
     */
    function setFeeRecipient(address _feeRecipient) public onlyOwner {
        feeRecipient = _feeRecipient;
    }

    /**
     * @dev Sends transactional fees to feeRecipient address from given address
     * @param account The account that sends the fees
     * @param value The amount to subtract fees from
     * @return an uint256 that represents the given value minus the transactional fees
     */
    function processFees(
        address account,
        address recipient,
        uint256 value
    ) internal returns (uint256) {
        (uint256 txFees, bool senderPays) = getFees(value, account, recipient);
        if (txFees > 0 && !identity.isDAOContract(msg.sender)) {
            require(
                senderPays == false || value.add(txFees) <= balanceOf(account),
                "Not enough balance to pay TX fee"
            );
            if (account == msg.sender) {
                super.transfer(feeRecipient, txFees);
            } else {
                super.transferFrom(account, feeRecipient, txFees);
            }

            return senderPays ? value : value.sub(txFees);
        }
        return value;
    }
}

/// math.sol -- mixin for inline numerical wizardry
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
contract DSMath {
    function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x + y) >= x, "ds-math-add-overflow");
    }
    function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x - y) <= x, "ds-math-sub-underflow");
    }
    function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow");
    }

    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        return x <= y ? x : y;
    }
    function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
        return x >= y ? x : y;
    }
    function imin(int256 x, int256 y) internal pure returns (int256 z) {
        return x <= y ? x : y;
    }
    function imax(int256 x, int256 y) internal pure returns (int256 z) {
        return x >= y ? x : y;
    }

    uint256 constant WAD = 10**18;
    uint256 constant RAY = 10**27;

    function wmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = add(mul(x, y), WAD / 2) / WAD;
    }
    function rmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = add(mul(x, y), RAY / 2) / RAY;
    }
    function wdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = add(mul(x, WAD), y / 2) / y;
    }
    function rdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = add(mul(x, RAY), y / 2) / y;
    }

    // This famous algorithm is called "exponentiation by squaring"
    // and calculates x^n with x as fixed-point and n as regular unsigned.
    //
    // It's O(log n), instead of O(n) for naive repeated multiplication.
    //
    // These facts are why it works:
    //
    //  If n is even, then x^n = (x^2)^(n/2).
    //  If n is odd,  then x^n = x * x^(n-1),
    //   and applying the equation for even x gives
    //    x^n = x * (x^2)^((n-1) / 2).
    //
    //  Also, EVM division is flooring and
    //    floor[(n-1) / 2] = floor[n / 2].
    //
    function rpow(uint256 x, uint256 n) internal pure returns (uint256 z) {
        z = n % 2 != 0 ? x : RAY;

        for (n /= 2; n != 0; n /= 2) {
            x = rmul(x, x);

            if (n % 2 != 0) {
                z = rmul(z, x);
            }
        }
    }
}

contract BancorFormula {
    using SafeMath for uint256;

    uint16 public version = 6;

    uint256 private constant ONE = 1;
    uint32 private constant MAX_RATIO = 1000000;
    uint8 private constant MIN_PRECISION = 32;
    uint8 private constant MAX_PRECISION = 127;

    /**
     * Auto-generated via 'PrintIntScalingFactors.py'
     */
    uint256 private constant FIXED_1 = 0x080000000000000000000000000000000;
    uint256 private constant FIXED_2 = 0x100000000000000000000000000000000;
    uint256 private constant MAX_NUM = 0x200000000000000000000000000000000;

    /**
     * Auto-generated via 'PrintLn2ScalingFactors.py'
     */
    uint256 private constant LN2_NUMERATOR = 0x3f80fe03f80fe03f80fe03f80fe03f8;
    uint256 private constant LN2_DENOMINATOR = 0x5b9de1d10bf4103d647b0955897ba80;

    /**
     * Auto-generated via 'PrintFunctionOptimalLog.py' and 'PrintFunctionOptimalExp.py'
     */
    uint256 private constant OPT_LOG_MAX_VAL = 0x15bf0a8b1457695355fb8ac404e7a79e3;
    uint256 private constant OPT_EXP_MAX_VAL = 0x800000000000000000000000000000000;

    /**
     * Auto-generated via 'PrintFunctionConstructor.py'
     */
    uint256[128] private maxExpArray;

    constructor() public {
        //  maxExpArray[  0] = 0x6bffffffffffffffffffffffffffffffff;
        //  maxExpArray[  1] = 0x67ffffffffffffffffffffffffffffffff;
        //  maxExpArray[  2] = 0x637fffffffffffffffffffffffffffffff;
        //  maxExpArray[  3] = 0x5f6fffffffffffffffffffffffffffffff;
        //  maxExpArray[  4] = 0x5b77ffffffffffffffffffffffffffffff;
        //  maxExpArray[  5] = 0x57b3ffffffffffffffffffffffffffffff;
        //  maxExpArray[  6] = 0x5419ffffffffffffffffffffffffffffff;
        //  maxExpArray[  7] = 0x50a2ffffffffffffffffffffffffffffff;
        //  maxExpArray[  8] = 0x4d517fffffffffffffffffffffffffffff;
        //  maxExpArray[  9] = 0x4a233fffffffffffffffffffffffffffff;
        //  maxExpArray[ 10] = 0x47165fffffffffffffffffffffffffffff;
        //  maxExpArray[ 11] = 0x4429afffffffffffffffffffffffffffff;
        //  maxExpArray[ 12] = 0x415bc7ffffffffffffffffffffffffffff;
        //  maxExpArray[ 13] = 0x3eab73ffffffffffffffffffffffffffff;
        //  maxExpArray[ 14] = 0x3c1771ffffffffffffffffffffffffffff;
        //  maxExpArray[ 15] = 0x399e96ffffffffffffffffffffffffffff;
        //  maxExpArray[ 16] = 0x373fc47fffffffffffffffffffffffffff;
        //  maxExpArray[ 17] = 0x34f9e8ffffffffffffffffffffffffffff;
        //  maxExpArray[ 18] = 0x32cbfd5fffffffffffffffffffffffffff;
        //  maxExpArray[ 19] = 0x30b5057fffffffffffffffffffffffffff;
        //  maxExpArray[ 20] = 0x2eb40f9fffffffffffffffffffffffffff;
        //  maxExpArray[ 21] = 0x2cc8340fffffffffffffffffffffffffff;
        //  maxExpArray[ 22] = 0x2af09481ffffffffffffffffffffffffff;
        //  maxExpArray[ 23] = 0x292c5bddffffffffffffffffffffffffff;
        //  maxExpArray[ 24] = 0x277abdcdffffffffffffffffffffffffff;
        //  maxExpArray[ 25] = 0x25daf6657fffffffffffffffffffffffff;
        //  maxExpArray[ 26] = 0x244c49c65fffffffffffffffffffffffff;
        //  maxExpArray[ 27] = 0x22ce03cd5fffffffffffffffffffffffff;
        //  maxExpArray[ 28] = 0x215f77c047ffffffffffffffffffffffff;
        //  maxExpArray[ 29] = 0x1fffffffffffffffffffffffffffffffff;
        //  maxExpArray[ 30] = 0x1eaefdbdabffffffffffffffffffffffff;
        //  maxExpArray[ 31] = 0x1d6bd8b2ebffffffffffffffffffffffff;
        maxExpArray[32] = 0x1c35fedd14ffffffffffffffffffffffff;
        maxExpArray[33] = 0x1b0ce43b323fffffffffffffffffffffff;
        maxExpArray[34] = 0x19f0028ec1ffffffffffffffffffffffff;
        maxExpArray[35] = 0x18ded91f0e7fffffffffffffffffffffff;
        maxExpArray[36] = 0x17d8ec7f0417ffffffffffffffffffffff;
        maxExpArray[37] = 0x16ddc6556cdbffffffffffffffffffffff;
        maxExpArray[38] = 0x15ecf52776a1ffffffffffffffffffffff;
        maxExpArray[39] = 0x15060c256cb2ffffffffffffffffffffff;
        maxExpArray[40] = 0x1428a2f98d72ffffffffffffffffffffff;
        maxExpArray[41] = 0x13545598e5c23fffffffffffffffffffff;
        maxExpArray[42] = 0x1288c4161ce1dfffffffffffffffffffff;
        maxExpArray[43] = 0x11c592761c666fffffffffffffffffffff;
        maxExpArray[44] = 0x110a688680a757ffffffffffffffffffff;
        maxExpArray[45] = 0x1056f1b5bedf77ffffffffffffffffffff;
        maxExpArray[46] = 0x0faadceceeff8bffffffffffffffffffff;
        maxExpArray[47] = 0x0f05dc6b27edadffffffffffffffffffff;
        maxExpArray[48] = 0x0e67a5a25da4107fffffffffffffffffff;
        maxExpArray[49] = 0x0dcff115b14eedffffffffffffffffffff;
        maxExpArray[50] = 0x0d3e7a392431239fffffffffffffffffff;
        maxExpArray[51] = 0x0cb2ff529eb71e4fffffffffffffffffff;
        maxExpArray[52] = 0x0c2d415c3db974afffffffffffffffffff;
        maxExpArray[53] = 0x0bad03e7d883f69bffffffffffffffffff;
        maxExpArray[54] = 0x0b320d03b2c343d5ffffffffffffffffff;
        maxExpArray[55] = 0x0abc25204e02828dffffffffffffffffff;
        maxExpArray[56] = 0x0a4b16f74ee4bb207fffffffffffffffff;
        maxExpArray[57] = 0x09deaf736ac1f569ffffffffffffffffff;
        maxExpArray[58] = 0x0976bd9952c7aa957fffffffffffffffff;
        maxExpArray[59] = 0x09131271922eaa606fffffffffffffffff;
        maxExpArray[60] = 0x08b380f3558668c46fffffffffffffffff;
        maxExpArray[61] = 0x0857ddf0117efa215bffffffffffffffff;
        maxExpArray[62] = 0x07ffffffffffffffffffffffffffffffff;
        maxExpArray[63] = 0x07abbf6f6abb9d087fffffffffffffffff;
        maxExpArray[64] = 0x075af62cbac95f7dfa7fffffffffffffff;
        maxExpArray[65] = 0x070d7fb7452e187ac13fffffffffffffff;
        maxExpArray[66] = 0x06c3390ecc8af379295fffffffffffffff;
        maxExpArray[67] = 0x067c00a3b07ffc01fd6fffffffffffffff;
        maxExpArray[68] = 0x0637b647c39cbb9d3d27ffffffffffffff;
        maxExpArray[69] = 0x05f63b1fc104dbd39587ffffffffffffff;
        maxExpArray[70] = 0x05b771955b36e12f7235ffffffffffffff;
        maxExpArray[71] = 0x057b3d49dda84556d6f6ffffffffffffff;
        maxExpArray[72] = 0x054183095b2c8ececf30ffffffffffffff;
        maxExpArray[73] = 0x050a28be635ca2b888f77fffffffffffff;
        maxExpArray[74] = 0x04d5156639708c9db33c3fffffffffffff;
        maxExpArray[75] = 0x04a23105873875bd52dfdfffffffffffff;
        maxExpArray[76] = 0x0471649d87199aa990756fffffffffffff;
        maxExpArray[77] = 0x04429a21a029d4c1457cfbffffffffffff;
        maxExpArray[78] = 0x0415bc6d6fb7dd71af2cb3ffffffffffff;
        maxExpArray[79] = 0x03eab73b3bbfe282243ce1ffffffffffff;
        maxExpArray[80] = 0x03c1771ac9fb6b4c18e229ffffffffffff;
        maxExpArray[81] = 0x0399e96897690418f785257fffffffffff;
        maxExpArray[82] = 0x0373fc456c53bb779bf0ea9fffffffffff;
        maxExpArray[83] = 0x034f9e8e490c48e67e6ab8bfffffffffff;
        maxExpArray[84] = 0x032cbfd4a7adc790560b3337ffffffffff;
        maxExpArray[85] = 0x030b50570f6e5d2acca94613ffffffffff;
        maxExpArray[86] = 0x02eb40f9f620fda6b56c2861ffffffffff;
        maxExpArray[87] = 0x02cc8340ecb0d0f520a6af58ffffffffff;
        maxExpArray[88] = 0x02af09481380a0a35cf1ba02ffffffffff;
        maxExpArray[89] = 0x0292c5bdd3b92ec810287b1b3fffffffff;
        maxExpArray[90] = 0x0277abdcdab07d5a77ac6d6b9fffffffff;
        maxExpArray[91] = 0x025daf6654b1eaa55fd64df5efffffffff;
        maxExpArray[92] = 0x0244c49c648baa98192dce88b7ffffffff;
        maxExpArray[93] = 0x022ce03cd5619a311b2471268bffffffff;
        maxExpArray[94] = 0x0215f77c045fbe885654a44a0fffffffff;
        maxExpArray[95] = 0x01ffffffffffffffffffffffffffffffff;
        maxExpArray[96] = 0x01eaefdbdaaee7421fc4d3ede5ffffffff;
        maxExpArray[97] = 0x01d6bd8b2eb257df7e8ca57b09bfffffff;
        maxExpArray[98] = 0x01c35fedd14b861eb0443f7f133fffffff;
        maxExpArray[99] = 0x01b0ce43b322bcde4a56e8ada5afffffff;
        maxExpArray[100] = 0x019f0028ec1fff007f5a195a39dfffffff;
        maxExpArray[101] = 0x018ded91f0e72ee74f49b15ba527ffffff;
        maxExpArray[102] = 0x017d8ec7f04136f4e5615fd41a63ffffff;
        maxExpArray[103] = 0x016ddc6556cdb84bdc8d12d22e6fffffff;
        maxExpArray[104] = 0x015ecf52776a1155b5bd8395814f7fffff;
        maxExpArray[105] = 0x015060c256cb23b3b3cc3754cf40ffffff;
        maxExpArray[106] = 0x01428a2f98d728ae223ddab715be3fffff;
        maxExpArray[107] = 0x013545598e5c23276ccf0ede68034fffff;
        maxExpArray[108] = 0x01288c4161ce1d6f54b7f61081194fffff;
        maxExpArray[109] = 0x011c592761c666aa641d5a01a40f17ffff;
        maxExpArray[110] = 0x0110a688680a7530515f3e6e6cfdcdffff;
        maxExpArray[111] = 0x01056f1b5bedf75c6bcb2ce8aed428ffff;
        maxExpArray[112] = 0x00faadceceeff8a0890f3875f008277fff;
        maxExpArray[113] = 0x00f05dc6b27edad306388a600f6ba0bfff;
        maxExpArray[114] = 0x00e67a5a25da41063de1495d5b18cdbfff;
        maxExpArray[115] = 0x00dcff115b14eedde6fc3aa5353f2e4fff;
        maxExpArray[116] = 0x00d3e7a3924312399f9aae2e0f868f8fff;
        maxExpArray[117] = 0x00cb2ff529eb71e41582cccd5a1ee26fff;
        maxExpArray[118] = 0x00c2d415c3db974ab32a51840c0b67edff;
        maxExpArray[119] = 0x00bad03e7d883f69ad5b0a186184e06bff;
        maxExpArray[120] = 0x00b320d03b2c343d4829abd6075f0cc5ff;
        maxExpArray[121] = 0x00abc25204e02828d73c6e80bcdb1a95bf;
        maxExpArray[122] = 0x00a4b16f74ee4bb2040a1ec6c15fbbf2df;
        maxExpArray[123] = 0x009deaf736ac1f569deb1b5ae3f36c130f;
        maxExpArray[124] = 0x00976bd9952c7aa957f5937d790ef65037;
        maxExpArray[125] = 0x009131271922eaa6064b73a22d0bd4f2bf;
        maxExpArray[126] = 0x008b380f3558668c46c91c49a2f8e967b9;
        maxExpArray[127] = 0x00857ddf0117efa215952912839f6473e6;
    }

    /**
     * @dev given a token supply, reserve balance, ratio and a deposit amount (in the reserve token),
     * calculates the return for a given conversion (in the main token)
     *
     * Formula:
     * Return = _supply * ((1 + _depositAmount / _reserveBalance) ^ (_reserveRatio / 1000000) - 1)
     *
     * @param _supply              token total supply
     * @param _reserveBalance      total reserve balance
     * @param _reserveRatio        reserve ratio, represented in ppm, 1-1000000
     * @param _depositAmount       deposit amount, in reserve token
     *
     * @return purchase return amount
     */
    function calculatePurchaseReturn(
        uint256 _supply,
        uint256 _reserveBalance,
        uint32 _reserveRatio,
        uint256 _depositAmount
    ) public view returns (uint256) {
        // validate input
        require(
            _supply > 0 &&
                _reserveBalance > 0 &&
                _reserveRatio > 0 &&
                _reserveRatio <= MAX_RATIO
        );

        // special case for 0 deposit amount
        if (_depositAmount == 0) return 0;

        // special case if the ratio = 100%
        if (_reserveRatio == MAX_RATIO)
            return _supply.mul(_depositAmount) / _reserveBalance;

        uint256 result;
        uint8 precision;
        uint256 baseN = _depositAmount.add(_reserveBalance);
        (result, precision) = power(baseN, _reserveBalance, _reserveRatio, MAX_RATIO);
        uint256 temp = _supply.mul(result) >> precision;
        return temp - _supply;
    }

    /**
     * @dev given a token supply, reserve balance, ratio and a sell amount (in the main token),
     * calculates the return for a given conversion (in the reserve token)
     *
     * Formula:
     * Return = _reserveBalance * (1 - (1 - _sellAmount / _supply) ^ (1000000 / _reserveRatio))
     *
     * @param _supply              token total supply
     * @param _reserveBalance      total reserve
     * @param _reserveRatio        constant reserve Ratio, represented in ppm, 1-1000000
     * @param _sellAmount          sell amount, in the token itself
     *
     * @return sale return amount
     */
    function calculateSaleReturn(
        uint256 _supply,
        uint256 _reserveBalance,
        uint32 _reserveRatio,
        uint256 _sellAmount
    ) public view returns (uint256) {
        // validate input
        require(
            _supply > 0 &&
                _reserveBalance > 0 &&
                _reserveRatio > 0 &&
                _reserveRatio <= MAX_RATIO &&
                _sellAmount <= _supply
        );

        // special case for 0 sell amount
        if (_sellAmount == 0) return 0;

        // special case for selling the entire supply
        if (_sellAmount == _supply) return _reserveBalance;

        // special case if the ratio = 100%
        if (_reserveRatio == MAX_RATIO) return _reserveBalance.mul(_sellAmount) / _supply;

        uint256 result;
        uint8 precision;
        uint256 baseD = _supply - _sellAmount;
        (result, precision) = power(_supply, baseD, MAX_RATIO, _reserveRatio);
        uint256 temp1 = _reserveBalance.mul(result);
        uint256 temp2 = _reserveBalance << precision;
        return (temp1 - temp2) / result;
    }

    /**
     * @dev given two reserve balances/ratios and a sell amount (in the first reserve token),
     * calculates the return for a conversion from the first reserve token to the second reserve token (in the second reserve token)
     * note that prior to version 4, you should use 'calculateCrossConnectorReturn' instead
     *
     * Formula:
     * Return = _toReserveBalance * (1 - (_fromReserveBalance / (_fromReserveBalance + _amount)) ^ (_fromReserveRatio / _toReserveRatio))
     *
     * @param _fromReserveBalance      input reserve balance
     * @param _fromReserveRatio        input reserve ratio, represented in ppm, 1-1000000
     * @param _toReserveBalance        output reserve balance
     * @param _toReserveRatio          output reserve ratio, represented in ppm, 1-1000000
     * @param _amount                  input reserve amount
     *
     * @return second reserve amount
     */
    function calculateCrossReserveReturn(
        uint256 _fromReserveBalance,
        uint32 _fromReserveRatio,
        uint256 _toReserveBalance,
        uint32 _toReserveRatio,
        uint256 _amount
    ) public view returns (uint256) {
        // validate input
        require(
            _fromReserveBalance > 0 &&
                _fromReserveRatio > 0 &&
                _fromReserveRatio <= MAX_RATIO &&
                _toReserveBalance > 0 &&
                _toReserveRatio > 0 &&
                _toReserveRatio <= MAX_RATIO
        );

        // special case for equal ratios
        if (_fromReserveRatio == _toReserveRatio)
            return _toReserveBalance.mul(_amount) / _fromReserveBalance.add(_amount);

        uint256 result;
        uint8 precision;
        uint256 baseN = _fromReserveBalance.add(_amount);
        (result, precision) = power(
            baseN,
            _fromReserveBalance,
            _fromReserveRatio,
            _toReserveRatio
        );
        uint256 temp1 = _toReserveBalance.mul(result);
        uint256 temp2 = _toReserveBalance << precision;
        return (temp1 - temp2) / result;
    }

    /**
     * @dev given a smart token supply, reserve balance, total ratio and an amount of requested smart tokens,
     * calculates the amount of reserve tokens required for purchasing the given amount of smart tokens
     *
     * Formula:
     * Return = _reserveBalance * (((_supply + _amount) / _supply) ^ (MAX_RATIO / _totalRatio) - 1)
     *
     * @param _supply              smart token supply
     * @param _reserveBalance      reserve token balance
     * @param _totalRatio          total ratio, represented in ppm, 2-2000000
     * @param _amount              requested amount of smart tokens
     *
     * @return amount of reserve tokens
     */
    function calculateFundCost(
        uint256 _supply,
        uint256 _reserveBalance,
        uint32 _totalRatio,
        uint256 _amount
    ) public view returns (uint256) {
        // validate input
        require(
            _supply > 0 &&
                _reserveBalance > 0 &&
                _totalRatio > 1 &&
                _totalRatio <= MAX_RATIO * 2
        );

        // special case for 0 amount
        if (_amount == 0) return 0;

        // special case if the total ratio = 100%
        if (_totalRatio == MAX_RATIO)
            return (_amount.mul(_reserveBalance) - 1) / _supply + 1;

        uint256 result;
        uint8 precision;
        uint256 baseN = _supply.add(_amount);
        (result, precision) = power(baseN, _supply, MAX_RATIO, _totalRatio);
        uint256 temp = ((_reserveBalance.mul(result) - 1) >> precision) + 1;
        return temp - _reserveBalance;
    }

    /**
     * @dev given a smart token supply, reserve balance, total ratio and an amount of smart tokens to liquidate,
     * calculates the amount of reserve tokens received for selling the given amount of smart tokens
     *
     * Formula:
     * Return = _reserveBalance * (1 - ((_supply - _amount) / _supply) ^ (MAX_RATIO / _totalRatio))
     *
     * @param _supply              smart token supply
     * @param _reserveBalance      reserve token balance
     * @param _totalRatio          total ratio, represented in ppm, 2-2000000
     * @param _amount              amount of smart tokens to liquidate
     *
     * @return amount of reserve tokens
     */
    function calculateLiquidateReturn(
        uint256 _supply,
        uint256 _reserveBalance,
        uint32 _totalRatio,
        uint256 _amount
    ) public view returns (uint256) {
        // validate input
        require(
            _supply > 0 &&
                _reserveBalance > 0 &&
                _totalRatio > 1 &&
                _totalRatio <= MAX_RATIO * 2 &&
                _amount <= _supply
        );

        // special case for 0 amount
        if (_amount == 0) return 0;

        // special case for liquidating the entire supply
        if (_amount == _supply) return _reserveBalance;

        // special case if the total ratio = 100%
        if (_totalRatio == MAX_RATIO) return _amount.mul(_reserveBalance) / _supply;

        uint256 result;
        uint8 precision;
        uint256 baseD = _supply - _amount;
        (result, precision) = power(_supply, baseD, MAX_RATIO, _totalRatio);
        uint256 temp1 = _reserveBalance.mul(result);
        uint256 temp2 = _reserveBalance << precision;
        return (temp1 - temp2) / result;
    }

    /**
     * @dev General Description:
     *     Determine a value of precision.
     *     Calculate an integer approximation of (_baseN / _baseD) ^ (_expN / _expD) * 2 ^ precision.
     *     Return the result along with the precision used.
     *
     * Detailed Description:
     *     Instead of calculating "base ^ exp", we calculate "e ^ (log(base) * exp)".
     *     The value of "log(base)" is represented with an integer slightly smaller than "log(base) * 2 ^ precision".
     *     The larger "precision" is, the more accurately this value represents the real value.
     *     However, the larger "precision" is, the more bits are required in order to store this value.
     *     And the exponentiation function, which takes "x" and calculates "e ^ x", is limited to a maximum exponent (maximum value of "x").
     *     This maximum exponent depends on the "precision" used, and it is given by "maxExpArray[precision] >> (MAX_PRECISION - precision)".
     *     Hence we need to determine the highest precision which can be used for the given input, before calling the exponentiation function.
     *     This allows us to compute "base ^ exp" with maximum accuracy and without exceeding 256 bits in any of the intermediate computations.
     *     This functions assumes that "_expN < 2 ^ 256 / log(MAX_NUM - 1)", otherwise the multiplication should be replaced with a "safeMul".
     *     Since we rely on unsigned-integer arithmetic and "base < 1" ==> "log(base) < 0", this function does not support "_baseN < _baseD".
     */
    function power(
        uint256 _baseN,
        uint256 _baseD,
        uint32 _expN,
        uint32 _expD
    ) internal view returns (uint256, uint8) {
        require(_baseN < MAX_NUM);

        uint256 baseLog;
        uint256 base = (_baseN * FIXED_1) / _baseD;
        if (base < OPT_LOG_MAX_VAL) {
            baseLog = optimalLog(base);
        } else {
            baseLog = generalLog(base);
        }

        uint256 baseLogTimesExp = (baseLog * _expN) / _expD;
        if (baseLogTimesExp < OPT_EXP_MAX_VAL) {
            return (optimalExp(baseLogTimesExp), MAX_PRECISION);
        } else {
            uint8 precision = findPositionInMaxExpArray(baseLogTimesExp);
            return (
                generalExp(baseLogTimesExp >> (MAX_PRECISION - precision), precision),
                precision
            );
        }
    }

    /**
     * @dev computes log(x / FIXED_1) * FIXED_1.
     * This functions assumes that "x >= FIXED_1", because the output would be negative otherwise.
     */
    function generalLog(uint256 x) internal pure returns (uint256) {
        uint256 res = 0;

        // If x >= 2, then we compute the integer part of log2(x), which is larger than 0.
        if (x >= FIXED_2) {
            uint8 count = floorLog2(x / FIXED_1);
            x >>= count; // now x < 2
            res = count * FIXED_1;
        }

        // If x > 1, then we compute the fraction part of log2(x), which is larger than 0.
        if (x > FIXED_1) {
            for (uint8 i = MAX_PRECISION; i > 0; --i) {
                x = (x * x) / FIXED_1; // now 1 < x < 4
                if (x >= FIXED_2) {
                    x >>= 1; // now 1 < x < 2
                    res += ONE << (i - 1);
                }
            }
        }

        return (res * LN2_NUMERATOR) / LN2_DENOMINATOR;
    }

    /**
     * @dev computes the largest integer smaller than or equal to the binary logarithm of the input.
     */
    function floorLog2(uint256 _n) internal pure returns (uint8) {
        uint8 res = 0;

        if (_n < 256) {
            // At most 8 iterations
            while (_n > 1) {
                _n >>= 1;
                res += 1;
            }
        } else {
            // Exactly 8 iterations
            for (uint8 s = 128; s > 0; s >>= 1) {
                if (_n >= (ONE << s)) {
                    _n >>= s;
                    res |= s;
                }
            }
        }

        return res;
    }

    /**
     * @dev the global "maxExpArray" is sorted in descending order, and therefore the following statements are equivalent:
     * - This function finds the position of [the smallest value in "maxExpArray" larger than or equal to "x"]
     * - This function finds the highest position of [a value in "maxExpArray" larger than or equal to "x"]
     */
    function findPositionInMaxExpArray(uint256 _x) internal view returns (uint8) {
        uint8 lo = MIN_PRECISION;
        uint8 hi = MAX_PRECISION;

        while (lo + 1 < hi) {
            uint8 mid = (lo + hi) / 2;
            if (maxExpArray[mid] >= _x) lo = mid;
            else hi = mid;
        }

        if (maxExpArray[hi] >= _x) return hi;
        if (maxExpArray[lo] >= _x) return lo;

        require(false);
        return 0;
    }

    /**
     * @dev this function can be auto-generated by the script 'PrintFunctionGeneralExp.py'.
     * it approximates "e ^ x" via maclaurin summation: "(x^0)/0! + (x^1)/1! + ... + (x^n)/n!".
     * it returns "e ^ (x / 2 ^ precision) * 2 ^ precision", that is, the result is upshifted for accuracy.
     * the global "maxExpArray" maps each "precision" to "((maximumExponent + 1) << (MAX_PRECISION - precision)) - 1".
     * the maximum permitted value for "x" is therefore given by "maxExpArray[precision] >> (MAX_PRECISION - precision)".
     */
    function generalExp(uint256 _x, uint8 _precision) internal pure returns (uint256) {
        uint256 xi = _x;
        uint256 res = 0;

        xi = (xi * _x) >> _precision;
        res += xi * 0x3442c4e6074a82f1797f72ac0000000; // add x^02 * (33! / 02!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x116b96f757c380fb287fd0e40000000; // add x^03 * (33! / 03!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x045ae5bdd5f0e03eca1ff4390000000; // add x^04 * (33! / 04!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00defabf91302cd95b9ffda50000000; // add x^05 * (33! / 05!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x002529ca9832b22439efff9b8000000; // add x^06 * (33! / 06!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00054f1cf12bd04e516b6da88000000; // add x^07 * (33! / 07!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000a9e39e257a09ca2d6db51000000; // add x^08 * (33! / 08!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x000012e066e7b839fa050c309000000; // add x^09 * (33! / 09!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x000001e33d7d926c329a1ad1a800000; // add x^10 * (33! / 10!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000002bee513bdb4a6b19b5f800000; // add x^11 * (33! / 11!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000003a9316fa79b88eccf2a00000; // add x^12 * (33! / 12!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000048177ebe1fa812375200000; // add x^13 * (33! / 13!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000005263fe90242dcbacf00000; // add x^14 * (33! / 14!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x000000000057e22099c030d94100000; // add x^15 * (33! / 15!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000000057e22099c030d9410000; // add x^16 * (33! / 16!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000000000052b6b54569976310000; // add x^17 * (33! / 17!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000000000004985f67696bf748000; // add x^18 * (33! / 18!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x000000000000003dea12ea99e498000; // add x^19 * (33! / 19!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000000000000031880f2214b6e000; // add x^20 * (33! / 20!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x000000000000000025bcff56eb36000; // add x^21 * (33! / 21!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x000000000000000001b722e10ab1000; // add x^22 * (33! / 22!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000000000000001317c70077000; // add x^23 * (33! / 23!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000000000000000000cba84aafa00; // add x^24 * (33! / 24!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000000000000000000082573a0a00; // add x^25 * (33! / 25!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000000000000000000005035ad900; // add x^26 * (33! / 26!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x000000000000000000000002f881b00; // add x^27 * (33! / 27!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000000000000000000001b29340; // add x^28 * (33! / 28!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x00000000000000000000000000efc40; // add x^29 * (33! / 29!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000000000000000000000007fe0; // add x^30 * (33! / 30!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000000000000000000000000420; // add x^31 * (33! / 31!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000000000000000000000000021; // add x^32 * (33! / 32!)
        xi = (xi * _x) >> _precision;
        res += xi * 0x0000000000000000000000000000001; // add x^33 * (33! / 33!)

        return res / 0x688589cc0e9505e2f2fee5580000000 + _x + (ONE << _precision); // divide by 33! and then add x^1 / 1! + x^0 / 0!
    }

    /**
     * @dev computes log(x / FIXED_1) * FIXED_1
     * Input range: FIXED_1 <= x <= LOG_EXP_MAX_VAL - 1
     * Auto-generated via 'PrintFunctionOptimalLog.py'
     * Detailed description:
     * - Rewrite the input as a product of natural exponents and a single residual r, such that 1 < r < 2
     * - The natural logarithm of each (pre-calculated) exponent is the degree of the exponent
     * - The natural logarithm of r is calculated via Taylor series for log(1 + x), where x = r - 1
     * - The natural logarithm of the input is calculated by summing up the intermediate results above
     * - For example: log(250) = log(e^4 * e^1 * e^0.5 * 1.021692859) = 4 + 1 + 0.5 + log(1 + 0.021692859)
     */
    function optimalLog(uint256 x) internal pure returns (uint256) {
        uint256 res = 0;

        uint256 y;
        uint256 z;
        uint256 w;

        if (x >= 0xd3094c70f034de4b96ff7d5b6f99fcd8) {
            res += 0x40000000000000000000000000000000;
            x = (x * FIXED_1) / 0xd3094c70f034de4b96ff7d5b6f99fcd8;
        } // add 1 / 2^1
        if (x >= 0xa45af1e1f40c333b3de1db4dd55f29a7) {
            res += 0x20000000000000000000000000000000;
            x = (x * FIXED_1) / 0xa45af1e1f40c333b3de1db4dd55f29a7;
        } // add 1 / 2^2
        if (x >= 0x910b022db7ae67ce76b441c27035c6a1) {
            res += 0x10000000000000000000000000000000;
            x = (x * FIXED_1) / 0x910b022db7ae67ce76b441c27035c6a1;
        } // add 1 / 2^3
        if (x >= 0x88415abbe9a76bead8d00cf112e4d4a8) {
            res += 0x08000000000000000000000000000000;
            x = (x * FIXED_1) / 0x88415abbe9a76bead8d00cf112e4d4a8;
        } // add 1 / 2^4
        if (x >= 0x84102b00893f64c705e841d5d4064bd3) {
            res += 0x04000000000000000000000000000000;
            x = (x * FIXED_1) / 0x84102b00893f64c705e841d5d4064bd3;
        } // add 1 / 2^5
        if (x >= 0x8204055aaef1c8bd5c3259f4822735a2) {
            res += 0x02000000000000000000000000000000;
            x = (x * FIXED_1) / 0x8204055aaef1c8bd5c3259f4822735a2;
        } // add 1 / 2^6
        if (x >= 0x810100ab00222d861931c15e39b44e99) {
            res += 0x01000000000000000000000000000000;
            x = (x * FIXED_1) / 0x810100ab00222d861931c15e39b44e99;
        } // add 1 / 2^7
        if (x >= 0x808040155aabbbe9451521693554f733) {
            res += 0x00800000000000000000000000000000;
            x = (x * FIXED_1) / 0x808040155aabbbe9451521693554f733;
        } // add 1 / 2^8

        z = y = x - FIXED_1;
        w = (y * y) / FIXED_1;
        res +=
            (z * (0x100000000000000000000000000000000 - y)) /
            0x100000000000000000000000000000000;
        z = (z * w) / FIXED_1; // add y^01 / 01 - y^02 / 02
        res +=
            (z * (0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - y)) /
            0x200000000000000000000000000000000;
        z = (z * w) / FIXED_1; // add y^03 / 03 - y^04 / 04
        res +=
            (z * (0x099999999999999999999999999999999 - y)) /
            0x300000000000000000000000000000000;
        z = (z * w) / FIXED_1; // add y^05 / 05 - y^06 / 06
        res +=
            (z * (0x092492492492492492492492492492492 - y)) /
            0x400000000000000000000000000000000;
        z = (z * w) / FIXED_1; // add y^07 / 07 - y^08 / 08
        res +=
            (z * (0x08e38e38e38e38e38e38e38e38e38e38e - y)) /
            0x500000000000000000000000000000000;
        z = (z * w) / FIXED_1; // add y^09 / 09 - y^10 / 10
        res +=
            (z * (0x08ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b - y)) /
            0x600000000000000000000000000000000;
        z = (z * w) / FIXED_1; // add y^11 / 11 - y^12 / 12
        res +=
            (z * (0x089d89d89d89d89d89d89d89d89d89d89 - y)) /
            0x700000000000000000000000000000000;
        z = (z * w) / FIXED_1; // add y^13 / 13 - y^14 / 14
        res +=
            (z * (0x088888888888888888888888888888888 - y)) /
            0x800000000000000000000000000000000; // add y^15 / 15 - y^16 / 16

        return res;
    }

    /**
     * @dev computes e ^ (x / FIXED_1) * FIXED_1
     * input range: 0 <= x <= OPT_EXP_MAX_VAL - 1
     * auto-generated via 'PrintFunctionOptimalExp.py'
     * Detailed description:
     * - Rewrite the input as a sum of binary exponents and a single residual r, as small as possible
     * - The exponentiation of each binary exponent is given (pre-calculated)
     * - The exponentiation of r is calculated via Taylor series for e^x, where x = r
     * - The exponentiation of the input is calculated by multiplying the intermediate results above
     * - For example: e^5.521692859 = e^(4 + 1 + 0.5 + 0.021692859) = e^4 * e^1 * e^0.5 * e^0.021692859
     */
    function optimalExp(uint256 x) internal pure returns (uint256) {
        uint256 res = 0;

        uint256 y;
        uint256 z;

        z = y = x % 0x10000000000000000000000000000000; // get the input modulo 2^(-3)
        z = (z * y) / FIXED_1;
        res += z * 0x10e1b3be415a0000; // add y^02 * (20! / 02!)
        z = (z * y) / FIXED_1;
        res += z * 0x05a0913f6b1e0000; // add y^03 * (20! / 03!)
        z = (z * y) / FIXED_1;
        res += z * 0x0168244fdac78000; // add y^04 * (20! / 04!)
        z = (z * y) / FIXED_1;
        res += z * 0x004807432bc18000; // add y^05 * (20! / 05!)
        z = (z * y) / FIXED_1;
        res += z * 0x000c0135dca04000; // add y^06 * (20! / 06!)
        z = (z * y) / FIXED_1;
        res += z * 0x0001b707b1cdc000; // add y^07 * (20! / 07!)
        z = (z * y) / FIXED_1;
        res += z * 0x000036e0f639b800; // add y^08 * (20! / 08!)
        z = (z * y) / FIXED_1;
        res += z * 0x00000618fee9f800; // add y^09 * (20! / 09!)
        z = (z * y) / FIXED_1;
        res += z * 0x0000009c197dcc00; // add y^10 * (20! / 10!)
        z = (z * y) / FIXED_1;
        res += z * 0x0000000e30dce400; // add y^11 * (20! / 11!)
        z = (z * y) / FIXED_1;
        res += z * 0x000000012ebd1300; // add y^12 * (20! / 12!)
        z = (z * y) / FIXED_1;
        res += z * 0x0000000017499f00; // add y^13 * (20! / 13!)
        z = (z * y) / FIXED_1;
        res += z * 0x0000000001a9d480; // add y^14 * (20! / 14!)
        z = (z * y) / FIXED_1;
        res += z * 0x00000000001c6380; // add y^15 * (20! / 15!)
        z = (z * y) / FIXED_1;
        res += z * 0x000000000001c638; // add y^16 * (20! / 16!)
        z = (z * y) / FIXED_1;
        res += z * 0x0000000000001ab8; // add y^17 * (20! / 17!)
        z = (z * y) / FIXED_1;
        res += z * 0x000000000000017c; // add y^18 * (20! / 18!)
        z = (z * y) / FIXED_1;
        res += z * 0x0000000000000014; // add y^19 * (20! / 19!)
        z = (z * y) / FIXED_1;
        res += z * 0x0000000000000001; // add y^20 * (20! / 20!)
        res = res / 0x21c3677c82b40000 + y + FIXED_1; // divide by 20! and then add y^1 / 1! + y^0 / 0!

        if ((x & 0x010000000000000000000000000000000) != 0)
            res =
                (res * 0x1c3d6a24ed82218787d624d3e5eba95f9) /
                0x18ebef9eac820ae8682b9793ac6d1e776; // multiply by e^2^(-3)
        if ((x & 0x020000000000000000000000000000000) != 0)
            res =
                (res * 0x18ebef9eac820ae8682b9793ac6d1e778) /
                0x1368b2fc6f9609fe7aceb46aa619baed4; // multiply by e^2^(-2)
        if ((x & 0x040000000000000000000000000000000) != 0)
            res =
                (res * 0x1368b2fc6f9609fe7aceb46aa619baed5) /
                0x0bc5ab1b16779be3575bd8f0520a9f21f; // multiply by e^2^(-1)
        if ((x & 0x080000000000000000000000000000000) != 0)
            res =
                (res * 0x0bc5ab1b16779be3575bd8f0520a9f21e) /
                0x0454aaa8efe072e7f6ddbab84b40a55c9; // multiply by e^2^(+0)
        if ((x & 0x100000000000000000000000000000000) != 0)
            res =
                (res * 0x0454aaa8efe072e7f6ddbab84b40a55c5) /
                0x00960aadc109e7a3bf4578099615711ea; // multiply by e^2^(+1)
        if ((x & 0x200000000000000000000000000000000) != 0)
            res =
                (res * 0x00960aadc109e7a3bf4578099615711d7) /
                0x0002bf84208204f5977f9a8cf01fdce3d; // multiply by e^2^(+2)
        if ((x & 0x400000000000000000000000000000000) != 0)
            res =
                (res * 0x0002bf84208204f5977f9a8cf01fdc307) /
                0x0000003c6ab775dd0b95b4cbee7e65d11; // multiply by e^2^(+3)

        return res;
    }

    /**
     * @dev deprecated, backward compatibility
     */
    function calculateCrossConnectorReturn(
        uint256 _fromConnectorBalance,
        uint32 _fromConnectorWeight,
        uint256 _toConnectorBalance,
        uint32 _toConnectorWeight,
        uint256 _amount
    ) public view returns (uint256) {
        return
            calculateCrossReserveReturn(
                _fromConnectorBalance,
                _fromConnectorWeight,
                _toConnectorBalance,
                _toConnectorWeight,
                _amount
            );
    }
}

/**
@title Dynamic reserve ratio market maker
*/
contract GoodMarketMaker is BancorFormula, DSMath, SchemeGuard {
    using SafeMath for uint256;

    // For calculate the return value on buy and sell
    BancorFormula bancor;

    // Entity that holds a reserve token
    struct ReserveToken {
        // Determines the reserve token balance
        // that the reserve contract holds
        uint256 reserveSupply;
        // Determines the current ratio between
        // the reserve token and the GD token
        uint32 reserveRatio;
        // How many GD tokens have been minted
        // against that reserve token
        uint256 gdSupply;
    }

    // The map which holds the reserve token entities
    mapping(address => ReserveToken) public reserveTokens;

    // Emits when a change has occurred in a
    // reserve balance, i.e. buy / sell will
    // change the balance
    event BalancesUpdated(
        // The account who initiated the action
        address indexed caller,
        // The address of the reserve token
        address indexed reserveToken,
        // The incoming amount
        uint256 amount,
        // The return value
        uint256 returnAmount,
        // The updated total supply
        uint256 totalSupply,
        // The updated reserve balance
        uint256 reserveBalance
    );

    // Emits when the ratio changed. The caller should be the Avatar by definition
    event ReserveRatioUpdated(address indexed caller, uint256 nom, uint256 denom);

    // Emits when new tokens should be minted
    // as a result of incoming interest.
    // That event will be emitted after the
    // reserve entity has been updated
    event InterestMinted(
        // The account who initiated the action
        address indexed caller,
        // The address of the reserve token
        address indexed reserveToken,
        // How much new reserve tokens been
        // added to the reserve balance
        uint256 addInterest,
        // The GD supply in the reserve entity
        // before the new minted GD tokens were
        // added to the supply
        uint256 oldSupply,
        // The number of the new minted GD tokens
        uint256 mint
    );

    // Emits when new tokens should be minted
    // as a result of a reserve ratio expansion
    // change. This change should have occurred
    // on a regular basis. That event will be
    // emitted after the reserve entity has been
    // updated
    event UBIExpansionMinted(
        // The account who initiated the action
        address indexed caller,
        // The address of the reserve token
        address indexed reserveToken,
        // The reserve ratio before the expansion
        uint256 oldReserveRatio,
        // The GD supply in the reserve entity
        // before the new minted GD tokens were
        // added to the supply
        uint256 oldSupply,
        // The number of the new minted GD tokens
        uint256 mint
    );

    // Defines the daily change in the reserve ratio in RAY precision.
    // In the current release, only global ratio expansion is supported.
    // That will be a part of each reserve token entity in the future.
    uint256 public reserveRatioDailyExpansion;

    /**
     * @dev Constructor
     * @param _avatar The avatar of the DAO
     * @param _nom The numerator to calculate the global `reserveRatioDailyExpansion` from
     * @param _denom The denominator to calculate the global `reserveRatioDailyExpansion` from
     */
    constructor(
        Avatar _avatar,
        uint256 _nom,
        uint256 _denom
    ) public SchemeGuard(_avatar) {
        reserveRatioDailyExpansion = rdiv(_nom, _denom);
    }

    modifier onlyActiveToken(ERC20 _token) {
        ReserveToken storage rtoken = reserveTokens[address(_token)];
        require(rtoken.gdSupply > 0, "Reserve token not initialized");
        _;
    }

    /**
     * @dev Allows the DAO to change the daily expansion rate
     * it is calculated by _nom/_denom with e27 precision. Emits
     * `ReserveRatioUpdated` event after the ratio has changed.
     * Only Avatar can call this method.
     * @param _nom The numerator to calculate the global `reserveRatioDailyExpansion` from
     * @param _denom The denominator to calculate the global `reserveRatioDailyExpansion` from
     */
    function setReserveRatioDailyExpansion(uint256 _nom, uint256 _denom)
        public
        onlyAvatar
    {
        require(_denom > 0, "denominator must be above 0");
        reserveRatioDailyExpansion = rdiv(_nom, _denom);
        emit ReserveRatioUpdated(msg.sender, _nom, _denom);
    }

    // NOTICE: In the current release, if there is a wish to add another reserve token,
    //  `end` method in the reserve contract should be called first. Then, the DAO have
    //  to deploy a new reserve contract that will own the market maker. A scheme for
    // updating the new reserve must be deployed too.

    /**
     * @dev Initialize a reserve token entity with the given parameters
     * @param _token The reserve token
     * @param _gdSupply Initial supply of GD to set the price
     * @param _tokenSupply Initial supply of reserve token to set the price
     * @param _reserveRatio The starting reserve ratio
     */
    function initializeToken(
        ERC20 _token,
        uint256 _gdSupply,
        uint256 _tokenSupply,
        uint32 _reserveRatio
    ) public onlyOwner {
        reserveTokens[address(_token)] = ReserveToken({
            gdSupply: _gdSupply,
            reserveSupply: _tokenSupply,
            reserveRatio: _reserveRatio
        });
    }

    /**
     * @dev Calculates how much to decrease the reserve ratio for _token by
     * the `reserveRatioDailyExpansion`
     * @param _token The reserve token to calculate the reserve ratio for
     * @return The new reserve ratio
     */
    function calculateNewReserveRatio(ERC20 _token)
        public
        view
        onlyActiveToken(_token)
        returns (uint32)
    {
        ReserveToken memory reserveToken = reserveTokens[address(_token)];
        uint32 ratio = reserveToken.reserveRatio;
        if (ratio == 0) {
            ratio = 1e6;
        }
        return
            uint32(
                rmul(
                    uint256(ratio).mul(1e21), // expand to e27 precision
                    reserveRatioDailyExpansion
                )
                    .div(1e21) // return to e6 precision
            );
    }

    /**
     * @dev Decreases the reserve ratio for _token by the `reserveRatioDailyExpansion`
     * @param _token The token to change the reserve ratio for
     * @return The new reserve ratio
     */
    function expandReserveRatio(ERC20 _token)
        public
        onlyOwner
        onlyActiveToken(_token)
        returns (uint32)
    {
        ReserveToken storage reserveToken = reserveTokens[address(_token)];
        uint32 ratio = reserveToken.reserveRatio;
        if (ratio == 0) {
            ratio = 1e6;
        }
        reserveToken.reserveRatio = calculateNewReserveRatio(_token);
        return reserveToken.reserveRatio;
    }

    /**
     * @dev Calculates the buy return in GD according to the given _tokenAmount
     * @param _token The reserve token buying with
     * @param _tokenAmount The amount of reserve token buying with
     * @return Number of GD that should be given in exchange as calculated by the bonding curve
     */
    function buyReturn(ERC20 _token, uint256 _tokenAmount)
        public
        view
        onlyActiveToken(_token)
        returns (uint256)
    {
        ReserveToken memory rtoken = reserveTokens[address(_token)];
        return
            calculatePurchaseReturn(
                rtoken.gdSupply,
                rtoken.reserveSupply,
                rtoken.reserveRatio,
                _tokenAmount
            );
    }

    /**
     * @dev Calculates the sell return in _token according to the given _gdAmount
     * @param _token The desired reserve token to have
     * @param _gdAmount The amount of GD that are sold
     * @return Number of tokens that should be given in exchange as calculated by the bonding curve
     */
    function sellReturn(ERC20 _token, uint256 _gdAmount)
        public
        view
        onlyActiveToken(_token)
        returns (uint256)
    {
        ReserveToken memory rtoken = reserveTokens[address(_token)];
        return
            calculateSaleReturn(
                rtoken.gdSupply,
                rtoken.reserveSupply,
                rtoken.reserveRatio,
                _gdAmount
            );
    }

    /**
     * @dev Updates the _token bonding curve params. Emits `BalancesUpdated` with the
     * new reserve token information.
     * @param _token The reserve token buying with
     * @param _tokenAmount The amount of reserve token buying with
     * @return (gdReturn) Number of GD that will be given in exchange as calculated by the bonding curve
     */
    function buy(ERC20 _token, uint256 _tokenAmount)
        public
        onlyOwner
        onlyActiveToken(_token)
        returns (uint256)
    {
        uint256 gdReturn = buyReturn(_token, _tokenAmount);
        ReserveToken storage rtoken = reserveTokens[address(_token)];
        rtoken.gdSupply = rtoken.gdSupply.add(gdReturn);
        rtoken.reserveSupply = rtoken.reserveSupply.add(_tokenAmount);
        emit BalancesUpdated(
            msg.sender,
            address(_token),
            _tokenAmount,
            gdReturn,
            rtoken.gdSupply,
            rtoken.reserveSupply
        );
        return gdReturn;
    }

    /**
     * @dev Updates the _token bonding curve params. Emits `BalancesUpdated` with the
     * new reserve token information.
     * @param _token The desired reserve token to have
     * @param _gdAmount The amount of GD that are sold
     * @return Number of tokens that will be given in exchange as calculated by the bonding curve
     */
    function sell(ERC20 _token, uint256 _gdAmount)
        public
        onlyOwner
        onlyActiveToken(_token)
        returns (uint256)
    {
        ReserveToken storage rtoken = reserveTokens[address(_token)];
        require(rtoken.gdSupply > _gdAmount, "GD amount is higher than the total supply");
        uint256 tokenReturn = sellReturn(_token, _gdAmount);
        rtoken.gdSupply = rtoken.gdSupply.sub(_gdAmount);
        rtoken.reserveSupply = rtoken.reserveSupply.sub(tokenReturn);
        emit BalancesUpdated(
            msg.sender,
            address(_token),
            _gdAmount,
            tokenReturn,
            rtoken.gdSupply,
            rtoken.reserveSupply
        );
        return tokenReturn;
    }

    /**
     * @dev Calculates the sell return with contribution in _token and update the bonding curve params.
     * Emits `BalancesUpdated` with the new reserve token information.
     * @param _token The desired reserve token to have
     * @param _gdAmount The amount of GD that are sold
     * @param _contributionGdAmount The number of GD tokens that will not be traded for the reserve token
     * @return Number of tokens that will be given in exchange as calculated by the bonding curve
     */
    function sellWithContribution(
        ERC20 _token,
        uint256 _gdAmount,
        uint256 _contributionGdAmount
    ) public onlyOwner onlyActiveToken(_token) returns (uint256) {
        require(
            _gdAmount >= _contributionGdAmount,
            "GD amount is lower than the contribution amount"
        );
        ReserveToken storage rtoken = reserveTokens[address(_token)];
        require(rtoken.gdSupply > _gdAmount, "GD amount is higher than the total supply");

        // Deduces the convertible amount of GD tokens by the given contribution amount
        uint256 amountAfterContribution = _gdAmount.sub(_contributionGdAmount);

        // The return value after the deduction
        uint256 tokenReturn = sellReturn(_token, amountAfterContribution);
        rtoken.gdSupply = rtoken.gdSupply.sub(_gdAmount);
        rtoken.reserveSupply = rtoken.reserveSupply.sub(tokenReturn);
        emit BalancesUpdated(
            msg.sender,
            address(_token),
            _contributionGdAmount,
            tokenReturn,
            rtoken.gdSupply,
            rtoken.reserveSupply
        );
        return tokenReturn;
    }

    /**
     * @dev Current price of GD in `token`. currently only cDAI is supported.
     * @param _token The desired reserve token to have
     * @return price of GD
     */
    function currentPrice(ERC20 _token)
        public
        view
        onlyActiveToken(_token)
        returns (uint256)
    {
        ReserveToken memory rtoken = reserveTokens[address(_token)];
        GoodDollar gooddollar = GoodDollar(address(avatar.nativeToken()));
        return
            calculateSaleReturn(
                rtoken.gdSupply,
                rtoken.reserveSupply,
                rtoken.reserveRatio,
                (10**uint256(gooddollar.decimals()))
            );
    }

    //TODO: need real calculation and tests
    /**
     * @dev Calculates how much G$ to mint based on added token supply (from interest)
     * and on current reserve ratio, in order to keep G$ price the same at the bonding curve
     * formula to calculate the gd to mint: gd to mint =
     * addreservebalance * (gdsupply / (reservebalance * reserveratio))
     * @param _token the reserve token
     * @param _addTokenSupply amount of token added to supply
     * @return how much to mint in order to keep price in bonding curve the same
     */
    function calculateMintInterest(ERC20 _token, uint256 _addTokenSupply)
        public
        view
        onlyActiveToken(_token)
        returns (uint256)
    {
        GoodDollar gooddollar = GoodDollar(address(avatar.nativeToken()));
        uint256 decimalsDiff = uint256(27).sub(uint256(gooddollar.decimals()));
        //resulting amount is in RAY precision
        //we divide by decimalsdiff to get precision in GD (2 decimals)
        return rdiv(_addTokenSupply, currentPrice(_token)).div(10**decimalsDiff);
    }

    /**
     * @dev Updates bonding curve based on _addTokenSupply and new minted amount
     * @param _token The reserve token
     * @param _addTokenSupply Amount of token added to supply
     * @return How much to mint in order to keep price in bonding curve the same
     */
    function mintInterest(ERC20 _token, uint256 _addTokenSupply)
        public
        onlyOwner
        returns (uint256)
    {
        if (_addTokenSupply == 0) {
            return 0;
        }
        uint256 toMint = calculateMintInterest(_token, _addTokenSupply);
        ReserveToken storage reserveToken = reserveTokens[address(_token)];
        uint256 gdSupply = reserveToken.gdSupply;
        uint256 reserveBalance = reserveToken.reserveSupply;
        reserveToken.gdSupply = gdSupply.add(toMint);
        reserveToken.reserveSupply = reserveBalance.add(_addTokenSupply);
        emit InterestMinted(
            msg.sender,
            address(_token),
            _addTokenSupply,
            gdSupply,
            toMint
        );
        return toMint;
    }

    /**
     * @dev Calculate how much G$ to mint based on expansion change (new reserve
     * ratio), in order to keep G$ price the same at the bonding curve. the
     * formula to calculate the gd to mint: gd to mint =
     * (reservebalance / (newreserveratio * currentprice)) - gdsupply
     * @param _token The reserve token
     * @return How much to mint in order to keep price in bonding curve the same
     */
    function calculateMintExpansion(ERC20 _token)
        public
        view
        onlyActiveToken(_token)
        returns (uint256)
    {
        ReserveToken memory reserveToken = reserveTokens[address(_token)];
        uint32 newReserveRatio = calculateNewReserveRatio(_token); // new reserve ratio
        uint256 reserveDecimalsDiff = uint256(
            uint256(27).sub(ERC20Detailed(address(_token)).decimals())
        ); // //result is in RAY precision
        uint256 denom = rmul(
            uint256(newReserveRatio).mul(1e21),
            currentPrice(_token).mul(10**reserveDecimalsDiff)
        ); // (newreserveratio * currentprice) in RAY precision
        GoodDollar gooddollar = GoodDollar(address(avatar.nativeToken()));
        uint256 gdDecimalsDiff = uint256(27).sub(uint256(gooddollar.decimals()));
        uint256 toMint = rdiv(
            reserveToken.reserveSupply.mul(10**reserveDecimalsDiff), // reservebalance in RAY precision
            denom
        )
            .div(10**gdDecimalsDiff); // return to gd precision
        return toMint.sub(reserveToken.gdSupply);
    }

    /**
     * @dev Updates bonding curve based on expansion change and new minted amount
     * @param _token The reserve token
     * @return How much to mint in order to keep price in bonding curve the same
     */
    function mintExpansion(ERC20 _token) public onlyOwner returns (uint256) {
        uint256 toMint = calculateMintExpansion(_token);
        ReserveToken storage reserveToken = reserveTokens[address(_token)];
        uint256 gdSupply = reserveToken.gdSupply;
        uint256 ratio = reserveToken.reserveRatio;
        reserveToken.gdSupply = gdSupply.add(toMint);
        expandReserveRatio(_token);
        emit UBIExpansionMinted(msg.sender, address(_token), ratio, gdSupply, toMint);
        return toMint;
    }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract Avatar","name":"_avatar","type":"address"},{"internalType":"uint256","name":"_nom","type":"uint256"},{"internalType":"uint256","name":"_denom","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"reserveToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"returnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalSupply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reserveBalance","type":"uint256"}],"name":"BalancesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"reserveToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"addInterest","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"oldSupply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mint","type":"uint256"}],"name":"InterestMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"nom","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"denom","type":"uint256"}],"name":"ReserveRatioUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"reserveToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldReserveRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"oldSupply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mint","type":"uint256"}],"name":"UBIExpansionMinted","type":"event"},{"constant":false,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"}],"name":"buy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"}],"name":"buyReturn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"_fromConnectorBalance","type":"uint256"},{"internalType":"uint32","name":"_fromConnectorWeight","type":"uint32"},{"internalType":"uint256","name":"_toConnectorBalance","type":"uint256"},{"internalType":"uint32","name":"_toConnectorWeight","type":"uint32"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"calculateCrossConnectorReturn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"_fromReserveBalance","type":"uint256"},{"internalType":"uint32","name":"_fromReserveRatio","type":"uint32"},{"internalType":"uint256","name":"_toReserveBalance","type":"uint256"},{"internalType":"uint32","name":"_toReserveRatio","type":"uint32"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"calculateCrossReserveReturn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"_supply","type":"uint256"},{"internalType":"uint256","name":"_reserveBalance","type":"uint256"},{"internalType":"uint32","name":"_totalRatio","type":"uint32"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"calculateFundCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"_supply","type":"uint256"},{"internalType":"uint256","name":"_reserveBalance","type":"uint256"},{"internalType":"uint32","name":"_totalRatio","type":"uint32"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"calculateLiquidateReturn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"}],"name":"calculateMintExpansion","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_addTokenSupply","type":"uint256"}],"name":"calculateMintInterest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"}],"name":"calculateNewReserveRatio","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"_supply","type":"uint256"},{"internalType":"uint256","name":"_reserveBalance","type":"uint256"},{"internalType":"uint32","name":"_reserveRatio","type":"uint32"},{"internalType":"uint256","name":"_depositAmount","type":"uint256"}],"name":"calculatePurchaseReturn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"_supply","type":"uint256"},{"internalType":"uint256","name":"_reserveBalance","type":"uint256"},{"internalType":"uint32","name":"_reserveRatio","type":"uint32"},{"internalType":"uint256","name":"_sellAmount","type":"uint256"}],"name":"calculateSaleReturn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"}],"name":"currentPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"}],"name":"expandReserveRatio","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_gdSupply","type":"uint256"},{"internalType":"uint256","name":"_tokenSupply","type":"uint256"},{"internalType":"uint32","name":"_reserveRatio","type":"uint32"}],"name":"initializeToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isRegistered","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"scheme","type":"address"}],"name":"isRegistered","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"}],"name":"mintExpansion","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_addTokenSupply","type":"uint256"}],"name":"mintInterest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"reserveRatioDailyExpansion","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"reserveTokens","outputs":[{"internalType":"uint256","name":"reserveSupply","type":"uint256"},{"internalType":"uint32","name":"reserveRatio","type":"uint32"},{"internalType":"uint256","name":"gdSupply","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_gdAmount","type":"uint256"}],"name":"sell","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_gdAmount","type":"uint256"}],"name":"sellReturn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_gdAmount","type":"uint256"},{"internalType":"uint256","name":"_contributionGdAmount","type":"uint256"}],"name":"sellWithContribution","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract Avatar","name":"_avatar","type":"address"}],"name":"setAvatar","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_nom","type":"uint256"},{"internalType":"uint256","name":"_denom","type":"uint256"}],"name":"setReserveRatioDailyExpansion","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"payable":false,"stateMutability":"view","type":"function"}]

60806040526000805461ffff19166006179055608380546001600160a01b03191690553480156200002f57600080fd5b506040516200383c3803806200383c833981810160405260608110156200005557600080fd5b50805160208201516040928301516001641c35fedd1560601b036021556001646c3390ecc9605e1b036022556001640cf801476160611b0360235560016431bdb23e1d605f1b0360245560016502fb1d8fe083605b1b0360255560016505b771955b37605a1b036026556001650af67a93bb5160591b0360275560016515060c256cb360581b036028556001651428a2f98d7360581b036029556001654d515663970960561b03602a55600165944620b0e70f60551b03602b55600166011c592761c66760541b03602c5560016602214d10d014eb60531b03602d55600166020ade36b7dbef60531b03602e5560016603eab73b3bbfe360521b03602f556001660782ee3593f6d760511b036030556001661ccf4b44bb4821604f1b0360315560016606e7f88ad8a77760511b0360325560016669f3d1c921891d604d1b03603355600166cb2ff529eb71e5604c1b03603455600166c2d415c3db974b604c1b0360355560016702eb40f9f620fda7604a1b0360365560016705990681d961a1eb60491b03603755600167055e12902701414760491b0360385560016714962dee9dc9764160471b0360395560016704ef57b9b560fab560491b03603a5560016712ed7b32a58f552b60471b03603b556001679131271922eaa60760441b03603c556001678b380f3558668c4760441b03603d556001680215f77c045fbe885760421b03603e556001600160831b03603f556001670f577eded5773a1160471b0384556001680eb5ec597592befbf5603f1b036041556001681c35fedd14b861eb05603e1b036042556001683619c87664579bc94b603d1b0360435560016867c00a3b07ffc01fd7603c1b03604455600168c6f6c8f8739773a7a5603b1b03604555600168bec763f8209b7a72b1603b1b0360465560016902dbb8caad9b7097b91b60391b03604755600169057b3d49dda84556d6f760381b03604855600169054183095b2c8ececf3160381b036049556001690a14517cc6b9457111ef60371b03604a5560016913545598e5c23276ccf160361b03604b556001692511882c39c3adea96ff60351b03604c55600169471649d87199aa99075760341b03604d557004429a21a029d4c1457cfbffffffffffff604e55700415bc6d6fb7dd71af2cb3ffffffffffff604f557003eab73b3bbfe282243ce1ffffffffffff6050557003c1771ac9fb6b4c18e229ffffffffffff605155700399e96897690418f785257fffffffffff605255700373fc456c53bb779bf0ea9fffffffffff60535570034f9e8e490c48e67e6ab8bfffffffffff60545570032cbfd4a7adc790560b3337ffffffffff60555570030b50570f6e5d2acca94613ffffffffff6056557002eb40f9f620fda6b56c2861ffffffffff6057557002cc8340ecb0d0f520a6af58ffffffffff6058557002af09481380a0a35cf1ba02ffffffffff605955700292c5bdd3b92ec810287b1b3fffffffff605a55700277abdcdab07d5a77ac6d6b9fffffffff605b5570025daf6654b1eaa55fd64df5efffffffff605c55700244c49c648baa98192dce88b7ffffffff605d5570022ce03cd5619a311b2471268bffffffff605e55700215f77c045fbe885654a44a0fffffffff605f556001600160811b036060557001eaefdbdaaee7421fc4d3ede5ffffffff6061557001d6bd8b2eb257df7e8ca57b09bfffffff6062557001c35fedd14b861eb0443f7f133fffffff6063557001b0ce43b322bcde4a56e8ada5afffffff60645570019f0028ec1fff007f5a195a39dfffffff60655570018ded91f0e72ee74f49b15ba527ffffff60665570017d8ec7f04136f4e5615fd41a63ffffff60675570016ddc6556cdb84bdc8d12d22e6fffffff60685570015ecf52776a1155b5bd8395814f7fffff60695570015060c256cb23b3b3cc3754cf40ffffff606a557001428a2f98d728ae223ddab715be3fffff606b5570013545598e5c23276ccf0ede68034fffff606c557001288c4161ce1d6f54b7f61081194fffff606d5570011c592761c666aa641d5a01a40f17ffff606e55700110a688680a7530515f3e6e6cfdcdffff606f557001056f1b5bedf75c6bcb2ce8aed428ffff6070556ffaadceceeff8a0890f3875f008277fff6071556ff05dc6b27edad306388a600f6ba0bfff6072556fe67a5a25da41063de1495d5b18cdbfff6073556fdcff115b14eedde6fc3aa5353f2e4fff6074556fd3e7a3924312399f9aae2e0f868f8fff6075556fcb2ff529eb71e41582cccd5a1ee26fff6076556fc2d415c3db974ab32a51840c0b67edff6077556fbad03e7d883f69ad5b0a186184e06bff6078556fb320d03b2c343d4829abd6075f0cc5ff6079556fabc25204e02828d73c6e80bcdb1a95bf607a556fa4b16f74ee4bb2040a1ec6c15fbbf2df607b556f9deaf736ac1f569deb1b5ae3f36c130f607c556f976bd9952c7aa957f5937d790ef65037607d556f9131271922eaa6064b73a22d0bd4f2bf607e556f8b380f3558668c46c91c49a2f8e967b9607f556f857ddf0117efa215952912839f6473e6608055608180546001600160a01b031916331790819055935192939192909184916001600160a01b03909116906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3608280546001600160a01b0319166001600160a01b0383811691909117918290551615620008a257608260009054906101000a90046001600160a01b03166001600160a01b0316638da5cb5b6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200085457600080fd5b505afa15801562000869573d6000803e3d6000fd5b505050506040513d60208110156200088057600080fd5b5051608380546001600160a01b0319166001600160a01b039092169190911790555b50620008b882826001600160e01b03620008c516565b60865550620009de915050565b60008162000900620008ed856b033b2e3c9fd0803ce80000006001600160e01b036200091016565b600285046001600160e01b036200098516565b816200090857fe5b049392505050565b60008115806200092d575050808202828282816200092a57fe5b04145b6200097f576040805162461bcd60e51b815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b92915050565b808201828110156200097f576040805162461bcd60e51b815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b612e4e80620009ee6000396000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c80636cb4b4c1116101045780639f2d0d07116100a2578063cce7ec1311610071578063cce7ec1314610647578063e72a083314610673578063e9833c2f14610699578063f2fde38b146106bf576101da565b80639f2d0d071461059d578063abfd231d146105c0578063bc179d45146105f5578063c3c5a54714610621576101da565b806379c1b450116100de57806379c1b450146104eb578063835bbd55146105285780638da5cb5b146105715780638f32d59b14610595576101da565b80636cb4b4c1146104af578063715018a6146104b757806374920d30146104bf576101da565b806346f7cb231161017c5780635cf3a7a91161014b5780635cf3a7a9146103ee57806365098bb31461041a5780636a989e6e146104575780636c197ff514610483576101da565b806346f7cb231461033657806349f9b0f71461035c578063545bf97e1461039157806354fd4d50146103cf576101da565b806322366844116101b8578063223668441461028057806329a00e7c1461029c578063371d52dc146102d15780633e21374e14610310576101da565b8063086cfca8146101df5780630b184866146102075780631da6bbfb1461024b575b600080fd5b610205600480360360208110156101f557600080fd5b50356001600160a01b03166106e5565b005b6102396004803603606081101561021d57600080fd5b506001600160a01b0381351690602081013590604001356107a0565b60408051918252519081900360200190f35b6102396004803603608081101561026157600080fd5b5080359060208101359063ffffffff6040820135169060600135610964565b610288610a43565b604080519115158252519081900360200190f35b610239600480360360808110156102b257600080fd5b5080359060208101359063ffffffff6040820135169060600135610a53565b6102f7600480360360208110156102e757600080fd5b50356001600160a01b0316610b24565b6040805163ffffffff9092168252519081900360200190f35b6102396004803603602081101561032657600080fd5b50356001600160a01b0316610c1f565b6102f76004803603602081101561034c57600080fd5b50356001600160a01b0316610eed565b6102396004803603608081101561037257600080fd5b5080359060208101359063ffffffff6040820135169060600135610fbe565b610205600480360360808110156103a757600080fd5b5080356001600160a01b0316906020810135906040810135906060013563ffffffff16611098565b6103d7611108565b6040805161ffff9092168252519081900360200190f35b6102396004803603604081101561040457600080fd5b506001600160a01b038135169060200135611112565b610239600480360360a081101561043057600080fd5b5080359063ffffffff602082013581169160408101359160608201351690608001356111ce565b6102396004803603604081101561046d57600080fd5b506001600160a01b0381351690602001356111e9565b6102396004803603604081101561049957600080fd5b506001600160a01b0381351690602001356112a5565b610239611414565b61020561141a565b610239600480360360408110156104d557600080fd5b506001600160a01b038135169060200135611475565b610239600480360360a081101561050157600080fd5b5080359063ffffffff60208201358116916040810135916060820135169060800135611546565b61054e6004803603602081101561053e57600080fd5b50356001600160a01b031661164e565b6040805193845263ffffffff909216602084015282820152519081900360600190f35b610579611675565b604080516001600160a01b039092168252519081900360200190f35b610288611684565b610205600480360360408110156105b357600080fd5b5080359060200135611695565b610239600480360360808110156105d657600080fd5b5080359060208101359063ffffffff6040820135169060600135611794565b6102396004803603604081101561060b57600080fd5b506001600160a01b03813516906020013561181f565b6102886004803603602081101561063757600080fd5b50356001600160a01b0316611960565b6102396004803603604081101561065d57600080fd5b506001600160a01b038135169060200135611a4d565b6102396004803603602081101561068957600080fd5b50356001600160a01b0316611b7b565b610239600480360360208110156106af57600080fd5b50356001600160a01b0316611c3d565b610205600480360360208110156106d557600080fd5b50356001600160a01b0316611dd0565b6106ed611684565b6106f657600080fd5b608280546001600160a01b0319166001600160a01b03838116919091179182905560408051638da5cb5b60e01b815290519290911691638da5cb5b91600480820192602092909190829003018186803b15801561075257600080fd5b505afa158015610766573d6000803e3d6000fd5b505050506040513d602081101561077c57600080fd5b5051608380546001600160a01b0319166001600160a01b0390921691909117905550565b60006107aa611684565b6107b357600080fd5b6001600160a01b03841660009081526085602052604090206002810154859190610812576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b838510156108515760405162461bcd60e51b815260040180806020018281038252602f815260200180612deb602f913960400191505060405180910390fd5b6001600160a01b0386166000908152608560205260409020600281015486106108ab5760405162461bcd60e51b8152600401808060200182810382526029815260200180612da26029913960400191505060405180910390fd5b60006108bd878763ffffffff611ded16565b905060006108cb89836111e9565b60028401549091506108e3908963ffffffff611ded16565b600284015582546108fa908263ffffffff611ded16565b8084556002840154604080518a81526020810185905280820192909252606082019290925290516001600160a01b038b169133917fed639966d5b0a89f5ac16d6359c7707785de6e51a00f07dd3197e5fbf0a303749181900360800190a398975050505050505050565b600080851180156109755750600084115b8015610987575060018363ffffffff16115b801561099c5750621e848063ffffffff841611155b6109a557600080fd5b816109b257506000610a3b565b63ffffffff8316620f424014156109e9578460016109d6848763ffffffff611e0216565b03816109de57fe5b046001019050610a3b565b600080806109fd888663ffffffff611e3016565b9050610a0e8189620f424089611e42565b9093509150600060ff83166001610a2b8a8763ffffffff611e0216565b03901c8890036001019450505050505b949350505050565b6000610a4e30611960565b905090565b60008085118015610a645750600084115b8015610a76575060008363ffffffff16115b8015610a8b5750620f424063ffffffff841611155b610a9457600080fd5b81610aa157506000610a3b565b63ffffffff8316620f42401415610ad25783610ac3868463ffffffff611e0216565b81610aca57fe5b049050610a3b565b60008080610ae6858863ffffffff611e3016565b9050610af7818888620f4240611e42565b9093509150600060ff8316610b128a8663ffffffff611e0216565b901c9890980398975050505050505050565b6001600160a01b03811660009081526085602052604081206002810154839190610b83576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b610b8b612d7a565b506001600160a01b038416600090815260856020908152604091829020825160608101845281548152600182015463ffffffff169281018390526002909101549281019290925280610bdd5750620f42405b610c15683635c9adc5dea00000610c09610c0163ffffffff808616908490611e0216565b608654611f14565b9063ffffffff611f5516565b9695505050505050565b6001600160a01b03811660009081526085602052604081206002810154839190610c7e576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b610c86612d7a565b506001600160a01b0384166000908152608560209081526040808320815160608101835281548152600182015463ffffffff1693810193909352600201549082015290610cd286610b24565b90506000610d4f876001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610d1257600080fd5b505afa158015610d26573d6000803e3d6000fd5b505050506040513d6020811015610d3c57600080fd5b5051601b9060ff1663ffffffff611ded16565b90506000610d94610d7363ffffffff80861690683635c9adc5dea0000090611e0216565b610d8f84600a0a610d838c611c3d565b9063ffffffff611e0216565b611f14565b90506000608260009054906101000a90046001600160a01b03166001600160a01b031663e1758bd86040518163ffffffff1660e01b815260040160206040518083038186803b158015610de657600080fd5b505afa158015610dfa573d6000803e3d6000fd5b505050506040513d6020811015610e1057600080fd5b50516040805163313ce56760e01b81529051919250600091610e97916001600160a01b0385169163313ce56791600480820192602092909190829003018186803b158015610e5d57600080fd5b505afa158015610e71573d6000803e3d6000fd5b505050506040513d6020811015610e8757600080fd5b5051601b9063ffffffff611ded16565b90506000610ec582600a0a610c09610ebf88600a0a8b60000151611e0290919063ffffffff16565b87611f77565b9050610ede876040015182611ded90919063ffffffff16565b9b9a5050505050505050505050565b6000610ef7611684565b610f0057600080fd5b6001600160a01b03821660009081526085602052604090206002810154839190610f5f576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b6001600160a01b0384166000908152608560205260409020600181015463ffffffff1680610f8d5750620f42405b610f9686610b24565b600192909201805463ffffffff191663ffffffff938416179081905590911695945050505050565b60008085118015610fcf5750600084115b8015610fe1575060008363ffffffff16115b8015610ff65750620f424063ffffffff841611155b80156110025750848211155b61100b57600080fd5b8161101857506000610a3b565b84821415611027575082610a3b565b63ffffffff8316620f424014156110495784610ac3858463ffffffff611e0216565b60008083870361105e8882620f424089611e42565b90935091506000611075888563ffffffff611e0216565b905060ff831688901b848183038161108957fe5b049a9950505050505050505050565b6110a0611684565b6110a957600080fd5b6040805160608101825292835263ffffffff91821660208085019182528483019586526001600160a01b039690961660009081526085909652942091518255925160018201805463ffffffff1916919094161790925551600290910155565b60005461ffff1681565b6001600160a01b03821660009081526085602052604081206002810154849190611171576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b611179612d7a565b506001600160a01b03851660009081526085602090815260409182902082516060810184528154808252600183015463ffffffff1693820184905260029092015493810184905292610c159290919088610a53565b60006111dd8686868686611546565b90505b95945050505050565b6001600160a01b03821660009081526085602052604081206002810154849190611248576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b611250612d7a565b506001600160a01b03851660009081526085602090815260409182902082516060810184528154808252600183015463ffffffff1693820184905260029092015493810184905292610c159290919088610fbe565b60006112af611684565b6112b857600080fd5b6001600160a01b03831660009081526085602052604090206002810154849190611317576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b6001600160a01b0385166000908152608560205260409020600281015485106113715760405162461bcd60e51b8152600401808060200182810382526029815260200180612da26029913960400191505060405180910390fd5b600061137d87876111e9565b6002830154909150611395908763ffffffff611ded16565b600283015581546113ac908263ffffffff611ded16565b8083556002830154604080518981526020810185905280820192909252606082019290925290516001600160a01b0389169133917fed639966d5b0a89f5ac16d6359c7707785de6e51a00f07dd3197e5fbf0a303749181900360800190a39695505050505050565b60865481565b611422611684565b61142b57600080fd5b6081546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3608180546001600160a01b0319169055565b600061147f611684565b61148857600080fd5b8161149557506000611540565b60006114a1848461181f565b6001600160a01b03851660009081526085602052604090206002810154815492935090916114d5828563ffffffff611e3016565b60028401556114ea818763ffffffff611e3016565b8355604080518781526020810184905280820186905290516001600160a01b0389169133917fbecd073f6198ce1d3038bf9a242d869e1f276e2370746f104c735fa8d4fa313c9181900360600190a35091925050505b92915050565b6000808611801561155d575060008563ffffffff16115b80156115725750620f424063ffffffff861611155b801561157e5750600084115b8015611590575060008363ffffffff16115b80156115a55750620f424063ffffffff841611155b6115ae57600080fd5b8263ffffffff168563ffffffff1614156115f1576115d2868363ffffffff611e3016565b6115e2858463ffffffff611e0216565b816115e957fe5b0490506111e0565b60008080611605898663ffffffff611e3016565b9050611613818a8a89611e42565b9093509150600061162a888563ffffffff611e0216565b905060ff831688901b848183038161163e57fe5b049b9a5050505050505050505050565b608560205260009081526040902080546001820154600290920154909163ffffffff169083565b6081546001600160a01b031690565b6081546001600160a01b0316331490565b6082546001600160a01b031633146116f4576040805162461bcd60e51b815260206004820181905260248201527f6f6e6c79204176617461722063616e2063616c6c2074686973206d6574686f64604482015290519081900360640190fd5b60008111611749576040805162461bcd60e51b815260206004820152601b60248201527f64656e6f6d696e61746f72206d7573742062652061626f766520300000000000604482015290519081900360640190fd5b6117538282611f77565b6086556040805183815260208101839052815133927fcd3db955892df8543ef392cb55c3f36e13ad4c38e151c8315101b3006ef105df928290030190a25050565b600080851180156117a55750600084115b80156117b7575060018363ffffffff16115b80156117cc5750621e848063ffffffff841611155b80156117d85750848211155b6117e157600080fd5b816117ee57506000610a3b565b848214156117fd575082610a3b565b63ffffffff8316620f424014156110495784610ac3838663ffffffff611e0216565b6001600160a01b0382166000908152608560205260408120600281015484919061187e576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b60825460408051631c2eb17b60e31b815290516000926001600160a01b03169163e1758bd8916004808301926020929190829003018186803b1580156118c357600080fd5b505afa1580156118d7573d6000803e3d6000fd5b505050506040513d60208110156118ed57600080fd5b50516040805163313ce56760e01b8152905191925060009161193a916001600160a01b0385169163313ce56791600480820192602092909190829003018186803b158015610e5d57600080fd5b905061195581600a0a610c09886119508b611c3d565b611f77565b979650505050505050565b6082546000906001600160a01b03166119b4576040805162461bcd60e51b8152602060048201526011602482015270105d985d185c881a5cc81b9bdd081cd95d607a1b604482015290519081900360640190fd5b60835460825460408051639be2faed60e01b81526001600160a01b038681166004830152928316602482015290519190921691639be2faed916044808301926020929190829003018186803b158015611a0c57600080fd5b505afa158015611a20573d6000803e3d6000fd5b505050506040513d6020811015611a3657600080fd5b5051611a4457506000611a48565b5060015b919050565b6000611a57611684565b611a6057600080fd5b6001600160a01b03831660009081526085602052604090206002810154849190611abf576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b6000611acb8686611112565b6001600160a01b0387166000908152608560205260409020600281015491925090611afc908363ffffffff611e3016565b60028201558054611b13908763ffffffff611e3016565b8082556002820154604080518981526020810186905280820192909252606082019290925290516001600160a01b0389169133917fed639966d5b0a89f5ac16d6359c7707785de6e51a00f07dd3197e5fbf0a303749181900360800190a35095945050505050565b6000611b85611684565b611b8e57600080fd5b6000611b9983610c1f565b6001600160a01b038416600090815260856020526040902060028101546001820154929350909163ffffffff90811690611bd79083908690611e3016565b6002840155611be586610eed565b50604080518281526020810184905280820186905290516001600160a01b0388169133917fdf7a14785c215a09814aa4ee13a4578dd9842e48d61a2dda15aadd4b98c8007d9181900360600190a35091949350505050565b6001600160a01b03811660009081526085602052604081206002810154839190611c9c576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b611ca4612d7a565b506001600160a01b038085166000908152608560209081526040808320815160608101835281548152600182015463ffffffff1681850152600290910154818301526082548251631c2eb17b60e31b815292519195169263e1758bd89260048082019391829003018186803b158015611d1c57600080fd5b505afa158015611d30573d6000803e3d6000fd5b505050506040513d6020811015611d4657600080fd5b50516040808401518451602086810151845163313ce56760e01b81529451959650610c15959394929390926001600160a01b0388169263313ce56792600480840193829003018186803b158015611d9c57600080fd5b505afa158015611db0573d6000803e3d6000fd5b505050506040513d6020811015611dc657600080fd5b5051600a0a610fbe565b611dd8611684565b611de157600080fd5b611dea81611f9b565b50565b600082821115611dfc57600080fd5b50900390565b600082611e1157506000611540565b82820282848281611e1e57fe5b0414611e2957600080fd5b9392505050565b600082820183811015611e2957600080fd5b600080600160811b8610611e5557600080fd5b600080866001607f1b890281611e6757fe5b04905070015bf0a8b1457695355fb8ac404e7a79e3811015611e9357611e8c8161200a565b9150611e9f565b611e9c816123ec565b91505b60008563ffffffff168763ffffffff16840281611eb857fe5b049050600160831b811015611ede57611ed081612496565b607f94509450505050611f0b565b6000611ee98261283a565b9050611efe81607f0360ff1683901c826128ca565b95509350611f0b92505050565b94509492505050565b60006b033b2e3c9fd0803ce8000000611f46611f308585612c67565b60026b033b2e3c9fd0803ce80000005b04612cca565b81611f4d57fe5b049392505050565b6000808211611f6357600080fd5b6000828481611f6e57fe5b04949350505050565b600081611f46611f93856b033b2e3c9fd0803ce8000000612c67565b600285611f40565b6001600160a01b038116611fae57600080fd5b6081546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3608180546001600160a01b0319166001600160a01b0392909216919091179055565b6000808080806fd3094c70f034de4b96ff7d5b6f99fcd88610612053576001607e1b840193506fd3094c70f034de4b96ff7d5b6f99fcd86001607f1b87028161204f57fe5b0495505b6fa45af1e1f40c333b3de1db4dd55f29a78610612096576001607d1b840193506fa45af1e1f40c333b3de1db4dd55f29a76001607f1b87028161209257fe5b0495505b6f910b022db7ae67ce76b441c27035c6a186106120d9576001607c1b840193506f910b022db7ae67ce76b441c27035c6a16001607f1b8702816120d557fe5b0495505b6f88415abbe9a76bead8d00cf112e4d4a8861061211c576001607b1b840193506f88415abbe9a76bead8d00cf112e4d4a86001607f1b87028161211857fe5b0495505b6f84102b00893f64c705e841d5d4064bd3861061215f576001607a1b840193506f84102b00893f64c705e841d5d4064bd36001607f1b87028161215b57fe5b0495505b6f8204055aaef1c8bd5c3259f4822735a286106121a257600160791b840193506f8204055aaef1c8bd5c3259f4822735a26001607f1b87028161219e57fe5b0495505b6f810100ab00222d861931c15e39b44e9986106121e557600160781b840193506f810100ab00222d861931c15e39b44e996001607f1b8702816121e157fe5b0495505b6f808040155aabbbe9451521693554f733861061222857600160771b840193506f808040155aabbbe9451521693554f7336001607f1b87028161222457fe5b0495505b6f7fffffffffffffffffffffffffffffff19860192508291506001607f1b828002049050600160801b838103830204840193506001607f1b8183028161226a57fe5b049150600160811b836faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0383028161228e57fe5b04840193506001607f1b818302816122a257fe5b049150600360801b836f99999999999999999999999999999999038302816122c657fe5b04840193506001607f1b818302816122da57fe5b049150600160821b836f92492492492492492492492492492492038302816122fe57fe5b04840193506001607f1b8183028161231257fe5b049150600560801b836f8e38e38e38e38e38e38e38e38e38e38e0383028161233657fe5b04840193506001607f1b8183028161234a57fe5b049150600360811b836f8ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b0383028161236e57fe5b04840193506001607f1b8183028161238257fe5b049150600760801b836f89d89d89d89d89d89d89d89d89d89d89038302816123a657fe5b04840193506001607f1b818302816123ba57fe5b049150600160831b836f88888888888888888888888888888888038302816123de57fe5b049390930195945050505050565b600080600160801b831061241c57600061240b6001607f1b8504612d19565b60ff1693841c936001607f1b029150505b6001607f1b83111561246a57607f5b60ff811615612468576001607f1b848002049350600160801b841061245f57600193841c9360ff6000198301161b91909101905b6000190161242b565b505b6f05b9de1d10bf4103d647b0955897ba806f03f80fe03f80fe03f80fe03f80fe03f88202049392505050565b6000670168244fdac780006001607f1b6f0fffffffffffffffffffffffffffffff84168080028290048082028390048083028490049485026710e1b3be415a00009092026705a0913f6b1e000091909102010192909181830204905080664807432bc1800002830192506001607f1b8282028161250f57fe5b04905080660c0135dca0400002830192506001607f1b8282028161252f57fe5b049050806601b707b1cdc00002830192506001607f1b8282028161254f57fe5b049050806536e0f639b80002830192506001607f1b8282028161256e57fe5b04905080650618fee9f80002830192506001607f1b8282028161258d57fe5b04905080649c197dcc0002830192506001607f1b828202816125ab57fe5b04905080640e30dce40002830192506001607f1b828202816125c957fe5b0490508064012ebd130002830192506001607f1b828202816125e757fe5b049050806317499f0002830192506001607f1b8282028161260457fe5b049050806301a9d48002830192506001607f1b8282028161262157fe5b04905080621c638002830192506001607f1b8282028161263d57fe5b049050806201c63802830192506001607f1b8282028161265957fe5b04905080611ab802830192506001607f1b8282028161267457fe5b0490508061017c02830192506001607f1b8282028161268f57fe5b04905080601402830192506001607f1b828202816126a957fe5b6721c3677c82b400009190049384010482016001607f1b019290506001607c1b8516156126fa5770018ebef9eac820ae8682b9793ac6d1e7767001c3d6a24ed82218787d624d3e5eba95f984020492505b6001607d1b851615612730577001368b2fc6f9609fe7aceb46aa619baed470018ebef9eac820ae8682b9793ac6d1e77884020492505b6001607e1b851615612765576fbc5ab1b16779be3575bd8f0520a9f21f7001368b2fc6f9609fe7aceb46aa619baed584020492505b6001607f1b851615612799576f454aaa8efe072e7f6ddbab84b40a55c96fbc5ab1b16779be3575bd8f0520a9f21e84020492505b600160801b8516156127cd576f0960aadc109e7a3bf4578099615711ea6f454aaa8efe072e7f6ddbab84b40a55c584020492505b600160811b851615612800576e2bf84208204f5977f9a8cf01fdce3d6f0960aadc109e7a3bf4578099615711d784020492505b600160821b851615612831576d03c6ab775dd0b95b4cbee7e65d116e2bf84208204f5977f9a8cf01fdc30784020492505b50909392505050565b60006020607f5b8060ff168260010160ff161015612889576000600260ff848401160490508460018260ff166080811061287057fe5b01541061287f57809250612883565b8091505b50612841565b8360018260ff166080811061289a57fe5b0154106128aa579150611a489050565b8360018360ff16608081106128bb57fe5b0154106101da57509050611a48565b60008083905060008090508360ff16858302901c9150816f03442c4e6074a82f1797f72ac000000002810190508360ff16858302901c9150816f0116b96f757c380fb287fd0e4000000002810190508360ff16858302901c9150816e45ae5bdd5f0e03eca1ff439000000002810190508360ff16858302901c9150816e0defabf91302cd95b9ffda5000000002810190508360ff16858302901c9150816e02529ca9832b22439efff9b800000002810190508360ff16858302901c9150816d54f1cf12bd04e516b6da8800000002810190508360ff16858302901c9150816d0a9e39e257a09ca2d6db5100000002810190508360ff16858302901c9150816d012e066e7b839fa050c30900000002810190508360ff16858302901c9150816c1e33d7d926c329a1ad1a80000002810190508360ff16858302901c9150816c02bee513bdb4a6b19b5f80000002810190508360ff16858302901c9150816b3a9316fa79b88eccf2a0000002810190508360ff16858302901c9150816b048177ebe1fa81237520000002810190508360ff16858302901c9150816a5263fe90242dcbacf0000002810190508360ff16858302901c9150816a057e22099c030d9410000002810190508360ff16858302901c9150816957e22099c030d941000002810190508360ff16858302901c91508169052b6b5456997631000002810190508360ff16858302901c915081684985f67696bf74800002810190508360ff16858302901c9150816803dea12ea99e49800002810190508360ff16858302901c9150816731880f2214b6e00002810190508360ff16858302901c91508167025bcff56eb3600002810190508360ff16858302901c915081661b722e10ab100002810190508360ff16858302901c9150816601317c7007700002810190508360ff16858302901c915081650cba84aafa0002810190508360ff16858302901c9150816482573a0a0002810190508360ff16858302901c9150816405035ad90002810190508360ff16858302901c915081632f881b0002810190508360ff16858302901c9150816301b2934002810190508360ff16858302901c915081620efc4002810190508360ff16858302901c915081617fe002810190508360ff16858302901c91508161042002810190508360ff16858302901c915081602102810190508360ff16858302901c915081600102810190508360ff166001901b856f0688589cc0e9505e2f2fee55800000008381612c5b57fe5b04010195945050505050565b6000811580612c8257505080820282828281612c7f57fe5b04145b611540576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820182811015611540576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fd5b600080610100831015612d41575b6001831115612d3c57600192831c9201612d27565b611540565b60805b60ff811615612d7357600160ff82161b8410612d685760ff81169390931c92908117905b60011c607f16612d44565b5092915050565b604051806060016040528060008152602001600063ffffffff16815260200160008152509056fe474420616d6f756e7420697320686967686572207468616e2074686520746f74616c20737570706c795265736572766520746f6b656e206e6f7420696e697469616c697a6564000000474420616d6f756e74206973206c6f776572207468616e2074686520636f6e747269627574696f6e20616d6f756e74a265627a7a723158200bbc2cedbd60c0bcfe652548270f3aa8d63bec7b1bc5e3fde6e73eac1f9bea8e64736f6c634300051000320000000000000000000000001ecfd1afb601c406ff0e13c3485f2d75699b681700000000000000000000000000000000000000000000000000038cf0587b397800000000000000000000000000000000000000000000000000038d7ea4c68000

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101da5760003560e01c80636cb4b4c1116101045780639f2d0d07116100a2578063cce7ec1311610071578063cce7ec1314610647578063e72a083314610673578063e9833c2f14610699578063f2fde38b146106bf576101da565b80639f2d0d071461059d578063abfd231d146105c0578063bc179d45146105f5578063c3c5a54714610621576101da565b806379c1b450116100de57806379c1b450146104eb578063835bbd55146105285780638da5cb5b146105715780638f32d59b14610595576101da565b80636cb4b4c1146104af578063715018a6146104b757806374920d30146104bf576101da565b806346f7cb231161017c5780635cf3a7a91161014b5780635cf3a7a9146103ee57806365098bb31461041a5780636a989e6e146104575780636c197ff514610483576101da565b806346f7cb231461033657806349f9b0f71461035c578063545bf97e1461039157806354fd4d50146103cf576101da565b806322366844116101b8578063223668441461028057806329a00e7c1461029c578063371d52dc146102d15780633e21374e14610310576101da565b8063086cfca8146101df5780630b184866146102075780631da6bbfb1461024b575b600080fd5b610205600480360360208110156101f557600080fd5b50356001600160a01b03166106e5565b005b6102396004803603606081101561021d57600080fd5b506001600160a01b0381351690602081013590604001356107a0565b60408051918252519081900360200190f35b6102396004803603608081101561026157600080fd5b5080359060208101359063ffffffff6040820135169060600135610964565b610288610a43565b604080519115158252519081900360200190f35b610239600480360360808110156102b257600080fd5b5080359060208101359063ffffffff6040820135169060600135610a53565b6102f7600480360360208110156102e757600080fd5b50356001600160a01b0316610b24565b6040805163ffffffff9092168252519081900360200190f35b6102396004803603602081101561032657600080fd5b50356001600160a01b0316610c1f565b6102f76004803603602081101561034c57600080fd5b50356001600160a01b0316610eed565b6102396004803603608081101561037257600080fd5b5080359060208101359063ffffffff6040820135169060600135610fbe565b610205600480360360808110156103a757600080fd5b5080356001600160a01b0316906020810135906040810135906060013563ffffffff16611098565b6103d7611108565b6040805161ffff9092168252519081900360200190f35b6102396004803603604081101561040457600080fd5b506001600160a01b038135169060200135611112565b610239600480360360a081101561043057600080fd5b5080359063ffffffff602082013581169160408101359160608201351690608001356111ce565b6102396004803603604081101561046d57600080fd5b506001600160a01b0381351690602001356111e9565b6102396004803603604081101561049957600080fd5b506001600160a01b0381351690602001356112a5565b610239611414565b61020561141a565b610239600480360360408110156104d557600080fd5b506001600160a01b038135169060200135611475565b610239600480360360a081101561050157600080fd5b5080359063ffffffff60208201358116916040810135916060820135169060800135611546565b61054e6004803603602081101561053e57600080fd5b50356001600160a01b031661164e565b6040805193845263ffffffff909216602084015282820152519081900360600190f35b610579611675565b604080516001600160a01b039092168252519081900360200190f35b610288611684565b610205600480360360408110156105b357600080fd5b5080359060200135611695565b610239600480360360808110156105d657600080fd5b5080359060208101359063ffffffff6040820135169060600135611794565b6102396004803603604081101561060b57600080fd5b506001600160a01b03813516906020013561181f565b6102886004803603602081101561063757600080fd5b50356001600160a01b0316611960565b6102396004803603604081101561065d57600080fd5b506001600160a01b038135169060200135611a4d565b6102396004803603602081101561068957600080fd5b50356001600160a01b0316611b7b565b610239600480360360208110156106af57600080fd5b50356001600160a01b0316611c3d565b610205600480360360208110156106d557600080fd5b50356001600160a01b0316611dd0565b6106ed611684565b6106f657600080fd5b608280546001600160a01b0319166001600160a01b03838116919091179182905560408051638da5cb5b60e01b815290519290911691638da5cb5b91600480820192602092909190829003018186803b15801561075257600080fd5b505afa158015610766573d6000803e3d6000fd5b505050506040513d602081101561077c57600080fd5b5051608380546001600160a01b0319166001600160a01b0390921691909117905550565b60006107aa611684565b6107b357600080fd5b6001600160a01b03841660009081526085602052604090206002810154859190610812576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b838510156108515760405162461bcd60e51b815260040180806020018281038252602f815260200180612deb602f913960400191505060405180910390fd5b6001600160a01b0386166000908152608560205260409020600281015486106108ab5760405162461bcd60e51b8152600401808060200182810382526029815260200180612da26029913960400191505060405180910390fd5b60006108bd878763ffffffff611ded16565b905060006108cb89836111e9565b60028401549091506108e3908963ffffffff611ded16565b600284015582546108fa908263ffffffff611ded16565b8084556002840154604080518a81526020810185905280820192909252606082019290925290516001600160a01b038b169133917fed639966d5b0a89f5ac16d6359c7707785de6e51a00f07dd3197e5fbf0a303749181900360800190a398975050505050505050565b600080851180156109755750600084115b8015610987575060018363ffffffff16115b801561099c5750621e848063ffffffff841611155b6109a557600080fd5b816109b257506000610a3b565b63ffffffff8316620f424014156109e9578460016109d6848763ffffffff611e0216565b03816109de57fe5b046001019050610a3b565b600080806109fd888663ffffffff611e3016565b9050610a0e8189620f424089611e42565b9093509150600060ff83166001610a2b8a8763ffffffff611e0216565b03901c8890036001019450505050505b949350505050565b6000610a4e30611960565b905090565b60008085118015610a645750600084115b8015610a76575060008363ffffffff16115b8015610a8b5750620f424063ffffffff841611155b610a9457600080fd5b81610aa157506000610a3b565b63ffffffff8316620f42401415610ad25783610ac3868463ffffffff611e0216565b81610aca57fe5b049050610a3b565b60008080610ae6858863ffffffff611e3016565b9050610af7818888620f4240611e42565b9093509150600060ff8316610b128a8663ffffffff611e0216565b901c9890980398975050505050505050565b6001600160a01b03811660009081526085602052604081206002810154839190610b83576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b610b8b612d7a565b506001600160a01b038416600090815260856020908152604091829020825160608101845281548152600182015463ffffffff169281018390526002909101549281019290925280610bdd5750620f42405b610c15683635c9adc5dea00000610c09610c0163ffffffff808616908490611e0216565b608654611f14565b9063ffffffff611f5516565b9695505050505050565b6001600160a01b03811660009081526085602052604081206002810154839190610c7e576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b610c86612d7a565b506001600160a01b0384166000908152608560209081526040808320815160608101835281548152600182015463ffffffff1693810193909352600201549082015290610cd286610b24565b90506000610d4f876001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610d1257600080fd5b505afa158015610d26573d6000803e3d6000fd5b505050506040513d6020811015610d3c57600080fd5b5051601b9060ff1663ffffffff611ded16565b90506000610d94610d7363ffffffff80861690683635c9adc5dea0000090611e0216565b610d8f84600a0a610d838c611c3d565b9063ffffffff611e0216565b611f14565b90506000608260009054906101000a90046001600160a01b03166001600160a01b031663e1758bd86040518163ffffffff1660e01b815260040160206040518083038186803b158015610de657600080fd5b505afa158015610dfa573d6000803e3d6000fd5b505050506040513d6020811015610e1057600080fd5b50516040805163313ce56760e01b81529051919250600091610e97916001600160a01b0385169163313ce56791600480820192602092909190829003018186803b158015610e5d57600080fd5b505afa158015610e71573d6000803e3d6000fd5b505050506040513d6020811015610e8757600080fd5b5051601b9063ffffffff611ded16565b90506000610ec582600a0a610c09610ebf88600a0a8b60000151611e0290919063ffffffff16565b87611f77565b9050610ede876040015182611ded90919063ffffffff16565b9b9a5050505050505050505050565b6000610ef7611684565b610f0057600080fd5b6001600160a01b03821660009081526085602052604090206002810154839190610f5f576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b6001600160a01b0384166000908152608560205260409020600181015463ffffffff1680610f8d5750620f42405b610f9686610b24565b600192909201805463ffffffff191663ffffffff938416179081905590911695945050505050565b60008085118015610fcf5750600084115b8015610fe1575060008363ffffffff16115b8015610ff65750620f424063ffffffff841611155b80156110025750848211155b61100b57600080fd5b8161101857506000610a3b565b84821415611027575082610a3b565b63ffffffff8316620f424014156110495784610ac3858463ffffffff611e0216565b60008083870361105e8882620f424089611e42565b90935091506000611075888563ffffffff611e0216565b905060ff831688901b848183038161108957fe5b049a9950505050505050505050565b6110a0611684565b6110a957600080fd5b6040805160608101825292835263ffffffff91821660208085019182528483019586526001600160a01b039690961660009081526085909652942091518255925160018201805463ffffffff1916919094161790925551600290910155565b60005461ffff1681565b6001600160a01b03821660009081526085602052604081206002810154849190611171576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b611179612d7a565b506001600160a01b03851660009081526085602090815260409182902082516060810184528154808252600183015463ffffffff1693820184905260029092015493810184905292610c159290919088610a53565b60006111dd8686868686611546565b90505b95945050505050565b6001600160a01b03821660009081526085602052604081206002810154849190611248576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b611250612d7a565b506001600160a01b03851660009081526085602090815260409182902082516060810184528154808252600183015463ffffffff1693820184905260029092015493810184905292610c159290919088610fbe565b60006112af611684565b6112b857600080fd5b6001600160a01b03831660009081526085602052604090206002810154849190611317576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b6001600160a01b0385166000908152608560205260409020600281015485106113715760405162461bcd60e51b8152600401808060200182810382526029815260200180612da26029913960400191505060405180910390fd5b600061137d87876111e9565b6002830154909150611395908763ffffffff611ded16565b600283015581546113ac908263ffffffff611ded16565b8083556002830154604080518981526020810185905280820192909252606082019290925290516001600160a01b0389169133917fed639966d5b0a89f5ac16d6359c7707785de6e51a00f07dd3197e5fbf0a303749181900360800190a39695505050505050565b60865481565b611422611684565b61142b57600080fd5b6081546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3608180546001600160a01b0319169055565b600061147f611684565b61148857600080fd5b8161149557506000611540565b60006114a1848461181f565b6001600160a01b03851660009081526085602052604090206002810154815492935090916114d5828563ffffffff611e3016565b60028401556114ea818763ffffffff611e3016565b8355604080518781526020810184905280820186905290516001600160a01b0389169133917fbecd073f6198ce1d3038bf9a242d869e1f276e2370746f104c735fa8d4fa313c9181900360600190a35091925050505b92915050565b6000808611801561155d575060008563ffffffff16115b80156115725750620f424063ffffffff861611155b801561157e5750600084115b8015611590575060008363ffffffff16115b80156115a55750620f424063ffffffff841611155b6115ae57600080fd5b8263ffffffff168563ffffffff1614156115f1576115d2868363ffffffff611e3016565b6115e2858463ffffffff611e0216565b816115e957fe5b0490506111e0565b60008080611605898663ffffffff611e3016565b9050611613818a8a89611e42565b9093509150600061162a888563ffffffff611e0216565b905060ff831688901b848183038161163e57fe5b049b9a5050505050505050505050565b608560205260009081526040902080546001820154600290920154909163ffffffff169083565b6081546001600160a01b031690565b6081546001600160a01b0316331490565b6082546001600160a01b031633146116f4576040805162461bcd60e51b815260206004820181905260248201527f6f6e6c79204176617461722063616e2063616c6c2074686973206d6574686f64604482015290519081900360640190fd5b60008111611749576040805162461bcd60e51b815260206004820152601b60248201527f64656e6f6d696e61746f72206d7573742062652061626f766520300000000000604482015290519081900360640190fd5b6117538282611f77565b6086556040805183815260208101839052815133927fcd3db955892df8543ef392cb55c3f36e13ad4c38e151c8315101b3006ef105df928290030190a25050565b600080851180156117a55750600084115b80156117b7575060018363ffffffff16115b80156117cc5750621e848063ffffffff841611155b80156117d85750848211155b6117e157600080fd5b816117ee57506000610a3b565b848214156117fd575082610a3b565b63ffffffff8316620f424014156110495784610ac3838663ffffffff611e0216565b6001600160a01b0382166000908152608560205260408120600281015484919061187e576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b60825460408051631c2eb17b60e31b815290516000926001600160a01b03169163e1758bd8916004808301926020929190829003018186803b1580156118c357600080fd5b505afa1580156118d7573d6000803e3d6000fd5b505050506040513d60208110156118ed57600080fd5b50516040805163313ce56760e01b8152905191925060009161193a916001600160a01b0385169163313ce56791600480820192602092909190829003018186803b158015610e5d57600080fd5b905061195581600a0a610c09886119508b611c3d565b611f77565b979650505050505050565b6082546000906001600160a01b03166119b4576040805162461bcd60e51b8152602060048201526011602482015270105d985d185c881a5cc81b9bdd081cd95d607a1b604482015290519081900360640190fd5b60835460825460408051639be2faed60e01b81526001600160a01b038681166004830152928316602482015290519190921691639be2faed916044808301926020929190829003018186803b158015611a0c57600080fd5b505afa158015611a20573d6000803e3d6000fd5b505050506040513d6020811015611a3657600080fd5b5051611a4457506000611a48565b5060015b919050565b6000611a57611684565b611a6057600080fd5b6001600160a01b03831660009081526085602052604090206002810154849190611abf576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b6000611acb8686611112565b6001600160a01b0387166000908152608560205260409020600281015491925090611afc908363ffffffff611e3016565b60028201558054611b13908763ffffffff611e3016565b8082556002820154604080518981526020810186905280820192909252606082019290925290516001600160a01b0389169133917fed639966d5b0a89f5ac16d6359c7707785de6e51a00f07dd3197e5fbf0a303749181900360800190a35095945050505050565b6000611b85611684565b611b8e57600080fd5b6000611b9983610c1f565b6001600160a01b038416600090815260856020526040902060028101546001820154929350909163ffffffff90811690611bd79083908690611e3016565b6002840155611be586610eed565b50604080518281526020810184905280820186905290516001600160a01b0388169133917fdf7a14785c215a09814aa4ee13a4578dd9842e48d61a2dda15aadd4b98c8007d9181900360600190a35091949350505050565b6001600160a01b03811660009081526085602052604081206002810154839190611c9c576040805162461bcd60e51b815260206004820152601d6024820152600080516020612dcb833981519152604482015290519081900360640190fd5b611ca4612d7a565b506001600160a01b038085166000908152608560209081526040808320815160608101835281548152600182015463ffffffff1681850152600290910154818301526082548251631c2eb17b60e31b815292519195169263e1758bd89260048082019391829003018186803b158015611d1c57600080fd5b505afa158015611d30573d6000803e3d6000fd5b505050506040513d6020811015611d4657600080fd5b50516040808401518451602086810151845163313ce56760e01b81529451959650610c15959394929390926001600160a01b0388169263313ce56792600480840193829003018186803b158015611d9c57600080fd5b505afa158015611db0573d6000803e3d6000fd5b505050506040513d6020811015611dc657600080fd5b5051600a0a610fbe565b611dd8611684565b611de157600080fd5b611dea81611f9b565b50565b600082821115611dfc57600080fd5b50900390565b600082611e1157506000611540565b82820282848281611e1e57fe5b0414611e2957600080fd5b9392505050565b600082820183811015611e2957600080fd5b600080600160811b8610611e5557600080fd5b600080866001607f1b890281611e6757fe5b04905070015bf0a8b1457695355fb8ac404e7a79e3811015611e9357611e8c8161200a565b9150611e9f565b611e9c816123ec565b91505b60008563ffffffff168763ffffffff16840281611eb857fe5b049050600160831b811015611ede57611ed081612496565b607f94509450505050611f0b565b6000611ee98261283a565b9050611efe81607f0360ff1683901c826128ca565b95509350611f0b92505050565b94509492505050565b60006b033b2e3c9fd0803ce8000000611f46611f308585612c67565b60026b033b2e3c9fd0803ce80000005b04612cca565b81611f4d57fe5b049392505050565b6000808211611f6357600080fd5b6000828481611f6e57fe5b04949350505050565b600081611f46611f93856b033b2e3c9fd0803ce8000000612c67565b600285611f40565b6001600160a01b038116611fae57600080fd5b6081546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3608180546001600160a01b0319166001600160a01b0392909216919091179055565b6000808080806fd3094c70f034de4b96ff7d5b6f99fcd88610612053576001607e1b840193506fd3094c70f034de4b96ff7d5b6f99fcd86001607f1b87028161204f57fe5b0495505b6fa45af1e1f40c333b3de1db4dd55f29a78610612096576001607d1b840193506fa45af1e1f40c333b3de1db4dd55f29a76001607f1b87028161209257fe5b0495505b6f910b022db7ae67ce76b441c27035c6a186106120d9576001607c1b840193506f910b022db7ae67ce76b441c27035c6a16001607f1b8702816120d557fe5b0495505b6f88415abbe9a76bead8d00cf112e4d4a8861061211c576001607b1b840193506f88415abbe9a76bead8d00cf112e4d4a86001607f1b87028161211857fe5b0495505b6f84102b00893f64c705e841d5d4064bd3861061215f576001607a1b840193506f84102b00893f64c705e841d5d4064bd36001607f1b87028161215b57fe5b0495505b6f8204055aaef1c8bd5c3259f4822735a286106121a257600160791b840193506f8204055aaef1c8bd5c3259f4822735a26001607f1b87028161219e57fe5b0495505b6f810100ab00222d861931c15e39b44e9986106121e557600160781b840193506f810100ab00222d861931c15e39b44e996001607f1b8702816121e157fe5b0495505b6f808040155aabbbe9451521693554f733861061222857600160771b840193506f808040155aabbbe9451521693554f7336001607f1b87028161222457fe5b0495505b6f7fffffffffffffffffffffffffffffff19860192508291506001607f1b828002049050600160801b838103830204840193506001607f1b8183028161226a57fe5b049150600160811b836faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0383028161228e57fe5b04840193506001607f1b818302816122a257fe5b049150600360801b836f99999999999999999999999999999999038302816122c657fe5b04840193506001607f1b818302816122da57fe5b049150600160821b836f92492492492492492492492492492492038302816122fe57fe5b04840193506001607f1b8183028161231257fe5b049150600560801b836f8e38e38e38e38e38e38e38e38e38e38e0383028161233657fe5b04840193506001607f1b8183028161234a57fe5b049150600360811b836f8ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b0383028161236e57fe5b04840193506001607f1b8183028161238257fe5b049150600760801b836f89d89d89d89d89d89d89d89d89d89d89038302816123a657fe5b04840193506001607f1b818302816123ba57fe5b049150600160831b836f88888888888888888888888888888888038302816123de57fe5b049390930195945050505050565b600080600160801b831061241c57600061240b6001607f1b8504612d19565b60ff1693841c936001607f1b029150505b6001607f1b83111561246a57607f5b60ff811615612468576001607f1b848002049350600160801b841061245f57600193841c9360ff6000198301161b91909101905b6000190161242b565b505b6f05b9de1d10bf4103d647b0955897ba806f03f80fe03f80fe03f80fe03f80fe03f88202049392505050565b6000670168244fdac780006001607f1b6f0fffffffffffffffffffffffffffffff84168080028290048082028390048083028490049485026710e1b3be415a00009092026705a0913f6b1e000091909102010192909181830204905080664807432bc1800002830192506001607f1b8282028161250f57fe5b04905080660c0135dca0400002830192506001607f1b8282028161252f57fe5b049050806601b707b1cdc00002830192506001607f1b8282028161254f57fe5b049050806536e0f639b80002830192506001607f1b8282028161256e57fe5b04905080650618fee9f80002830192506001607f1b8282028161258d57fe5b04905080649c197dcc0002830192506001607f1b828202816125ab57fe5b04905080640e30dce40002830192506001607f1b828202816125c957fe5b0490508064012ebd130002830192506001607f1b828202816125e757fe5b049050806317499f0002830192506001607f1b8282028161260457fe5b049050806301a9d48002830192506001607f1b8282028161262157fe5b04905080621c638002830192506001607f1b8282028161263d57fe5b049050806201c63802830192506001607f1b8282028161265957fe5b04905080611ab802830192506001607f1b8282028161267457fe5b0490508061017c02830192506001607f1b8282028161268f57fe5b04905080601402830192506001607f1b828202816126a957fe5b6721c3677c82b400009190049384010482016001607f1b019290506001607c1b8516156126fa5770018ebef9eac820ae8682b9793ac6d1e7767001c3d6a24ed82218787d624d3e5eba95f984020492505b6001607d1b851615612730577001368b2fc6f9609fe7aceb46aa619baed470018ebef9eac820ae8682b9793ac6d1e77884020492505b6001607e1b851615612765576fbc5ab1b16779be3575bd8f0520a9f21f7001368b2fc6f9609fe7aceb46aa619baed584020492505b6001607f1b851615612799576f454aaa8efe072e7f6ddbab84b40a55c96fbc5ab1b16779be3575bd8f0520a9f21e84020492505b600160801b8516156127cd576f0960aadc109e7a3bf4578099615711ea6f454aaa8efe072e7f6ddbab84b40a55c584020492505b600160811b851615612800576e2bf84208204f5977f9a8cf01fdce3d6f0960aadc109e7a3bf4578099615711d784020492505b600160821b851615612831576d03c6ab775dd0b95b4cbee7e65d116e2bf84208204f5977f9a8cf01fdc30784020492505b50909392505050565b60006020607f5b8060ff168260010160ff161015612889576000600260ff848401160490508460018260ff166080811061287057fe5b01541061287f57809250612883565b8091505b50612841565b8360018260ff166080811061289a57fe5b0154106128aa579150611a489050565b8360018360ff16608081106128bb57fe5b0154106101da57509050611a48565b60008083905060008090508360ff16858302901c9150816f03442c4e6074a82f1797f72ac000000002810190508360ff16858302901c9150816f0116b96f757c380fb287fd0e4000000002810190508360ff16858302901c9150816e45ae5bdd5f0e03eca1ff439000000002810190508360ff16858302901c9150816e0defabf91302cd95b9ffda5000000002810190508360ff16858302901c9150816e02529ca9832b22439efff9b800000002810190508360ff16858302901c9150816d54f1cf12bd04e516b6da8800000002810190508360ff16858302901c9150816d0a9e39e257a09ca2d6db5100000002810190508360ff16858302901c9150816d012e066e7b839fa050c30900000002810190508360ff16858302901c9150816c1e33d7d926c329a1ad1a80000002810190508360ff16858302901c9150816c02bee513bdb4a6b19b5f80000002810190508360ff16858302901c9150816b3a9316fa79b88eccf2a0000002810190508360ff16858302901c9150816b048177ebe1fa81237520000002810190508360ff16858302901c9150816a5263fe90242dcbacf0000002810190508360ff16858302901c9150816a057e22099c030d9410000002810190508360ff16858302901c9150816957e22099c030d941000002810190508360ff16858302901c91508169052b6b5456997631000002810190508360ff16858302901c915081684985f67696bf74800002810190508360ff16858302901c9150816803dea12ea99e49800002810190508360ff16858302901c9150816731880f2214b6e00002810190508360ff16858302901c91508167025bcff56eb3600002810190508360ff16858302901c915081661b722e10ab100002810190508360ff16858302901c9150816601317c7007700002810190508360ff16858302901c915081650cba84aafa0002810190508360ff16858302901c9150816482573a0a0002810190508360ff16858302901c9150816405035ad90002810190508360ff16858302901c915081632f881b0002810190508360ff16858302901c9150816301b2934002810190508360ff16858302901c915081620efc4002810190508360ff16858302901c915081617fe002810190508360ff16858302901c91508161042002810190508360ff16858302901c915081602102810190508360ff16858302901c915081600102810190508360ff166001901b856f0688589cc0e9505e2f2fee55800000008381612c5b57fe5b04010195945050505050565b6000811580612c8257505080820282828281612c7f57fe5b04145b611540576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820182811015611540576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fd5b600080610100831015612d41575b6001831115612d3c57600192831c9201612d27565b611540565b60805b60ff811615612d7357600160ff82161b8410612d685760ff81169390931c92908117905b60011c607f16612d44565b5092915050565b604051806060016040528060008152602001600063ffffffff16815260200160008152509056fe474420616d6f756e7420697320686967686572207468616e2074686520746f74616c20737570706c795265736572766520746f6b656e206e6f7420696e697469616c697a6564000000474420616d6f756e74206973206c6f776572207468616e2074686520636f6e747269627574696f6e20616d6f756e74a265627a7a723158200bbc2cedbd60c0bcfe652548270f3aa8d63bec7b1bc5e3fde6e73eac1f9bea8e64736f6c63430005100032

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000001ecfd1afb601c406ff0e13c3485f2d75699b681700000000000000000000000000000000000000000000000000038cf0587b397800000000000000000000000000000000000000000000000000038d7ea4c68000

-----Decoded View---------------
Arg [0] : _avatar (address): 0x1ecFD1afb601C406fF0e13c3485f2d75699b6817
Arg [1] : _nom (uint256): 999388834642296
Arg [2] : _denom (uint256): 1000000000000000

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000001ecfd1afb601c406ff0e13c3485f2d75699b6817
Arg [1] : 00000000000000000000000000000000000000000000000000038cf0587b3978
Arg [2] : 00000000000000000000000000000000000000000000000000038d7ea4c68000


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.