ETH Price: $1,576.50 (-1.29%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

2 Internal Transactions found.

Latest 2 internal transactions

Advanced mode:
Parent Transaction Hash Method Block
From
To
Transfer181550432023-09-17 10:02:59581 days ago1694944979
0x03aA019F...A1f62859A
0 ETH
0x60a03461181550432023-09-17 10:02:59581 days ago1694944979  Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
DodoV2Oracle

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
default evmVersion
File 1 of 8 : DodoV2Oracle.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "../interfaces/IDodo.sol";
import "../interfaces/IDodoFactories.sol";
import "../interfaces/IOracle.sol";
import "../libraries/OraclePrices.sol";

// solhint-disable var-name-mixedcase

contract DodoV2Oracle is IOracle {
    using OraclePrices for OraclePrices.Data;
    using Math for uint256;

    IDVMFactory public immutable FACTORY; // DVMFactory
    IERC20 private constant _NONE = IERC20(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF);

    constructor(IDVMFactory _DVMFactory) {
        FACTORY = _DVMFactory;
    }

    function getRate(IERC20 srcToken, IERC20 dstToken, IERC20 connector, uint256 thresholdFilter) external view override returns (uint256 rate, uint256 weight) {
        OraclePrices.Data memory ratesAndWeights;
        if (connector == _NONE) {
            (address[] memory machines, bool isSrcBase) = _getMachines(address(srcToken), address(dstToken));
            ratesAndWeights = OraclePrices.init(machines.length);
            for (uint256 i = 0; i < machines.length; i++) {
                IDVM dvm = IDVM(machines[i]);
                (uint256 r, uint256 b0, uint256 b1) = _getDodoInfo(dvm, isSrcBase);
                ratesAndWeights.append(OraclePrices.OraclePrice(r, (b0 * b1).sqrt()));
            }
        } else {
            (address[] memory machines0, bool isSrcBase0) = _getMachines(address(srcToken), address(connector));
            (address[] memory machines1, bool isSrcBase1) = _getMachines(address(connector), address(dstToken));
            ratesAndWeights = OraclePrices.init(machines0.length * machines1.length);
            for (uint256 i = 0; i < machines0.length; i++) {
                (uint256 r0, uint256 b0, uint256 bc0) = _getDodoInfo(IDVM(machines0[i]), isSrcBase0);
                if (b0 == 0 || bc0 == 0) {
                    continue;
                }
                for (uint256 j = 0; j < machines1.length; j++) {
                    (uint256 r1, uint256 bc1, uint256 b1) = _getDodoInfo(IDVM(machines1[j]), isSrcBase1);
                    if (b1 == 0 || bc1 == 0) {
                        continue;
                    }
                    uint256 w = Math.min(b0 * bc0, b1 * bc1).sqrt();
                    ratesAndWeights.append(OraclePrices.OraclePrice(Math.mulDiv(r0, r1, 1e18), w));
                }
            }
        }
        return ratesAndWeights.getRateAndWeight(thresholdFilter);
    }

    function _getMachines(address srcToken, address dstToken) internal view returns (address[] memory machines, bool isSrcBase) {
        machines = FACTORY.getDODOPool(srcToken, dstToken);
        isSrcBase = (machines.length != 0);
        if (!isSrcBase) machines = FACTORY.getDODOPool(dstToken, srcToken);
        if(machines.length == 0) revert PoolNotFound();
    }

    function _getDodoInfo(IDVM dvm, bool isSrcBase) internal view returns (uint256 rate, uint256 balanceSrc, uint256 balanceDst) {
            uint256 b0 = dvm._BASE_RESERVE_();
            uint256 b1 = dvm._QUOTE_RESERVE_();
            if (b0 != 0 && b1 != 0) {
                uint256 price = dvm.getMidPrice();
                rate += isSrcBase ? price : 1e36 / price;
                (balanceSrc, balanceDst) = isSrcBase ? (b0, b1) : (b1, b0);
            }
        }
}

File 2 of 8 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

File 3 of 8 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 4 of 8 : SafeMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // 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 (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @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) {
        return a + b;
    }

    /**
     * @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 a - b;
    }

    /**
     * @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) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting 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 a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

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

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

File 5 of 8 : IDodo.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

// solhint-disable private-vars-leading-underscore
// solhint-disable func-name-mixedcase

interface IDodo {
    function _BASE_BALANCE_() external view returns (uint256);
    function _QUOTE_BALANCE_() external view returns (uint256);
    function getMidPrice() external view returns (uint256 midPrice);
}

interface IDVM {
    function _BASE_RESERVE_() external view returns (uint256);
    function _QUOTE_RESERVE_() external view returns (uint256);
    function getMidPrice() external view returns (uint256 midPrice);
}

File 6 of 8 : IDodoFactories.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IDodoZoo {
    function getDODO(address baseToken, address quoteToken) external view returns (address);
}

interface IDVMFactory {
    function getDODOPool(address baseToken, address quoteToken) external view returns (address[] memory machines);
}

File 7 of 8 : IOracle.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IOracle {
    error ConnectorShouldBeNone();
    error PoolNotFound();
    error PoolWithConnectorNotFound();

    function getRate(IERC20 srcToken, IERC20 dstToken, IERC20 connector, uint256 thresholdFilter) external view returns (uint256 rate, uint256 weight);
}

File 8 of 8 : OraclePrices.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

/**
 * @title OraclePrices
 * @notice A library that provides functionalities for processing and analyzing token rate and weight data provided by an oracle.
 *         The library is used when an oracle uses multiple pools to determine a token's price.
 *         It allows to filter out pools with low weight and significantly incorrect price, which could distort the weighted price.
 *         The level of low-weight pool filtering can be managed using the thresholdFilter parameter.
 */
