Contract 0x695Ea29618d3a66fb2C3B1e95B352E561EaBa0Bc

Contract Overview

Balance:
0 Ether
Txn Hash
Method
Block
From
To
Value
0x0cd7dc6dd9aabc6e4c0b46d760fdf933dd501479439feabca3fcb494bc0c54c00x6080604089992762021-07-25 15:43:43430 days 21 hrs ago0x6e517707b0d7e89c6cb68230b2fb4305fee51613 IN  Create: OOFTWAP0 Ether0.0115578910
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
OOFTWAP

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion
File 1 of 2 : OpenOracleFrameworkTWAP.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
pragma abicoder v2;

import {Address} from "@openzeppelin/contracts/utils/Address.sol";

interface IOpenOracleFramework {
    /**
    * @dev getHistoricalFeeds function lets the caller receive historical values for a given timestamp
    *
    * @param feedIDs the array of feedIds
    * @param timestamps the array of timestamps
    */
    function getHistoricalFeeds(uint256[] memory feedIDs, uint256[] memory timestamps) external view returns (uint256[] memory);

    /**
    * @dev getFeeds function lets anyone call the oracle to receive data (maybe pay an optional fee)
    *
    * @param feedIDs the array of feedIds
    */
    function getFeeds(uint256[] memory feedIDs) external view returns (uint256[] memory, uint256[] memory, uint256[] memory);

    /**
    * @dev getFeed function lets anyone call the oracle to receive data (maybe pay an optional fee)
    *
    * @param feedID the array of feedId
    */
    function getFeed(uint256 feedID) external view returns (uint256, uint256, uint256);

    /**
    * @dev getFeedList function returns the metadata of a feed
    *
    * @param feedIDs the array of feedId
    */
    function getFeedList(uint256[] memory feedIDs) external view returns(string[] memory, uint256[] memory, uint256[] memory, uint256[] memory, uint256[] memory);
}

contract OOFTWAP {

    // using Openzeppelin contracts for SafeMath and Address
    using Address for address;

    constructor() {
        
    }

    //---------------------------view functions ---------------------------

    function getTWAP(IOpenOracleFramework OOFContract, uint256[] memory feedIDs, uint256[] memory timestampstart, uint256[] memory timestampfinish, bool strictMode) external view returns (uint256[] memory TWAP) {

            uint256 feedLen = feedIDs.length;
            TWAP = new uint256[](feedLen);
            uint256[] memory timeslot = new uint256[](feedLen);

            require(feedIDs.length == timestampstart.length && feedIDs.length == timestampfinish.length, "Feeds and Timestamps must match");

            (,,timeslot,,) = OOFContract.getFeedList(feedIDs);

            for (uint c = 0; c < feedLen; c++) {

                uint256 twapCount = timestampfinish[c] / timeslot[c] - timestampstart[c] / timeslot[c] + 1;
                uint256[] memory twapFeedIDs = new uint256[](twapCount);
                uint256[] memory timestampToCheck = new uint256[](twapCount);
                uint256 twapTotal;

                uint256[] memory totals = new uint256[](twapCount);

                for (uint s = 0; s < twapCount; s++) {
                    timestampToCheck[s] = timestampstart[c] + s * timeslot[c];
                    twapFeedIDs[s] = feedIDs[c];
                }

                totals = OOFContract.getHistoricalFeeds(twapFeedIDs, timestampToCheck);

                uint256 twapLen;

                if (strictMode) {
                    require(totals[0] != 0 && totals[totals.length-1] != 0, "Strict Mode: no 0 values for first and last element");
                }

                for (uint t = 0; t < totals.length; t++){
                    if (totals[t] != 0) {
                        twapTotal += totals[t];
                        twapLen += 1;
                    }
                }

                if (twapLen > 0) {
                    TWAP[c] = twapTotal / twapLen;
                } else {
                    TWAP[c] = 0;
                }
            }

            return (TWAP);
    }

    function lastTWAP(IOpenOracleFramework OOFContract, uint256[] memory feedIDs, uint256[] memory timeWindows) external view returns (uint256[] memory TWAP) {

        TWAP = new uint256[](feedIDs.length);
        uint256[] memory timeslot = new uint256[](feedIDs.length);

        (,,timeslot,,) = OOFContract.getFeedList(feedIDs);

        for (uint c = 0; c < feedIDs.length; c++) {
            uint256 timestampfinish = block.timestamp;
            uint256 timestampstart = timestampfinish - timeWindows[c];

            uint256 twapCount = timestampfinish / timeslot[c] - timestampstart / timeslot[c] + 1;
            uint256[] memory twapFeedIDs = new uint256[](twapCount);
            uint256[] memory timestampToCheck = new uint256[](twapCount);
            uint256 twapTotal;

            uint256[] memory totals = new uint256[](twapCount);

            for (uint s = 0; s < twapCount; s++) {
                timestampToCheck[s] = timestampstart + s * timeslot[c];
                twapFeedIDs[s] = feedIDs[c];
            }

            totals = OOFContract.getHistoricalFeeds(twapFeedIDs, timestampToCheck);

            uint256 twapLen;

            for (uint t = 0; t < totals.length; t++){
                if (totals[t] != 0) {
                    twapTotal += totals[t];
                    twapLen += 1;
                }
            }

            if (twapLen > 0) {
                uint256 feedValue;
                (feedValue,,) = OOFContract.getFeed(feedIDs[c]);
                TWAP[c] = (twapTotal + feedValue) / (twapLen + 1);
            } else {
                TWAP[c] = 0;
            }
        }

        return (TWAP);
    }
}

