Address Details
contract

0xbe6285129462D970FC073a14E9CAfE57deB0841F

Contract Name
ConstantSumPricingModule
Creator
0x278160–50fc38 at 0x5fa889–a79e0c
Balance
0 CELO
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
Fetching transactions...
Transfers
Fetching transfers...
Gas Used
Fetching gas used...
Last Balance Update
14209863
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
ConstantSumPricingModule




Optimization enabled
true
Compiler version
v0.5.17+commit.d19bba13




Optimization runs
10000
EVM Version
istanbul




Verified at
2022-11-28T20:00:58.566843Z

contracts/ConstantSumPricingModule.sol

pragma solidity ^0.5.13;
pragma experimental ABIEncoderV2;

import { IPricingModule } from "./interfaces/IPricingModule.sol";

import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";
import { Ownable } from "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import { Initializable } from "./common/Initializable.sol";
import { FixidityLib } from "./common/FixidityLib.sol";

/**
 * @title ConstantSumPricingModule
 * @notice The ConstantSumPricingModule calculates the amount in and the amount out for a constant sum AMM.
 */
contract ConstantSumPricingModule is IPricingModule, Initializable, Ownable {
  using SafeMath for uint256;
  using FixidityLib for FixidityLib.Fraction;

  /* ==================== Constructor ==================== */

  /**
   * @notice Sets initialized == true on implementation contracts
   * @param test Set to true to skip implementation initialization
   */
  constructor(bool test) public Initializable(test) {}

  /**
   * @notice Allows the contract to be upgradable via the proxy.
   */
  function initilize() external initializer {
    _transferOwnership(msg.sender);
  }

  /* ==================== View Functions ==================== */
  /**
   * @notice Calculates the amount of tokens that should be received based on the given parameters
   * @dev amountOut = (1 - spread) * amountIn
   * @param tokenOutBucketSize The bucket size of the token swapt out.
   * @param spread The spread that is applied to a swap.
   * @param amountIn The amount of tokens in wei that is swapt in.
   * @return amountOut The amount of tokens in wei that should be received.
   */
  function getAmountOut(
    uint256,
    uint256 tokenOutBucketSize,
    uint256 spread,
    uint256 amountIn
  ) external view returns (uint256 amountOut) {
    if (amountIn == 0) return 0;

    FixidityLib.Fraction memory spreadFraction = FixidityLib.fixed1().subtract(FixidityLib.wrap(spread));
    amountOut = spreadFraction.multiply(FixidityLib.newFixed(amountIn)).unwrap();
    amountOut = amountOut.div(FixidityLib.fixed1().unwrap());
    require(
      amountOut <= FixidityLib.newFixed(tokenOutBucketSize).unwrap(),
      "amountOut cant be greater then the tokenOutPool size"
    );
    return amountOut;
  }

  /**
   * @notice Calculates the amount of tokens that should be provided in order to receive the desired amount out.
   * @dev amountIn = amountOut / (1 - spread)
   * @param tokenOutBucketSize The bucket size of the token swapt out.
   * @param spread The spread that is applied to a swap.
   * @param amountOut The amount of tokens in wei that should be swapt out.
   * @return amountIn The amount of tokens in wei that should be provided.
   */
  function getAmountIn(
    uint256,
    uint256 tokenOutBucketSize,
    uint256 spread,
    uint256 amountOut
  ) external view returns (uint256 amountIn) {
    require(amountOut <= tokenOutBucketSize, "amountOut cant be greater then the tokenOutPool size");
    if (amountOut == 0) return 0;

    FixidityLib.Fraction memory denominator = FixidityLib.fixed1().subtract(FixidityLib.wrap(spread));
    FixidityLib.Fraction memory numerator = FixidityLib.newFixed(amountOut);

    // Can't use FixidityLib.divide because numerator can be greater
    // than maxFixedDivisor.
    // Fortunately, we expect an integer result, so integer division gives us as
    // much precision as we could hope for.
    return numerator.unwrap().div(denominator.unwrap());
  }

  /**
   * @notice Returns the AMM that the IPricingModule implements
   * @return Constant Sum.
   */
  function name() external view returns (string memory) {
    return "ConstantSum";
  }
}
        

/lib/openzeppelin-contracts/contracts/ownership/Ownable.sol

pragma solidity ^0.5.0;