library OraclePrices {
    using SafeMath for uint256;

    /**
    * @title Oracle Price Data Structure
    * @notice This structure encapsulates the rate and weight information for tokens as provided by an oracle
    * @dev An array of OraclePrice structures can be used to represent oracle data for multiple pools
    * @param rate The oracle-provided rate for a token
    * @param weight The oracle-provided derived weight for a token
    */
    struct OraclePrice {
        uint256 rate;
        uint256 weight;
    }

    /**
    * @title Oracle Prices Data Structure
    * @notice This structure encapsulates information about a list of oracles prices and weights
    * @dev The structure is initialized with a maximum possible length by the `init` function
    * @param oraclePrices An array of OraclePrice structures, each containing a rate and weight
    * @param maxOracleWeight The maximum weight among the OraclePrice elements in the oraclePrices array
    * @param size The number of meaningful OraclePrice elements added to the oraclePrices array
    */
    struct Data {
        uint256 maxOracleWeight;
        uint256 size;
        OraclePrice[] oraclePrices;
    }

    /**
    * @notice Initializes an array of OraclePrices with a given maximum length and returns it wrapped inside a Data struct
    * @dev Uses inline assembly for memory allocation to avoid array zeroing and extra array copy to struct
    * @param maxArrLength The maximum length of the oraclePrices array
    * @return data Returns an instance of Data struct containing an OraclePrice array with a specified maximum length
    */
    function init(uint256 maxArrLength) internal pure returns (Data memory data) {
        assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
            data := mload(0x40)
            mstore(0x40, add(data, add(0x80, mul(maxArrLength, 0x40))))
            mstore(add(data, 0x00), 0)
            mstore(add(data, 0x20), 0)
            mstore(add(data, 0x40), add(data, 0x60))
            mstore(add(data, 0x60), maxArrLength)
        }
    }

    /**
    * @notice Appends an OraclePrice to the oraclePrices array in the provided Data struct if the OraclePrice has a non-zero weight
    * @dev If the weight of the OraclePrice is greater than the current maxOracleWeight, the maxOracleWeight is updated. The size (number of meaningful elements) of the array is incremented after appending the OraclePrice.
    * @param data The Data struct that contains the oraclePrices array, maxOracleWeight, and the current size
    * @param oraclePrice The OraclePrice to be appended to the oraclePrices array
    * @return isAppended A flag indicating whether the oraclePrice was appended or not
    */
    function append(Data memory data, OraclePrice memory oraclePrice) internal pure returns (bool isAppended) {
        if (oraclePrice.weight > 0) {
            data.oraclePrices[data.size] = oraclePrice;
            data.size++;
            if (oraclePrice.weight > data.maxOracleWeight) {
                data.maxOracleWeight = oraclePrice.weight;
            }
            return true;
        }
        return false;
    }

    /**
    * @notice Calculates the weighted rate from the oracle prices data using a threshold filter
    * @dev Shrinks the `oraclePrices` array to remove any unused space, though it's unclear how this optimizes the code, but it is. Then calculates the weighted rate
    *      considering only the oracle prices whose weight is above the threshold which is percent from max weight
    * @param data The data structure containing oracle prices, the maximum oracle weight and the size of the used oracle prices array
    * @param thresholdFilter The threshold to filter oracle prices based on their weight
    * @return weightedRate The calculated weighted rate
    * @return totalWeight The total weight of the oracle prices that passed the threshold
    */
    function getRateAndWeight(Data memory data, uint256 thresholdFilter) internal pure returns (uint256 weightedRate, uint256 totalWeight) {
        // shrink oraclePrices array
        uint256 size = data.size;
        assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
            let ptr := mload(add(data, 64))
            mstore(ptr, size)
        }

        // calculate weighted rate
        for (uint256 i = 0; i < size; i++) {
            OraclePrice memory p = data.oraclePrices[i];
            if (p.weight * 100 < data.maxOracleWeight * thresholdFilter) {
                continue;
            }
            weightedRate += p.rate * p.weight;
            totalWeight += p.weight;
        }
        if (totalWeight > 0) {
            unchecked { weightedRate /= totalWeight; }
        }
    }

    /**
    * @notice See `getRateAndWeight`. It uses SafeMath to prevent overflows.
    */
    function getRateAndWeightWithSafeMath(Data memory data, uint256 thresholdFilter) internal pure returns (uint256 weightedRate, uint256 totalWeight) {
        // shrink oraclePrices array
        uint256 size = data.size;
        assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
            let ptr := mload(add(data, 64))
            mstore(ptr, size)
        }

        // calculate weighted rate
        for (uint256 i = 0; i < size; i++) {
            OraclePrice memory p = data.oraclePrices[i];
            if (p.weight * 100 < data.maxOracleWeight * thresholdFilter) {
                continue;
            }
            (bool ok, uint256 weightedRateI) = p.rate.tryMul(p.weight);
            if (ok) {
                (ok, weightedRate) = _tryAdd(weightedRate, weightedRateI);
                if (ok) totalWeight += p.weight;
            }
        }
        if (totalWeight > 0) {
            unchecked { weightedRate /= totalWeight; }
        }
    }

    function _tryAdd(uint256 value, uint256 addition) private pure returns (bool, uint256) {
        unchecked {
            uint256 result = value + addition;
            if (result < value) return (false, value);
            return (true, result);
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 1000000
  },
  "viaIR": true,
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IDVMFactory","name":"_DVMFactory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ConnectorShouldBeNone","type":"error"},{"inputs":[],"name":"PoolNotFound","type":"error"},{"inputs":[],"name":"PoolWithConnectorNotFound","type":"error"},{"inputs":[],"name":"FACTORY","outputs":[{"internalType":"contract IDVMFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"srcToken","type":"address"},{"internalType":"contract IERC20","name":"dstToken","type":"address"},{"internalType":"contract IERC20","name":"connector","type":"address"},{"internalType":"uint256","name":"thresholdFilter","type":"uint256"}],"name":"getRate","outputs":[{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"}],"stateMutability":"view","type":"function"}]

60a03461007157601f610da938819003918201601f19168301916001600160401b038311848410176100765780849260209460405283398101031261007157516001600160a01b038116810361007157608052604051610d1c908161008d823960805181818161040301526109990152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe60806040908082526004908136101561001757600080fd5b600090813560e01c9081632dd31000146103b95750633d549b321461003b57600080fd5b346103b65760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103b657813573ffffffffffffffffffffffffffffffffffffffff8082168092036103b2576024918235908282168092036103ae57604435918383168093036103aa576064918235936100b76104b7565b508086036102395750906100ca91610940565b9490926100d78451610807565b96805b8a865182101561013a579061012f610111610135936101166101088d8d610101888f610558565b5116610ac2565b909491946104e9565b6106c4565b9051916101228361042b565b825260208201528b610839565b5061052b565b6100da565b50939796509450925090505b8295839560209586810151938a8201968588515280975b868910610189578c8c8c8c81610178575b8351928352820152f35b91816101839161059b565b9161016e565b90919293949596979961019d8b8351610558565b519b8a8d019c8d51888102908082048a149015171561020e576101c18c89516104e9565b1161020157916101e66101ee928f6101e0906101f496519051906104e9565b90610895565b9d5190610895565b9a61052b565b979695949392919061015d565b509b50996101f49061052b565b868660118c7f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b939895969197949061024e8561025692610940565b999095610940565b9961026c61026787518451906104e9565b610807565b96849a5b87518c101561039257908161028c8e93878f610101908d610558565b9d8e829b929c939c15908115610389575b5061037357895b885181101561034c578f908f918f928f938f948f958f968f8e61032a996101018a6102ce94610558565b9093919281158015610344575b610336576102fc610312956102f661012f9b61030c966104e9565b936104e9565b90508082101561032f57506106c4565b926105d4565b92519261031e8461042b565b83526020830152610839565b6102a4565b90506106c4565b50505050505050505061052b565b5084156102db565b50959450959850959850959a509a6103639061052b565b9a90919994969396959295610270565b959450959850959850959a509a6103639061052b565b9050158f61029d565b50949950959796995050509150949392919091610146565b8580fd5b8480fd5b8280fd5b80fd5b90503461042757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126104275760209073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b5080fd5b6040810190811067ffffffffffffffff82111761044757604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761044757604052565b604051906060820182811067ffffffffffffffff82111761044757604052606060408360008152600060208201520152565b818102929181159184041417156104fc57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146104fc5760010190565b805182101561056c5760209160051b010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b81156105a5570490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff818309818302918280831092039180830392146106b357670de0b6b3a76400009082821115610655577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4d6174683a206d756c446976206f766572666c6f7700000000000000000000006044820152fd5b5050670de0b6b3a764000091500490565b80156108015761078f816000908360801c806107f5575b508060401c806107e8575b508060201c806107db575b508060101c806107ce575b508060081c806107c1575b508060041c806107b4575b508060021c806107a7575b50600191828092811c6107a0575b1c1b610737818561059b565b01811c610744818561059b565b01811c610751818561059b565b01811c61075e818561059b565b01811c61076b818561059b565b01811c610778818561059b565b01811c610785818561059b565b01901c809261059b565b8082101561079b575090565b905090565b018161072b565b600291509101903861071d565b6004915091019038610712565b6008915091019038610707565b60109150910190386106fc565b60209150910190386106f1565b60409150910190386106e6565b915050608090386106db565b50600090565b906108106104b7565b506040519160808160061b84010160405260008352600060208401526060830180604085015252565b906020810190815161084d57505050600090565b61086e60408401519160208501928351916108688383610558565b52610558565b50610879815161052b565b905251908051821161088d575b5050600190565b523880610886565b919082018092116104fc57565b90602090818382031261093b57825167ffffffffffffffff9384821161093b570181601f8201121561093b578051938411610447578360051b90604051946108ec85840187610476565b8552838086019282010192831161093b578301905b82821061090f575050505090565b815173ffffffffffffffffffffffffffffffffffffffff8116810361093b578152908301908301610901565b600080fd5b6040517f57a281dc0000000000000000000000000000000000000000000000000000000080825273ffffffffffffffffffffffffffffffffffffffff8381166004840152848116602484015291949093909260009290917f0000000000000000000000000000000000000000000000000000000000000000909116908387604481855afa968715610ab7578497610a9b575b5086511595861596610a17575b50505050508251156109ed57565b60046040517f76ecffc0000000000000000000000000000000000000000000000000000000008152fd5b60405190815273ffffffffffffffffffffffffffffffffffffffff91821660048201529216602483015292945090918290829060449082905afa918215610a8f578092610a6c575b50509138808080806109df565b610a8892503d8091833e610a808183610476565b8101906108a2565b3880610a5f565b604051903d90823e3d90fd5b610ab09197503d8086833e610a808183610476565b95386109d2565b6040513d86823e3d90fd5b6000926000809373ffffffffffffffffffffffffffffffffffffffff829416906040908151917f7d72150400000000000000000000000000000000000000000000000000000000835260208084600481885afa938415610cdc578694610cad575b508151947fbbf5ce780000000000000000000000000000000000000000000000000000000086528186600481845afa958615610ca3578796610c70575b5084151580610c67575b610b78575b50505050505050565b909295995060049396985081839295985051938480927fee27c6890000000000000000000000000000000000000000000000000000000082525afa928315610c5e57508792610c30575b50508115610be7575b945015610be257905b909138808080808080610b6f565b610bd4565b8015610c03576ec097ce7bc90715b34b9f100000000004610bcb565b6024867f4e487b710000000000000000000000000000000000000000000000000000000081526012600452fd5b90809250813d8311610c57575b610c478183610476565b810103126103aa57513880610bc2565b503d610c3d565b513d89823e3d90fd5b50851515610b6a565b9095508181813d8311610c9c575b610c888183610476565b81010312610c9857519438610b60565b8680fd5b503d610c7e565b83513d89823e3d90fd5b9080945081813d8311610cd5575b610cc58183610476565b810103126103aa57519238610b23565b503d610cbb565b82513d88823e3d90fdfea26469706673582212200b538e770906f153cf3b5bb782d51e6433ee8e1b8f6cd316ebe6194f5928e04f64736f6c6343000813003300000000000000000000000072d220ce168c4f361dd4dee5d826a01ad8598f6c

Deployed Bytecode

0x60806040908082526004908136101561001757600080fd5b600090813560e01c9081632dd31000146103b95750633d549b321461003b57600080fd5b346103b65760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103b657813573ffffffffffffffffffffffffffffffffffffffff8082168092036103b2576024918235908282168092036103ae57604435918383168093036103aa576064918235936100b76104b7565b508086036102395750906100ca91610940565b9490926100d78451610807565b96805b8a865182101561013a579061012f610111610135936101166101088d8d610101888f610558565b5116610ac2565b909491946104e9565b6106c4565b9051916101228361042b565b825260208201528b610839565b5061052b565b6100da565b50939796509450925090505b8295839560209586810151938a8201968588515280975b868910610189578c8c8c8c81610178575b8351928352820152f35b91816101839161059b565b9161016e565b90919293949596979961019d8b8351610558565b519b8a8d019c8d51888102908082048a149015171561020e576101c18c89516104e9565b1161020157916101e66101ee928f6101e0906101f496519051906104e9565b90610895565b9d5190610895565b9a61052b565b979695949392919061015d565b509b50996101f49061052b565b868660118c7f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b939895969197949061024e8561025692610940565b999095610940565b9961026c61026787518451906104e9565b610807565b96849a5b87518c101561039257908161028c8e93878f610101908d610558565b9d8e829b929c939c15908115610389575b5061037357895b885181101561034c578f908f918f928f938f948f958f968f8e61032a996101018a6102ce94610558565b9093919281158015610344575b610336576102fc610312956102f661012f9b61030c966104e9565b936104e9565b90508082101561032f57506106c4565b926105d4565b92519261031e8461042b565b83526020830152610839565b6102a4565b90506106c4565b50505050505050505061052b565b5084156102db565b50959450959850959850959a509a6103639061052b565b9a90919994969396959295610270565b959450959850959850959a509a6103639061052b565b9050158f61029d565b50949950959796995050509150949392919091610146565b8580fd5b8480fd5b8280fd5b80fd5b90503461042757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126104275760209073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000072d220ce168c4f361dd4dee5d826a01ad8598f6c168152f35b5080fd5b6040810190811067ffffffffffffffff82111761044757604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761044757604052565b604051906060820182811067ffffffffffffffff82111761044757604052606060408360008152600060208201520152565b818102929181159184041417156104fc57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146104fc5760010190565b805182101561056c5760209160051b010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b81156105a5570490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff818309818302918280831092039180830392146106b357670de0b6b3a76400009082821115610655577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4d6174683a206d756c446976206f766572666c6f7700000000000000000000006044820152fd5b5050670de0b6b3a764000091500490565b80156108015761078f816000908360801c806107f5575b508060401c806107e8575b508060201c806107db575b508060101c806107ce575b508060081c806107c1575b508060041c806107b4575b508060021c806107a7575b50600191828092811c6107a0575b1c1b610737818561059b565b01811c610744818561059b565b01811c610751818561059b565b01811c61075e818561059b565b01811c61076b818561059b565b01811c610778818561059b565b01811c610785818561059b565b01901c809261059b565b8082101561079b575090565b905090565b018161072b565b600291509101903861071d565b6004915091019038610712565b6008915091019038610707565b60109150910190386106fc565b60209150910190386106f1565b60409150910190386106e6565b915050608090386106db565b50600090565b906108106104b7565b506040519160808160061b84010160405260008352600060208401526060830180604085015252565b906020810190815161084d57505050600090565b61086e60408401519160208501928351916108688383610558565b52610558565b50610879815161052b565b905251908051821161088d575b5050600190565b523880610886565b919082018092116104fc57565b90602090818382031261093b57825167ffffffffffffffff9384821161093b570181601f8201121561093b578051938411610447578360051b90604051946108ec85840187610476565b8552838086019282010192831161093b578301905b82821061090f575050505090565b815173ffffffffffffffffffffffffffffffffffffffff8116810361093b578152908301908301610901565b600080fd5b6040517f57a281dc0000000000000000000000000000000000000000000000000000000080825273ffffffffffffffffffffffffffffffffffffffff8381166004840152848116602484015291949093909260009290917f00000000000000000000000072d220ce168c4f361dd4dee5d826a01ad8598f6c909116908387604481855afa968715610ab7578497610a9b575b5086511595861596610a17575b50505050508251156109ed57565b60046040517f76ecffc0000000000000000000000000000000000000000000000000000000008152fd5b60405190815273ffffffffffffffffffffffffffffffffffffffff91821660048201529216602483015292945090918290829060449082905afa918215610a8f578092610a6c575b50509138808080806109df565b610a8892503d8091833e610a808183610476565b8101906108a2565b3880610a5f565b604051903d90823e3d90fd5b610ab09197503d8086833e610a808183610476565b95386109d2565b6040513d86823e3d90fd5b6000926000809373ffffffffffffffffffffffffffffffffffffffff829416906040908151917f7d72150400000000000000000000000000000000000000000000000000000000835260208084600481885afa938415610cdc578694610cad575b508151947fbbf5ce780000000000000000000000000000000000000000000000000000000086528186600481845afa958615610ca3578796610c70575b5084151580610c67575b610b78575b50505050505050565b909295995060049396985081839295985051938480927fee27c6890000000000000000000000000000000000000000000000000000000082525afa928315610c5e57508792610c30575b50508115610be7575b945015610be257905b909138808080808080610b6f565b610bd4565b8015610c03576ec097ce7bc90715b34b9f100000000004610bcb565b6024867f4e487b710000000000000000000000000000000000000000000000000000000081526012600452fd5b90809250813d8311610c57575b610c478183610476565b810103126103aa57513880610bc2565b503d610c3d565b513d89823e3d90fd5b50851515610b6a565b9095508181813d8311610c9c575b610c888183610476565b81010312610c9857519438610b60565b8680fd5b503d610c7e565b83513d89823e3d90fd5b9080945081813d8311610cd5575b610cc58183610476565b810103126103aa57519238610b23565b503d610cbb565b82513d88823e3d90fdfea26469706673582212200b538e770906f153cf3b5bb782d51e6433ee8e1b8f6cd316ebe6194f5928e04f64736f6c63430008130033

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

00000000000000000000000072d220ce168c4f361dd4dee5d826a01ad8598f6c

-----Decoded View---------------
Arg [0] : _DVMFactory (address): 0x72d220cE168C4f361dD4deE5D826a01AD8598f6C

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000072d220ce168c4f361dd4dee5d826a01ad8598f6c


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
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ 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.