File 2 of 2 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": false,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"contract IOpenOracleFramework","name":"OOFContract","type":"address"},{"internalType":"uint256[]","name":"feedIDs","type":"uint256[]"},{"internalType":"uint256[]","name":"timestampstart","type":"uint256[]"},{"internalType":"uint256[]","name":"timestampfinish","type":"uint256[]"},{"internalType":"bool","name":"strictMode","type":"bool"}],"name":"getTWAP","outputs":[{"internalType":"uint256[]","name":"TWAP","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IOpenOracleFramework","name":"OOFContract","type":"address"},{"internalType":"uint256[]","name":"feedIDs","type":"uint256[]"},{"internalType":"uint256[]","name":"timeWindows","type":"uint256[]"}],"name":"lastTWAP","outputs":[{"internalType":"uint256[]","name":"TWAP","type":"uint256[]"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b506113f8806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806326c88bff1461003b578063d68563e61461006b575b600080fd5b61005560048036038101906100509190610e70565b61009b565b6040516100629190611137565b60405180910390f35b61008560048036038101906100809190610eef565b610594565b6040516100929190611137565b60405180910390f35b6060825167ffffffffffffffff811180156100b557600080fd5b506040519080825280602002602001820160405280156100e45781602001602082028036833780820191505090505b5090506000835167ffffffffffffffff8111801561010157600080fd5b506040519080825280602002602001820160405280156101305781602001602082028036833780820191505090505b5090508473ffffffffffffffffffffffffffffffffffffffff1663d69d117c856040518263ffffffff1660e01b815260040161016c9190611137565b60006040518083038186803b15801561018457600080fd5b505afa158015610198573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906101c19190610d40565b9091929350909192509050508091505060005b845181101561058b57600042905060008583815181106101f057fe5b6020026020010151820390506000600185858151811061020c57fe5b6020026020010151838161021c57fe5b0486868151811061022957fe5b6020026020010151858161023957fe5b040301905060008167ffffffffffffffff8111801561025757600080fd5b506040519080825280602002602001820160405280156102865781602001602082028036833780820191505090505b50905060008267ffffffffffffffff811180156102a257600080fd5b506040519080825280602002602001820160405280156102d15781602001602082028036833780820191505090505b5090506000808467ffffffffffffffff811180156102ee57600080fd5b5060405190808252806020026020018201604052801561031d5781602001602082028036833780820191505090505b50905060005b858110156103945789898151811061033757fe5b60200260200101518102870184828151811061034f57fe5b6020026020010181815250508c898151811061036757fe5b602002602001015185828151811061037b57fe5b6020026020010181815250508080600101915050610323565b508c73ffffffffffffffffffffffffffffffffffffffff166384f3c58585856040518363ffffffff1660e01b81526004016103d0929190611159565b60006040518083038186803b1580156103e857600080fd5b505afa1580156103fc573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906104259190610e2f565b9050600080600090505b825181101561047f57600083828151811061044657fe5b6020026020010151146104725782818151811061045f57fe5b6020026020010151840193506001820191505b808060010191505061042f565b50600081111561055b5760008e73ffffffffffffffffffffffffffffffffffffffff1663ecb76d908f8c815181106104b357fe5b60200260200101516040518263ffffffff1660e01b81526004016104d791906111d0565b60606040518083038186803b1580156104ef57600080fd5b505afa158015610503573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105279190610fae565b90505080915050600182018185018161053c57fe5b048c8b8151811061054957fe5b60200260200101818152505050610576565b60008b8a8151811061056957fe5b6020026020010181815250505b505050505050505080806001019150506101d4565b50509392505050565b60606000855190508067ffffffffffffffff811180156105b357600080fd5b506040519080825280602002602001820160405280156105e25781602001602082028036833780820191505090505b50915060008167ffffffffffffffff811180156105fe57600080fd5b5060405190808252806020026020018201604052801561062d5781602001602082028036833780820191505090505b50905085518751148015610642575084518751145b610681576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610678906111b0565b60405180910390fd5b8773ffffffffffffffffffffffffffffffffffffffff1663d69d117c886040518263ffffffff1660e01b81526004016106ba9190611137565b60006040518083038186803b1580156106d257600080fd5b505afa1580156106e6573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061070f9190610d40565b9091929350909192509050508091505060005b82811015610ac5576000600183838151811061073a57fe5b602002602001015189848151811061074e57fe5b60200260200101518161075d57fe5b0484848151811061076a57fe5b602002602001015189858151811061077e57fe5b60200260200101518161078d57fe5b040301905060008167ffffffffffffffff811180156107ab57600080fd5b506040519080825280602002602001820160405280156107da5781602001602082028036833780820191505090505b50905060008267ffffffffffffffff811180156107f657600080fd5b506040519080825280602002602001820160405280156108255781602001602082028036833780820191505090505b5090506000808467ffffffffffffffff8111801561084257600080fd5b506040519080825280602002602001820160405280156108715781602001602082028036833780820191505090505b50905060005b858110156108fb5787878151811061088b57fe5b602002602001015181028d88815181106108a157fe5b6020026020010151018482815181106108b657fe5b6020026020010181815250508d87815181106108ce57fe5b60200260200101518582815181106108e257fe5b6020026020010181815250508080600101915050610877565b508d73ffffffffffffffffffffffffffffffffffffffff166384f3c58585856040518363ffffffff1660e01b8152600401610937929190611159565b60006040518083038186803b15801561094f57600080fd5b505afa158015610963573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061098c9190610e2f565b905060008a15610a13576000826000815181106109a557fe5b6020026020010151141580156109d357506000826001845103815181106109c857fe5b602002602001015114155b610a12576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0990611190565b60405180910390fd5b5b60005b8251811015610a66576000838281518110610a2d57fe5b602002602001015114610a5957828181518110610a4657fe5b6020026020010151840193506001820191505b8080600101915050610a16565b506000811115610a9757808381610a7957fe5b048a8881518110610a8657fe5b602002602001018181525050610ab2565b60008a8881518110610aa557fe5b6020026020010181815250505b5050505050508080600101915050610722565b50505095945050505050565b6000610ae4610adf8461121c565b6111eb565b9050808382526020820190508260005b85811015610b245781518501610b0a8882610cec565b845260208401935060208301925050600181019050610af4565b5050509392505050565b6000610b41610b3c84611248565b6111eb565b90508083825260208201905082856020860282011115610b6057600080fd5b60005b85811015610b905781610b768882610d16565b845260208401935060208301925050600181019050610b63565b5050509392505050565b6000610bad610ba884611248565b6111eb565b90508083825260208201905082856020860282011115610bcc57600080fd5b60005b85811015610bfc5781610be28882610d2b565b845260208401935060208301925050600181019050610bcf565b5050509392505050565b6000610c19610c1484611274565b6111eb565b905082815260208101848484011115610c3157600080fd5b610c3c848285611348565b509392505050565b600082601f830112610c5557600080fd5b8151610c65848260208601610ad1565b91505092915050565b600082601f830112610c7f57600080fd5b8135610c8f848260208601610b2e565b91505092915050565b600082601f830112610ca957600080fd5b8151610cb9848260208601610b9a565b91505092915050565b600081359050610cd18161137d565b92915050565b600081359050610ce681611394565b92915050565b600082601f830112610cfd57600080fd5b8151610d0d848260208601610c06565b91505092915050565b600081359050610d25816113ab565b92915050565b600081519050610d3a816113ab565b92915050565b600080600080600060a08688031215610d5857600080fd5b600086015167ffffffffffffffff811115610d7257600080fd5b610d7e88828901610c44565b955050602086015167ffffffffffffffff811115610d9b57600080fd5b610da788828901610c98565b945050604086015167ffffffffffffffff811115610dc457600080fd5b610dd088828901610c98565b935050606086015167ffffffffffffffff811115610ded57600080fd5b610df988828901610c98565b925050608086015167ffffffffffffffff811115610e1657600080fd5b610e2288828901610c98565b9150509295509295909350565b600060208284031215610e4157600080fd5b600082015167ffffffffffffffff811115610e5b57600080fd5b610e6784828501610c98565b91505092915050565b600080600060608486031215610e8557600080fd5b6000610e9386828701610cd7565b935050602084013567ffffffffffffffff811115610eb057600080fd5b610ebc86828701610c6e565b925050604084013567ffffffffffffffff811115610ed957600080fd5b610ee586828701610c6e565b9150509250925092565b600080600080600060a08688031215610f0757600080fd5b6000610f1588828901610cd7565b955050602086013567ffffffffffffffff811115610f3257600080fd5b610f3e88828901610c6e565b945050604086013567ffffffffffffffff811115610f5b57600080fd5b610f6788828901610c6e565b935050606086013567ffffffffffffffff811115610f8457600080fd5b610f9088828901610c6e565b9250506080610fa188828901610cc2565b9150509295509295909350565b600080600060608486031215610fc357600080fd5b6000610fd186828701610d2b565b9350506020610fe286828701610d2b565b9250506040610ff386828701610d2b565b9150509250925092565b60006110098383611119565b60208301905092915050565b6000611020826112b4565b61102a81856112cc565b9350611035836112a4565b8060005b8381101561106657815161104d8882610ffd565b9750611058836112bf565b925050600181019050611039565b5085935050505092915050565b60006110806033836112dd565b91507f537472696374204d6f64653a206e6f20302076616c75657320666f722066697260008301527f737420616e64206c61737420656c656d656e74000000000000000000000000006020830152604082019050919050565b60006110e6601f836112dd565b91507f466565647320616e642054696d657374616d7073206d757374206d61746368006000830152602082019050919050565b6111228161133e565b82525050565b6111318161133e565b82525050565b600060208201905081810360008301526111518184611015565b905092915050565b600060408201905081810360008301526111738185611015565b905081810360208301526111878184611015565b90509392505050565b600060208201905081810360008301526111a981611073565b9050919050565b600060208201905081810360008301526111c9816110d9565b9050919050565b60006020820190506111e56000830184611128565b92915050565b6000604051905081810181811067ffffffffffffffff821117156112125761121161137b565b5b8060405250919050565b600067ffffffffffffffff8211156112375761123661137b565b5b602082029050602081019050919050565b600067ffffffffffffffff8211156112635761126261137b565b5b602082029050602081019050919050565b600067ffffffffffffffff82111561128f5761128e61137b565b5b601f19601f8301169050602081019050919050565b6000819050602082019050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b60006112f98261131e565b9050919050565b60008115159050919050565b6000611317826112ee565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b8381101561136657808201518184015260208101905061134b565b83811115611375576000848401525b50505050565bfe5b61138681611300565b811461139157600080fd5b50565b61139d8161130c565b81146113a857600080fd5b50565b6113b48161133e565b81146113bf57600080fd5b5056fea26469706673582212205c34f5a5cc56d4a95eb82645259256592fcfb9a6df5a904581f80d46c7b7adc964736f6c63430007060033

Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading

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.