import "../GSN/Context.sol";
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
contract Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(isOwner(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Returns true if the caller is the current owner.
     */
    function isOwner() public view returns (bool) {
        return _msgSender() == _owner;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public onlyOwner {
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     */
    function _transferOwnership(address newOwner) internal {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}
          

/lib/openzeppelin-contracts/contracts/math/SafeMath.sol

pragma solidity ^0.5.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     *
     * _Available since v2.4.0._
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     *
     * _Available since v2.4.0._
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     *
     * _Available since v2.4.0._
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}
          

/lib/openzeppelin-contracts/contracts/GSN/Context.sol

pragma solidity ^0.5.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
contract Context {
    // Empty internal constructor, to prevent people from mistakenly deploying
    // an instance of this contract, which should be used via inheritance.
    constructor () internal { }
    // solhint-disable-previous-line no-empty-blocks

    function _msgSender() internal view returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}
          

/contracts/interfaces/IPricingModule.sol

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.5.13;

/**
 * @title Interface for a Mento Pricing Module.
 * @notice A Mento pricing module represents an exchange relation between a pair of ERC20 assets.
 */
interface IPricingModule {
  /**
   * @notice Returns the output amount and new bucket sizes for a given input amount.
   * @param tokenInBucketSize Size of the tokenIn bucket.
   * @param tokenOutBucketSize Size of the tokenOut bucket.
   * @param spread Spread charged on exchanges.
   * @param amountIn Amount of tokenIn being paid in.
   * @return amountOut Amount of tokenOut that will be paid out.
   */
  function getAmountOut(
    uint256 tokenInBucketSize,
    uint256 tokenOutBucketSize,
    uint256 spread,
    uint256 amountIn
  ) external view returns (uint256 amountOut);

  /**
   * @notice Returns the input amount necessary for a given output amount.
   * @param tokenInBucketSize Size of the tokenIn bucket.
   * @param tokenOutBucketSize Size of the tokenOut bucket.
   * @param spread Spread charged on exchanges.
   * @param amountOut Amount of tokenIn being paid out.
   * @return amountIn Amount of tokenOut that would have to be paid in.
   */
  function getAmountIn(
    uint256 tokenInBucketSize,
    uint256 tokenOutBucketSize,
    uint256 spread,
    uint256 amountOut
  ) external view returns (uint256 amountIn);

  /**
   * @notice Retrieve the name of this pricing module.
   * @return exchangeName The name of the pricing module.
   */
  function name() external view returns (string memory pricingModuleName);
}
          

/contracts/common/Initializable.sol

pragma solidity ^0.5.13;

contract Initializable {
  bool public initialized;

  constructor(bool testingDeployment) public {
    if (!testingDeployment) {
      initialized = true;
    }
  }

  modifier initializer() {
    require(!initialized, "contract already initialized");
    initialized = true;
    _;
  }
}
          

/contracts/common/FixidityLib.sol

pragma solidity ^0.5.13;

/**
 * @title FixidityLib
 * @author Gadi Guy, Alberto Cuesta Canada
 * @notice This library provides fixed point arithmetic with protection against
 * overflow.
 * All operations are done with uint256 and the operands must have been created
 * with any of the newFrom* functions, which shift the comma digits() to the
 * right and check for limits, or with wrap() which expects a number already
 * in the internal representation of a fraction.
 * When using this library be sure to use maxNewFixed() as the upper limit for
 * creation of fixed point numbers.
 * @dev All contained functions are pure and thus marked internal to be inlined
 * on consuming contracts at compile time for gas efficiency.
 */
library FixidityLib {
  struct Fraction {
    uint256 value;
  }

  /**
   * @notice Number of positions that the comma is shifted to the right.
   */
  function digits() internal pure returns (uint8) {
    return 24;
  }

  uint256 private constant FIXED1_UINT = 1000000000000000000000000;

  /**
   * @notice This is 1 in the fixed point units used in this library.
   * @dev Test fixed1() equals 10^digits()
   * Hardcoded to 24 digits.
   */
  function fixed1() internal pure returns (Fraction memory) {
    return Fraction(FIXED1_UINT);
  }

  /**
   * @notice Wrap a uint256 that represents a 24-decimal fraction in a Fraction
   * struct.
   * @param x Number that already represents a 24-decimal fraction.
   * @return A Fraction struct with contents x.
   */
  function wrap(uint256 x) internal pure returns (Fraction memory) {
    return Fraction(x);
  }

  /**
   * @notice Unwraps the uint256 inside of a Fraction struct.
   */
  function unwrap(Fraction memory x) internal pure returns (uint256) {
    return x.value;
  }

  /**
   * @notice The amount of decimals lost on each multiplication operand.
   * @dev Test mulPrecision() equals sqrt(fixed1)
   */
  function mulPrecision() internal pure returns (uint256) {
    return 1000000000000;
  }

  /**
   * @notice Maximum value that can be converted to fixed point. Optimize for deployment.
   * @dev
   * Test maxNewFixed() equals maxUint256() / fixed1()
   */
  function maxNewFixed() internal pure returns (uint256) {
    return 115792089237316195423570985008687907853269984665640564;
  }

  /**
   * @notice Converts a uint256 to fixed point Fraction
   * @dev Test newFixed(0) returns 0
   * Test newFixed(1) returns fixed1()
   * Test newFixed(maxNewFixed()) returns maxNewFixed() * fixed1()
   * Test newFixed(maxNewFixed()+1) fails
   */
  function newFixed(uint256 x) internal pure returns (Fraction memory) {
    require(x <= maxNewFixed(), "can't create fixidity number larger than maxNewFixed()");
    return Fraction(x * FIXED1_UINT);
  }

  /**
   * @notice Converts a uint256 in the fixed point representation of this
   * library to a non decimal. All decimal digits will be truncated.
   */
  function fromFixed(Fraction memory x) internal pure returns (uint256) {
    return x.value / FIXED1_UINT;
  }

  /**
   * @notice Converts two uint256 representing a fraction to fixed point units,
   * equivalent to multiplying dividend and divisor by 10^digits().
   * @param numerator numerator must be <= maxNewFixed()
   * @param denominator denominator must be <= maxNewFixed() and denominator can't be 0
   * @dev
   * Test newFixedFraction(1,0) fails
   * Test newFixedFraction(0,1) returns 0
   * Test newFixedFraction(1,1) returns fixed1()
   * Test newFixedFraction(1,fixed1()) returns 1
   */
  function newFixedFraction(uint256 numerator, uint256 denominator) internal pure returns (Fraction memory) {
    Fraction memory convertedNumerator = newFixed(numerator);
    Fraction memory convertedDenominator = newFixed(denominator);
    return divide(convertedNumerator, convertedDenominator);
  }

  /**
   * @notice Returns the integer part of a fixed point number.
   * @dev
   * Test integer(0) returns 0
   * Test integer(fixed1()) returns fixed1()
   * Test integer(newFixed(maxNewFixed())) returns maxNewFixed()*fixed1()
   */
  function integer(Fraction memory x) internal pure returns (Fraction memory) {
    return Fraction((x.value / FIXED1_UINT) * FIXED1_UINT); // Can't overflow
  }

  /**
   * @notice Returns the fractional part of a fixed point number.
   * In the case of a negative number the fractional is also negative.
   * @dev
   * Test fractional(0) returns 0
   * Test fractional(fixed1()) returns 0
   * Test fractional(fixed1()-1) returns 10^24-1
   */
  function fractional(Fraction memory x) internal pure returns (Fraction memory) {
    return Fraction(x.value - (x.value / FIXED1_UINT) * FIXED1_UINT); // Can't overflow
  }

  /**
   * @notice x+y.
   * @dev The maximum value that can be safely used as an addition operator is defined as
   * maxFixedAdd = maxUint256()-1 / 2, or
   * 57896044618658097711785492504343953926634992332820282019728792003956564819967.
   * Test add(maxFixedAdd,maxFixedAdd) equals maxFixedAdd + maxFixedAdd
   * Test add(maxFixedAdd+1,maxFixedAdd+1) throws
   */
  function add(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    uint256 z = x.value + y.value;
    require(z >= x.value, "add overflow detected");
    return Fraction(z);
  }

  /**
   * @notice x-y.
   * @dev
   * Test subtract(6, 10) fails
   */
  function subtract(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    require(x.value >= y.value, "substraction underflow detected");
    return Fraction(x.value - y.value);
  }

  /**
   * @notice x*y. If any of the operators is higher than the max multiplier value it
   * might overflow.
   * @dev The maximum value that can be safely used as a multiplication operator
   * (maxFixedMul) is calculated as sqrt(maxUint256()*fixed1()),
   * or 340282366920938463463374607431768211455999999999999
   * Test multiply(0,0) returns 0
   * Test multiply(maxFixedMul,0) returns 0
   * Test multiply(0,maxFixedMul) returns 0
   * Test multiply(fixed1()/mulPrecision(),fixed1()*mulPrecision()) returns fixed1()
   * Test multiply(maxFixedMul,maxFixedMul) is around maxUint256()
   * Test multiply(maxFixedMul+1,maxFixedMul+1) fails
   */
  // solhint-disable-next-line code-complexity
  function multiply(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    if (x.value == 0 || y.value == 0) return Fraction(0);
    if (y.value == FIXED1_UINT) return x;
    if (x.value == FIXED1_UINT) return y;

    // Separate into integer and fractional parts
    // x = x1 + x2, y = y1 + y2
    uint256 x1 = integer(x).value / FIXED1_UINT;
    uint256 x2 = fractional(x).value;
    uint256 y1 = integer(y).value / FIXED1_UINT;
    uint256 y2 = fractional(y).value;

    // (x1 + x2) * (y1 + y2) = (x1 * y1) + (x1 * y2) + (x2 * y1) + (x2 * y2)
    uint256 x1y1 = x1 * y1;
    if (x1 != 0) require(x1y1 / x1 == y1, "overflow x1y1 detected");

    // x1y1 needs to be multiplied back by fixed1
    // solhint-disable-next-line var-name-mixedcase
    uint256 fixed_x1y1 = x1y1 * FIXED1_UINT;
    if (x1y1 != 0) require(fixed_x1y1 / x1y1 == FIXED1_UINT, "overflow x1y1 * fixed1 detected");
    x1y1 = fixed_x1y1;

    uint256 x2y1 = x2 * y1;
    if (x2 != 0) require(x2y1 / x2 == y1, "overflow x2y1 detected");

    uint256 x1y2 = x1 * y2;
    if (x1 != 0) require(x1y2 / x1 == y2, "overflow x1y2 detected");

    x2 = x2 / mulPrecision();
    y2 = y2 / mulPrecision();
    uint256 x2y2 = x2 * y2;
    if (x2 != 0) require(x2y2 / x2 == y2, "overflow x2y2 detected");

    // result = fixed1() * x1 * y1 + x1 * y2 + x2 * y1 + x2 * y2 / fixed1();
    Fraction memory result = Fraction(x1y1);
    result = add(result, Fraction(x2y1)); // Add checks for overflow
    result = add(result, Fraction(x1y2)); // Add checks for overflow
    result = add(result, Fraction(x2y2)); // Add checks for overflow
    return result;
  }

  /**
   * @notice 1/x
   * @dev
   * Test reciprocal(0) fails
   * Test reciprocal(fixed1()) returns fixed1()
   * Test reciprocal(fixed1()*fixed1()) returns 1 // Testing how the fractional is truncated
   * Test reciprocal(1+fixed1()*fixed1()) returns 0 // Testing how the fractional is truncated
   * Test reciprocal(newFixedFraction(1, 1e24)) returns newFixed(1e24)
   */
  function reciprocal(Fraction memory x) internal pure returns (Fraction memory) {
    require(x.value != 0, "can't call reciprocal(0)");
    return Fraction((FIXED1_UINT * FIXED1_UINT) / x.value); // Can't overflow
  }

  /**
   * @notice x/y. If the dividend is higher than the max dividend value, it
   * might overflow. You can use multiply(x,reciprocal(y)) instead.
   * @dev The maximum value that can be safely used as a dividend (maxNewFixed) is defined as
   * divide(maxNewFixed,newFixedFraction(1,fixed1())) is around maxUint256().
   * This yields the value 115792089237316195423570985008687907853269984665640564.
   * Test maxNewFixed equals maxUint256()/fixed1()
   * Test divide(maxNewFixed,1) equals maxNewFixed*(fixed1)
   * Test divide(maxNewFixed+1,multiply(mulPrecision(),mulPrecision())) throws
   * Test divide(fixed1(),0) fails
   * Test divide(maxNewFixed,1) = maxNewFixed*(10^digits())
   * Test divide(maxNewFixed+1,1) throws
   */
  function divide(Fraction memory x, Fraction memory y) internal pure returns (Fraction memory) {
    require(y.value != 0, "can't divide by 0");
    // solhint-disable-next-line var-name-mixedcase
    uint256 X = x.value * FIXED1_UINT;
    require(X / FIXED1_UINT == x.value, "overflow at divide");
    return Fraction(X / y.value);
  }

  /**
   * @notice x > y
   */
  function gt(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value > y.value;
  }

  /**
   * @notice x >= y
   */
  function gte(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value >= y.value;
  }

  /**
   * @notice x < y
   */
  function lt(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value < y.value;
  }

  /**
   * @notice x <= y
   */
  function lte(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value <= y.value;
  }

  /**
   * @notice x == y
   */
  function equals(Fraction memory x, Fraction memory y) internal pure returns (bool) {
    return x.value == y.value;
  }

  /**
   * @notice x <= 1
   */
  function isProperFraction(Fraction memory x) internal pure returns (bool) {
    return lte(x, fixed1());
  }
}
          

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","payable":false,"inputs":[{"type":"bool","name":"test","internalType":"bool"}]},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"}],"name":"getAmountIn","inputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"tokenOutBucketSize","internalType":"uint256"},{"type":"uint256","name":"spread","internalType":"uint256"},{"type":"uint256","name":"amountOut","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"}],"name":"getAmountOut","inputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"tokenOutBucketSize","internalType":"uint256"},{"type":"uint256","name":"spread","internalType":"uint256"},{"type":"uint256","name":"amountIn","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"initialized","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"initilize","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isOwner","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"string","name":"","internalType":"string"}],"name":"name","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"renounceOwnership","inputs":[],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}],"constant":false}]
              

Contract Creation Code

0x608060405234801561001057600080fd5b50604051620010d1380380620010d1833981016040819052610031916100c6565b8080610045576000805460ff191660011790555b5060006100596001600160e01b036100b116565b60008054610100600160a81b0319166101006001600160a01b038416908102919091178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a35050610108565b3390565b80516100c0816100f1565b92915050565b6000602082840312156100d857600080fd5b60006100e484846100b5565b949350505050565b151590565b6100fa816100ec565b811461010557600080fd5b50565b610fb980620001186000396000f3fe608060405234801561001057600080fd5b50600436106100a35760003560e01c8063715018a6116100765780638f32d59b1161005b5780638f32d59b1461012d578063df91132f14610135578063f2fde38b1461013d576100a3565b8063715018a61461010e5780638da5cb5b14610118576100a3565b806306fdde03146100a8578063158ef93e146100c657806352707d8c146100db578063571fd012146100fb575b600080fd5b6100b0610150565b6040516100bd9190610ded565b60405180910390f35b6100ce610187565b6040516100bd9190610ddf565b6100ee6100e93660046109f9565b610190565b6040516100bd9190610ebe565b6100ee6101093660046109f9565b610247565b6101166102cb565b005b610120610362565b6040516100bd9190610dd1565b6100ce610383565b6101166103c6565b61011661014b3660046109db565b61041f565b60408051808201909152600b81527f436f6e7374616e7453756d000000000000000000000000000000000000000000602082015290565b60005460ff1681565b60008161019f5750600061023f565b6101a76109b2565b6101c76101b38561044f565b6101bb610469565b9063ffffffff61048d16565b90506101ea6101e56101d8856104d1565b839063ffffffff61052016565b610789565b91506102076101fa6101e5610469565b839063ffffffff61078d16565b91506102156101e5866104d1565b82111561023d5760405162461bcd60e51b815260040161023490610e5e565b60405180910390fd5b505b949350505050565b6000838211156102695760405162461bcd60e51b815260040161023490610e5e565b816102765750600061023f565b61027e6109b2565b61028a6101b38561044f565b90506102946109b2565b61029d846104d1565b90506102c06102ab83610789565b6102b483610789565b9063ffffffff61078d16565b979650505050505050565b6102d3610383565b6102ef5760405162461bcd60e51b815260040161023490610e6e565b6000805460405161010090910473ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffff0000000000000000000000000000000000000000ff169055565b600054610100900473ffffffffffffffffffffffffffffffffffffffff1690565b60008054610100900473ffffffffffffffffffffffffffffffffffffffff166103aa6107d6565b73ffffffffffffffffffffffffffffffffffffffff1614905090565b60005460ff16156103e95760405162461bcd60e51b815260040161023490610e0e565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905561041d336107da565b565b610427610383565b6104435760405162461bcd60e51b815260040161023490610e6e565b61044c816107da565b50565b6104576109b2565b50604080516020810190915290815290565b6104716109b2565b50604080516020810190915269d3c21bcecceda1000000815290565b6104956109b2565b8151835110156104b75760405162461bcd60e51b815260040161023490610e1e565b506040805160208101909152815183510381525b92915050565b6104d96109b2565b6104e16108a4565b8211156105005760405162461bcd60e51b815260040161023490610e4e565b50604080516020810190915269d3c21bcecceda100000082028152919050565b6105286109b2565b8251158061053557508151155b1561054f57506040805160208101909152600081526104cb565b815169d3c21bcecceda100000014156105695750816104cb565b825169d3c21bcecceda100000014156105835750806104cb565b600069d3c21bcecceda1000000610599856108bf565b51816105a157fe5b04905060006105af856108f4565b519050600069d3c21bcecceda10000006105c8866108bf565b51816105d057fe5b04905060006105de866108f4565b519050838202841561061257828582816105f457fe5b04146106125760405162461bcd60e51b815260040161023490610dfe565b69d3c21bcecceda1000000810281156106575769d3c21bcecceda100000082828161063957fe5b04146106575760405162461bcd60e51b815260040161023490610e9e565b905080848402851561068b578486828161066d57fe5b041461068b5760405162461bcd60e51b815260040161023490610eae565b86840287156106bc578488828161069e57fe5b04146106bc5760405162461bcd60e51b815260040161023490610e7e565b6106c461092e565b87816106cc57fe5b0496506106d761092e565b85816106df57fe5b049450868502871561071357858882816106f557fe5b04146107135760405162461bcd60e51b815260040161023490610e3e565b61071b6109b2565b604051806020016040528087815250905061074481604051806020016040528087815250610937565b905061075e81604051806020016040528086815250610937565b905061077881604051806020016040528085815250610937565b9d9c50505050505050505050505050565b5190565b60006107cf83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061097b565b9392505050565b3390565b73ffffffffffffffffffffffffffffffffffffffff811661080d5760405162461bcd60e51b815260040161023490610e2e565b6000805460405173ffffffffffffffffffffffffffffffffffffffff8085169361010090930416917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff909216610100027fffffffffffffffffffffff0000000000000000000000000000000000000000ff909216919091179055565b7601357c299a88ea76a58924d52ce4f26a85af186c2b9e7490565b6108c76109b2565b604051806020016040528069d3c21bcecceda1000000808560000151816108ea57fe5b0402905292915050565b6108fc6109b2565b604051806020016040528069d3c21bcecceda10000008085600001518161091f57fe5b95519504029093039092525090565b64e8d4a5100090565b61093f6109b2565b81518351908101908110156109665760405162461bcd60e51b815260040161023490610e8e565b60408051602081019091529081529392505050565b6000818361099c5760405162461bcd60e51b81526004016102349190610ded565b5060008385816109a857fe5b0495945050505050565b6040518060200160405280600081525090565b80356104cb81610f59565b80356104cb81610f6d565b6000602082840312156109ed57600080fd5b600061023f84846109c5565b60008060008060808587031215610a0f57600080fd5b6000610a1b87876109d0565b9450506020610a2c878288016109d0565b9350506040610a3d878288016109d0565b9250506060610a4e878288016109d0565b91505092959194509250565b610a6381610ed5565b82525050565b610a6381610ee0565b6000610a7d82610789565b610a878185610ecc565b9350610a97818560208601610f01565b610aa081610f31565b9093019392505050565b6000610ab7601683610ecc565b7f6f766572666c6f77207831793120646574656374656400000000000000000000815260200192915050565b6000610af0601c83610ecc565b7f636f6e747261637420616c726561647920696e697469616c697a656400000000815260200192915050565b6000610b29601f83610ecc565b7f737562737472616374696f6e20756e646572666c6f7720646574656374656400815260200192915050565b6000610b62602683610ecc565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206181527f6464726573730000000000000000000000000000000000000000000000000000602082015260400192915050565b6000610bc1601683610ecc565b7f6f766572666c6f77207832793220646574656374656400000000000000000000815260200192915050565b6000610bfa603683610ecc565b7f63616e277420637265617465206669786964697479206e756d626572206c617281527f676572207468616e206d61784e65774669786564282900000000000000000000602082015260400192915050565b6000610c59603483610ecc565b7f616d6f756e744f75742063616e742062652067726561746572207468656e207481527f686520746f6b656e4f7574506f6f6c2073697a65000000000000000000000000602082015260400192915050565b6000610cb8602083610ecc565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572815260200192915050565b6000610cf1601683610ecc565b7f6f766572666c6f77207831793220646574656374656400000000000000000000815260200192915050565b6000610d2a601583610ecc565b7f616464206f766572666c6f772064657465637465640000000000000000000000815260200192915050565b6000610d63601f83610ecc565b7f6f766572666c6f772078317931202a2066697865643120646574656374656400815260200192915050565b6000610d9c601683610ecc565b7f6f766572666c6f77207832793120646574656374656400000000000000000000815260200192915050565b610a6381610efe565b602081016104cb8284610a5a565b602081016104cb8284610a69565b602080825281016107cf8184610a72565b602080825281016104cb81610aaa565b602080825281016104cb81610ae3565b602080825281016104cb81610b1c565b602080825281016104cb81610b55565b602080825281016104cb81610bb4565b602080825281016104cb81610bed565b602080825281016104cb81610c4c565b602080825281016104cb81610cab565b602080825281016104cb81610ce4565b602080825281016104cb81610d1d565b602080825281016104cb81610d56565b602080825281016104cb81610d8f565b602081016104cb8284610dc8565b90815260200190565b60006104cb82610ee5565b151590565b73ffffffffffffffffffffffffffffffffffffffff1690565b90565b60005b83811015610f1c578181015183820152602001610f04565b83811115610f2b576000848401525b50505050565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690565b610f6281610ed5565b811461044c57600080fd5b610f6281610efe56fea365627a7a72315820eb48e592f661a82f9fc5dd79ed2f42e502ec3f9793654eb4668320436e0f4e7b6c6578706572696d656e74616cf564736f6c634300051100400000000000000000000000000000000000000000000000000000000000000001

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106100a35760003560e01c8063715018a6116100765780638f32d59b1161005b5780638f32d59b1461012d578063df91132f14610135578063f2fde38b1461013d576100a3565b8063715018a61461010e5780638da5cb5b14610118576100a3565b806306fdde03146100a8578063158ef93e146100c657806352707d8c146100db578063571fd012146100fb575b600080fd5b6100b0610150565b6040516100bd9190610ded565b60405180910390f35b6100ce610187565b6040516100bd9190610ddf565b6100ee6100e93660046109f9565b610190565b6040516100bd9190610ebe565b6100ee6101093660046109f9565b610247565b6101166102cb565b005b610120610362565b6040516100bd9190610dd1565b6100ce610383565b6101166103c6565b61011661014b3660046109db565b61041f565b60408051808201909152600b81527f436f6e7374616e7453756d000000000000000000000000000000000000000000602082015290565b60005460ff1681565b60008161019f5750600061023f565b6101a76109b2565b6101c76101b38561044f565b6101bb610469565b9063ffffffff61048d16565b90506101ea6101e56101d8856104d1565b839063ffffffff61052016565b610789565b91506102076101fa6101e5610469565b839063ffffffff61078d16565b91506102156101e5866104d1565b82111561023d5760405162461bcd60e51b815260040161023490610e5e565b60405180910390fd5b505b949350505050565b6000838211156102695760405162461bcd60e51b815260040161023490610e5e565b816102765750600061023f565b61027e6109b2565b61028a6101b38561044f565b90506102946109b2565b61029d846104d1565b90506102c06102ab83610789565b6102b483610789565b9063ffffffff61078d16565b979650505050505050565b6102d3610383565b6102ef5760405162461bcd60e51b815260040161023490610e6e565b6000805460405161010090910473ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffff0000000000000000000000000000000000000000ff169055565b600054610100900473ffffffffffffffffffffffffffffffffffffffff1690565b60008054610100900473ffffffffffffffffffffffffffffffffffffffff166103aa6107d6565b73ffffffffffffffffffffffffffffffffffffffff1614905090565b60005460ff16156103e95760405162461bcd60e51b815260040161023490610e0e565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905561041d336107da565b565b610427610383565b6104435760405162461bcd60e51b815260040161023490610e6e565b61044c816107da565b50565b6104576109b2565b50604080516020810190915290815290565b6104716109b2565b50604080516020810190915269d3c21bcecceda1000000815290565b6104956109b2565b8151835110156104b75760405162461bcd60e51b815260040161023490610e1e565b506040805160208101909152815183510381525b92915050565b6104d96109b2565b6104e16108a4565b8211156105005760405162461bcd60e51b815260040161023490610e4e565b50604080516020810190915269d3c21bcecceda100000082028152919050565b6105286109b2565b8251158061053557508151155b1561054f57506040805160208101909152600081526104cb565b815169d3c21bcecceda100000014156105695750816104cb565b825169d3c21bcecceda100000014156105835750806104cb565b600069d3c21bcecceda1000000610599856108bf565b51816105a157fe5b04905060006105af856108f4565b519050600069d3c21bcecceda10000006105c8866108bf565b51816105d057fe5b04905060006105de866108f4565b519050838202841561061257828582816105f457fe5b04146106125760405162461bcd60e51b815260040161023490610dfe565b69d3c21bcecceda1000000810281156106575769d3c21bcecceda100000082828161063957fe5b04146106575760405162461bcd60e51b815260040161023490610e9e565b905080848402851561068b578486828161066d57fe5b041461068b5760405162461bcd60e51b815260040161023490610eae565b86840287156106bc578488828161069e57fe5b04146106bc5760405162461bcd60e51b815260040161023490610e7e565b6106c461092e565b87816106cc57fe5b0496506106d761092e565b85816106df57fe5b049450868502871561071357858882816106f557fe5b04146107135760405162461bcd60e51b815260040161023490610e3e565b61071b6109b2565b604051806020016040528087815250905061074481604051806020016040528087815250610937565b905061075e81604051806020016040528086815250610937565b905061077881604051806020016040528085815250610937565b9d9c50505050505050505050505050565b5190565b60006107cf83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061097b565b9392505050565b3390565b73ffffffffffffffffffffffffffffffffffffffff811661080d5760405162461bcd60e51b815260040161023490610e2e565b6000805460405173ffffffffffffffffffffffffffffffffffffffff8085169361010090930416917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff909216610100027fffffffffffffffffffffff0000000000000000000000000000000000000000ff909216919091179055565b7601357c299a88ea76a58924d52ce4f26a85af186c2b9e7490565b6108c76109b2565b604051806020016040528069d3c21bcecceda1000000808560000151816108ea57fe5b0402905292915050565b6108fc6109b2565b604051806020016040528069d3c21bcecceda10000008085600001518161091f57fe5b95519504029093039092525090565b64e8d4a5100090565b61093f6109b2565b81518351908101908110156109665760405162461bcd60e51b815260040161023490610e8e565b60408051602081019091529081529392505050565b6000818361099c5760405162461bcd60e51b81526004016102349190610ded565b5060008385816109a857fe5b0495945050505050565b6040518060200160405280600081525090565b80356104cb81610f59565b80356104cb81610f6d565b6000602082840312156109ed57600080fd5b600061023f84846109c5565b60008060008060808587031215610a0f57600080fd5b6000610a1b87876109d0565b9450506020610a2c878288016109d0565b9350506040610a3d878288016109d0565b9250506060610a4e878288016109d0565b91505092959194509250565b610a6381610ed5565b82525050565b610a6381610ee0565b6000610a7d82610789565b610a878185610ecc565b9350610a97818560208601610f01565b610aa081610f31565b9093019392505050565b6000610ab7601683610ecc565b7f6f766572666c6f77207831793120646574656374656400000000000000000000815260200192915050565b6000610af0601c83610ecc565b7f636f6e747261637420616c726561647920696e697469616c697a656400000000815260200192915050565b6000610b29601f83610ecc565b7f737562737472616374696f6e20756e646572666c6f7720646574656374656400815260200192915050565b6000610b62602683610ecc565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206181527f6464726573730000000000000000000000000000000000000000000000000000602082015260400192915050565b6000610bc1601683610ecc565b7f6f766572666c6f77207832793220646574656374656400000000000000000000815260200192915050565b6000610bfa603683610ecc565b7f63616e277420637265617465206669786964697479206e756d626572206c617281527f676572207468616e206d61784e65774669786564282900000000000000000000602082015260400192915050565b6000610c59603483610ecc565b7f616d6f756e744f75742063616e742062652067726561746572207468656e207481527f686520746f6b656e4f7574506f6f6c2073697a65000000000000000000000000602082015260400192915050565b6000610cb8602083610ecc565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572815260200192915050565b6000610cf1601683610ecc565b7f6f766572666c6f77207831793220646574656374656400000000000000000000815260200192915050565b6000610d2a601583610ecc565b7f616464206f766572666c6f772064657465637465640000000000000000000000815260200192915050565b6000610d63601f83610ecc565b7f6f766572666c6f772078317931202a2066697865643120646574656374656400815260200192915050565b6000610d9c601683610ecc565b7f6f766572666c6f77207832793120646574656374656400000000000000000000815260200192915050565b610a6381610efe565b602081016104cb8284610a5a565b602081016104cb8284610a69565b602080825281016107cf8184610a72565b602080825281016104cb81610aaa565b602080825281016104cb81610ae3565b602080825281016104cb81610b1c565b602080825281016104cb81610b55565b602080825281016104cb81610bb4565b602080825281016104cb81610bed565b602080825281016104cb81610c4c565b602080825281016104cb81610cab565b602080825281016104cb81610ce4565b602080825281016104cb81610d1d565b602080825281016104cb81610d56565b602080825281016104cb81610d8f565b602081016104cb8284610dc8565b90815260200190565b60006104cb82610ee5565b151590565b73ffffffffffffffffffffffffffffffffffffffff1690565b90565b60005b83811015610f1c578181015183820152602001610f04565b83811115610f2b576000848401525b50505050565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690565b610f6281610ed5565b811461044c57600080fd5b610f6281610efe56fea365627a7a72315820eb48e592f661a82f9fc5dd79ed2f42e502ec3f9793654eb4668320436e0f4e7b6c6578706572696d656e74616cf564736f6c63430005110040