Contract 0xE01e50E970AcA3FAE1e955c359190Cda989921F3 11

 

Contract Overview

Balance:
0 ETH

ETH Value:
$0.00

Token:
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xdca8647a4393e5eab911cd37c94f15b579234d2ccc6e8418eeac8ae8a0743da2Perform Upkeep1820025072024-02-18 12:51:503 days 1 hr ago0x292f08a2ea12d1e57446ef4690284972be25ec85 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00009029 0.1
0xcb7942b28eebeca03b04042e5a0b50308929c65541e633f038ede0f057c73f8eCreate Order1819998172024-02-18 12:40:363 days 1 hr ago0xff10bda1d2626a780123d86b0012e30da2205b7c IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.000127960.1
0x5e3c5c5818c755eb80b74790c8a9dd462935cd92bdcb71dcf3aa33289d3aa3d8Remove Order1814702112024-02-16 22:20:444 days 16 hrs ago0x2134635a9fe88fa5a880152dda5011f5d2f0a672 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00004972 0.1
0xb4f90765bbb79ec6abe75792f70992a5747ab445c7ae7e711083c9516afdf926Create Order1806600682024-02-14 12:12:147 days 2 hrs ago0x2134635a9fe88fa5a880152dda5011f5d2f0a672 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00014265 0.1
0xe07e5ab855b5082ba0534be404c41fdfe3abb571d3ce79b72de6f75f6a655a0bRemove Order1798032362024-02-11 22:54:439 days 15 hrs ago0x7e0cb28572a0b3a7f5132382726337758dc4a655 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00008559 0.1
0xdca2e1fdbfa9f4694666805ad6adc743d19f85c50a64802f29c77db95a28602cCreate Order1794739572024-02-10 23:18:4010 days 15 hrs ago0x7e0cb28572a0b3a7f5132382726337758dc4a655 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00017429 0.1
0x532e59fffe0072a0fb88d958fe80b41a33966bbe21be20d30b12dc16de84793aRemove Order1793700182024-02-10 15:45:1610 days 22 hrs ago0xf8cd55ab4f606d0a8fd105386016bbef55ca4705 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00006154 0.1
0x6d6e547a457f71988387c84086ea87e5b1356bd44961b76f772be912a7f490adRemove Order1793695912024-02-10 15:43:2410 days 22 hrs ago0xf8cd55ab4f606d0a8fd105386016bbef55ca4705 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00006155 0.1
0xe6b3d06a521e56ca23f61aa6344683fd082eae8ffdee622ce786ac5064d0c4bdCreate Order1793677952024-02-10 15:35:4610 days 22 hrs ago0xf8cd55ab4f606d0a8fd105386016bbef55ca4705 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00014904 0.1
0xb5853b29d2c8f95aa929f3e7a5e60529e5a4aba4c80a038643156a38f1b96115Create Order1793655172024-02-10 15:25:5610 days 22 hrs ago0xf8cd55ab4f606d0a8fd105386016bbef55ca4705 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00014464 0.1
0xcb8c0895a84e500b53df58c1dc4382aed24ebba478ee5c03cebc6eeaa1b12055Remove Order1793639142024-02-10 15:19:0710 days 23 hrs ago0xf8cd55ab4f606d0a8fd105386016bbef55ca4705 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00006713 0.1
0xa4b8fbe1b963999479a0f54e1966053018a77378fa82591ec49948d113638a7aCreate Order1793573642024-02-10 14:51:0210 days 23 hrs ago0xf8cd55ab4f606d0a8fd105386016bbef55ca4705 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00013764 0.1
0x5f4db5de9c56733aac0a765fc5c319a4e5f9c3fe27a72388882f6ad7e9e32d86Remove Order1786876952024-02-08 13:25:1213 days 59 mins ago0xe1bcaae68afc90d99bd28ed03f05810bc27d6323 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00012239 0.1
0x7b1a8d923728ed8be195b520943ec775192fc14ce4ba7fb322f7f7f3a55d9603Create Order1785614452024-02-08 4:19:4613 days 10 hrs ago0xe1bcaae68afc90d99bd28ed03f05810bc27d6323 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00014064 0.1
0x0014e4ce470895b756158d6cdcf24682610267d423402d771b4ef67fa179e9faPerform Upkeep1776672882024-02-05 11:32:2616 days 2 hrs ago0x292f08a2ea12d1e57446ef4690284972be25ec85 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00006638 0.1
0xf15825c15148c5d0bca7666fdb2073b42beedf8de2bd8f0624afb725980fe98dCreate Order1776484832024-02-05 10:11:3616 days 4 hrs ago0x2134635a9fe88fa5a880152dda5011f5d2f0a672 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00009281 0.1
0xdc38f95721441c9e5845ecb0890d5bea597e0cb9f6ceb82dc4852af60a2839e1Perform Upkeep1776087892024-02-05 7:21:5416 days 7 hrs ago0x292f08a2ea12d1e57446ef4690284972be25ec85 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00006018 0.1
0xbd362e68c240cfe056022270630bd5b78e218d764b1057030d4b05335dd2e22bCreate Order1775553022024-02-05 3:27:1916 days 10 hrs ago0xe1bcaae68afc90d99bd28ed03f05810bc27d6323 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00007715 0.1
0xe42fdc93f56b65bf964f5bea9f72c03d6e028d6b941e5ae79662cbc90753302dRemove Order1763084442024-02-01 6:56:3620 days 7 hrs ago0x2134635a9fe88fa5a880152dda5011f5d2f0a672 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00003888 0.1
0x716ea4c38806b9a5d435e06b7e8825645b9bfd89adaa6248e030b9ac7e57a846Remove Order1762365472024-02-01 1:43:2220 days 12 hrs ago0xe1bcaae68afc90d99bd28ed03f05810bc27d6323 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00004973 0.1
0x4322515bf801ba8cf2930f868adea7496066d2abe817a395f45f168567b984d6Create Order1761783942024-01-31 21:28:0320 days 16 hrs ago0xe1bcaae68afc90d99bd28ed03f05810bc27d6323 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00011969 0.1
0x74a40322c57c712bb446aea6ff98e5f63df1c604e1433bd22e5b12714527b8a4Remove Order1761596602024-01-31 20:08:1020 days 18 hrs ago0x7e0cb28572a0b3a7f5132382726337758dc4a655 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00005396 0.1
0xbf37503f5fd15c6ffe2eae6d36f63e9c4645985f67e8e32827ac18fc55fba814Create Order1761490312024-01-31 19:22:4720 days 19 hrs ago0x7e0cb28572a0b3a7f5132382726337758dc4a655 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00011078 0.1
0x9440944fccfb773ddb5319e1c4df95d3d02709b10e387b21b64c643def076245Create Order1759707442024-01-31 6:43:0721 days 7 hrs ago0x2134635a9fe88fa5a880152dda5011f5d2f0a672 IN  0xe01e50e970aca3fae1e955c359190cda989921f30.002 ETH0.00010061 0.1
0x3b1edea3448839131a682905e2e44b86b8927e4fdc34aa1c01865b439a7c7cc7Perform Upkeep1757798842024-01-30 16:48:2521 days 21 hrs ago0x292f08a2ea12d1e57446ef4690284972be25ec85 IN  0xe01e50e970aca3fae1e955c359190cda989921f30 ETH0.00021384 0.1
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0xcb7942b28eebeca03b04042e5a0b50308929c65541e633f038ede0f057c73f8e1819998172024-02-18 12:40:363 days 1 hr ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xb4f90765bbb79ec6abe75792f70992a5747ab445c7ae7e711083c9516afdf9261806600682024-02-14 12:12:147 days 2 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xdca2e1fdbfa9f4694666805ad6adc743d19f85c50a64802f29c77db95a28602c1794739572024-02-10 23:18:4010 days 15 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xe6b3d06a521e56ca23f61aa6344683fd082eae8ffdee622ce786ac5064d0c4bd1793677952024-02-10 15:35:4610 days 22 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xb5853b29d2c8f95aa929f3e7a5e60529e5a4aba4c80a038643156a38f1b961151793655172024-02-10 15:25:5610 days 22 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xa4b8fbe1b963999479a0f54e1966053018a77378fa82591ec49948d113638a7a1793573642024-02-10 14:51:0210 days 23 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x7b1a8d923728ed8be195b520943ec775192fc14ce4ba7fb322f7f7f3a55d96031785614452024-02-08 4:19:4613 days 10 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xf15825c15148c5d0bca7666fdb2073b42beedf8de2bd8f0624afb725980fe98d1776484832024-02-05 10:11:3616 days 4 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xbd362e68c240cfe056022270630bd5b78e218d764b1057030d4b05335dd2e22b1775553022024-02-05 3:27:1916 days 10 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x4322515bf801ba8cf2930f868adea7496066d2abe817a395f45f168567b984d61761783942024-01-31 21:28:0320 days 16 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xbf37503f5fd15c6ffe2eae6d36f63e9c4645985f67e8e32827ac18fc55fba8141761490312024-01-31 19:22:4720 days 19 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x9440944fccfb773ddb5319e1c4df95d3d02709b10e387b21b64c643def0762451759707442024-01-31 6:43:0721 days 7 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x6e57258e30471c8e0122690556217ede519341eb7108d87489adc323faecfeb91757789432024-01-30 16:44:2221 days 21 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x6072477b35f98676be84ba2978d20ab85ccf0027d35569004f6678e627173f9e1757271772024-01-30 13:04:5622 days 1 hr ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x0ef50de2058a69929029fe62d2bcfb4d37a86b32039c7e92d81a43878120fc3a1747030252024-01-27 12:20:3425 days 2 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xd886dc15b5b36249801b0a9389555ba02b7105e2a292fb60257c61a9917ad2ee1746520432024-01-27 8:39:3125 days 5 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x44c3857e150c619a10e0a33e7d7a00813c4ffba2a645d594d59fee5667bf7a741745610742024-01-27 2:02:2325 days 12 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xfbf4d7ac6bd07c24f60a18791a0cf791a52a9bb922b10c3b433db682c3e394ae1744938782024-01-26 21:14:4925 days 17 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x12a656ff053dbbdf5f7d2d3c3566b5dcf38ac5bcf17e94070a4e2162a223f4e21742673322024-01-26 5:07:3826 days 9 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x3ba320fb08bd200140d0094c17ac825fceecccb1a43727d5737c7e8f640807dc1742582392024-01-26 4:29:3826 days 9 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x323e45f464f072d0326627226f283eb56ee2319857a205d70eac92a164844c7b1742414762024-01-26 3:16:0726 days 11 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xa831e2d5df478e86a3185048d21b451de9351e0c44c5b2c4eb6dcb60c79230721742411652024-01-26 3:14:4526 days 11 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xac99aa4a67b46b8c49d7fb555f1fd25fc160b6728bdd1d035b6b7905fc0805601737599652024-01-24 17:01:1227 days 21 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0xb0fe75c651ed5a229c9f98931536aa41c9971cb87b784b58d6f5e838c5e8b33c1721386132024-01-19 21:49:3932 days 16 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
0x56599a0e079bc9beefd367e43ebf1e6e74e76360afec1d5eee02112588ea47f21717538952024-01-18 18:00:1633 days 20 hrs ago 0xe01e50e970aca3fae1e955c359190cda989921f3Yieldification: Deployer0.002 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
PerpetualFuturesLimitOrders

Compiler Version
v0.8.16+commit.07a7930e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 11 : PerpetualFuturesLimitOrders.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import './interfaces/IPerpetualFutures.sol';

contract PerpetualFuturesLimitOrders is Ownable, ReentrancyGuard {
  using SafeERC20 for IERC20;

  IPerpetualFutures public perps;
  bool public enabled = true;
  uint256 public openServiceFee = 2 ether / 1000; // 0.002 ETH

  struct LimitOrder {
    bytes32 uid;
    uint256 openFeePaid;
    IPerpetualFutures.ActionRequest positionInfo;
  }

  mapping(bytes32 => address) _openOrderUIDs;
  LimitOrder[] public openOrders;

  event CreateLimitOrder(
    address indexed requestor,
    address indexed owner,
    address collateralToken,
    uint256 collateralAmount,
    uint256 indexIdx,
    uint256 desiredPrice,
    uint16 leverage,
    bool isLong
  );
  event CancelLimitOrder(
    address indexed owner,
    address collateralToken,
    uint256 collateralAmount,
    uint256 indexIdx,
    uint256 desiredPrice,
    uint16 leverage,
    bool isLong
  );
  event ProcessLimitOrder(
    address indexed owner,
    address collateralToken,
    uint256 collateralAmount,
    uint256 indexIdx,
    uint256 executedPrice,
    uint16 leverage,
    bool isLong
  );

  modifier onlyRelay() {
    require(perps.relays(msg.sender), 'RELAY: unauthorized');
    _;
  }

  constructor(IPerpetualFutures _perps) {
    perps = _perps;
  }

  function getOpenOrdersLength() external view returns (uint256) {
    return openOrders.length;
  }

  function getAllOpenOrders() external view returns (LimitOrder[] memory) {
    return openOrders;
  }

  function createOrder(
    address _positionUser,
    address _collToken,
    uint256 _indexIdx,
    uint256 _desiredPrice,
    uint256 _collateral,
    uint16 _leverage,
    bool _isLong
  ) external payable nonReentrant {
    require(enabled, 'CREATE: enabled');
    uint256 _posOpenFee = perps.openFeeETH();
    require(msg.value == openServiceFee + _posOpenFee, 'CREATE: fee');
    if (openServiceFee > 0) {
      (bool _s, ) = payable(owner()).call{ value: openServiceFee }('');
      require(_s, 'FEESEND');
    }
    _positionUser = _positionUser == address(0) ? _msgSender() : _positionUser;

    IERC20(_collToken).safeTransferFrom(
      _msgSender(),
      address(this),
      _collateral
    );

    bytes32 _uid = _getOrderUID(
      _msgSender(),
      _collToken,
      _collateral,
      _indexIdx,
      _desiredPrice,
      _leverage,
      _isLong
    );
    require(_openOrderUIDs[_uid] == address(0), 'DUPORDER');
    _openOrderUIDs[_uid] = _positionUser;
    openOrders.push(
      LimitOrder({
        uid: _uid,
        openFeePaid: _posOpenFee,
        positionInfo: IPerpetualFutures.ActionRequest({
          timestamp: block.timestamp,
          requester: _msgSender(),
          indexIdx: _indexIdx,
          tokenId: 0,
          owner: _positionUser,
          collateralToken: _collToken,
          collateralAmount: _collateral,
          isLong: _isLong,
          leverage: _leverage,
          openSlippage: 50,
          desiredIdxPriceStart: _desiredPrice
        })
      })
    );

    emit CreateLimitOrder(
      _msgSender(),
      _positionUser,
      _collToken,
      _collateral,
      _indexIdx,
      _desiredPrice,
      _leverage,
      _isLong
    );
  }

  function removeOrder(uint256 _idx) external nonReentrant {
    LimitOrder memory _order = openOrders[_idx];
    require(
      _msgSender() == _order.positionInfo.owner || _msgSender() == owner(),
      'REMOVE: auth'
    );
    if (_order.openFeePaid > 0) {
      (bool _s, ) = payable(_order.positionInfo.owner).call{
        value: _order.openFeePaid
      }('');
      require(_s, 'FEEREFUND');
    }
    bytes32 _uid = _getOrderUID(
      _order.positionInfo.owner,
      _order.positionInfo.collateralToken,
      _order.positionInfo.collateralAmount,
      _order.positionInfo.indexIdx,
      _order.positionInfo.desiredIdxPriceStart,
      _order.positionInfo.leverage,
      _order.positionInfo.isLong
    );
    delete _openOrderUIDs[_uid];
    IERC20(_order.positionInfo.collateralToken).safeTransfer(
      _order.positionInfo.owner,
      _order.positionInfo.collateralAmount
    );
    _removeOpenOrder(_idx);

    emit CancelLimitOrder(
      _order.positionInfo.owner,
      _order.positionInfo.collateralToken,
      _order.positionInfo.collateralAmount,
      _order.positionInfo.indexIdx,
      _order.positionInfo.desiredIdxPriceStart,
      _order.positionInfo.leverage,
      _order.positionInfo.isLong
    );
  }

  function _removeOpenOrder(uint256 _idx) internal {
    openOrders[_idx] = openOrders[openOrders.length - 1];
    openOrders.pop();
  }

  function _processOpenOrder(uint256 _idx, uint256 _currentPrice) internal {
    LimitOrder memory _order = openOrders[_idx];
    bool _shouldOpen = _shouldOpenOrder(_idx, _currentPrice);
    if (!_shouldOpen) {
      return;
    }

    IERC20(_order.positionInfo.collateralToken).safeApprove(
      address(perps),
      _order.positionInfo.collateralAmount
    );
    perps.openPositionRequest{ value: perps.openFeeETH() }(
      _order.positionInfo.collateralToken,
      _order.positionInfo.indexIdx,
      _currentPrice,
      _order.positionInfo.openSlippage,
      _order.positionInfo.collateralAmount,
      _order.positionInfo.leverage,
      _order.positionInfo.isLong,
      0,
      _order.positionInfo.owner
    );

    _removeOpenOrder(_idx);

    emit ProcessLimitOrder(
      _order.positionInfo.owner,
      _order.positionInfo.collateralToken,
      _order.positionInfo.collateralAmount,
      _order.positionInfo.indexIdx,
      _currentPrice,
      _order.positionInfo.leverage,
      _order.positionInfo.isLong
    );
  }

  function _shouldOpenOrder(uint256 _openOrderIdx, uint256 _currentPrice)
    internal
    view
    returns (bool)
  {
    LimitOrder memory _order = openOrders[_openOrderIdx];
    if (_order.positionInfo.isLong) {
      if (_currentPrice > _order.positionInfo.desiredIdxPriceStart) {
        return false;
      }
    } else {
      if (_currentPrice < _order.positionInfo.desiredIdxPriceStart) {
        return false;
      }
    }
    return true;
  }

  function _getOrderUID(
    address _owner,
    address _collateralToken,
    uint256 _collateralAmount,
    uint256 _indexIdx,
    uint256 _indexMarkPrice,
    uint16 _leverage,
    bool _isLong
  ) internal pure returns (bytes32) {
    return
      keccak256(
        abi.encodePacked(
          _owner,
          _collateralToken,
          _collateralAmount,
          _indexIdx,
          _indexMarkPrice,
          _leverage,
          _isLong
        )
      );
  }

  function checkUpkeep(uint256 _openOrderIdx, uint256 _currentPrice)
    external
    view
    returns (bool upkeepNeeded)
  {
    if (!enabled) {
      return false;
    }
    return _shouldOpenOrder(_openOrderIdx, _currentPrice);
  }

  function performUpkeep(uint256 _openOrderIdx, uint256 _currentPrice)
    external
    onlyRelay
  {
    require(enabled, 'ENABLED');
    if (!_shouldOpenOrder(_openOrderIdx, _currentPrice)) {
      return;
    }
    _processOpenOrder(_openOrderIdx, _currentPrice);
  }

  function setEnabled(bool _isEnabled) external onlyOwner {
    require(enabled != _isEnabled, 'ENABLE: toggle');
    enabled = _isEnabled;
  }

  function setOpenServiceFee(uint256 _wei) external onlyOwner {
    openServiceFee = _wei;
  }

  function withdrawERC20(IERC20 _token, uint256 _amount) external onlyOwner {
    _amount = _amount == 0 ? _token.balanceOf(address(this)) : _amount;
    _token.safeTransfer(owner(), _amount);
  }

  function withdrawETH(uint256 _amount) external onlyOwner {
    _amount = _amount == 0 ? address(this).balance : _amount;
    (bool _sent, ) = payable(owner()).call{ value: _amount }('');
    require(_sent, 'WITHDRAW');
  }
}

File 2 of 11 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/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.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

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

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 3 of 11 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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 4 of 11 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 5 of 11 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 6 of 11 : IPerpetualFutures.sol
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

interface IPerpetualFutures {
  struct Index {
    string name;
    uint256 dowOpenMin;
    uint256 dowOpenMax;
    uint256 hourOpenMin;
    uint256 hourOpenMax;
    bool isActive;
  }

  struct PositionLifecycle {
    uint256 openTime;
    uint256 openFees;
    uint256 closeTime;
    uint256 closeFees;
    uint256 settleCollPriceUSD; // For positions with alternate collateral, USD per collateral token extended to 18 decimals
    uint256 settleMainPriceUSD; // For positions with alternate collateral, USD per main token extended to 18 decimals
  }

  struct Position {
    PositionLifecycle lifecycle;
    uint256 indexIdx;
    address collateralToken;
    uint256 collateralAmount;
    bool isLong;
    uint16 leverage;
    uint256 indexPriceStart;
    uint256 indexPriceSettle;
    uint256 amountWon;
    uint256 amountLost;
    bool isSettled;
    uint256 mainCollateralSettledAmount;
  }

  struct ActionRequest {
    uint256 timestamp;
    address requester;
    uint256 indexIdx;
    uint256 tokenId;
    address owner;
    address collateralToken;
    uint256 collateralAmount;
    bool isLong;
    uint16 leverage;
    uint256 openSlippage;
    uint256 desiredIdxPriceStart;
  }

  function openFeeETH() external view returns (uint256);

  function mainCollateralToken() external view returns (address);

  function relays(address wallet) external view returns (bool);

  function perpsNft() external view returns (IERC721);

  function positions(uint256 tokenId) external view returns (Position memory);

  function openPositionRequest(
    address collateralToken,
    uint256 indexInd,
    uint256 desiredPrice,
    uint256 slippage,
    uint256 collateral,
    uint16 leverage,
    bool isLong,
    uint256 tokenId, // optional: if adding margin
    address owner // optional: if opening for another wallet
  ) external payable;

  function executeSettlement(
    uint256 tokenId,
    address to,
    uint256 amount
  ) external;
}

File 7 of 11 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.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 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.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 8 of 11 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 9 of 11 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal 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
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 10 of 11 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 11 of 11 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Settings
{
  "metadata": {
    "bytecodeHash": "none"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract ABI

[{"inputs":[{"internalType":"contract IPerpetualFutures","name":"_perps","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"indexIdx","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"desiredPrice","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"leverage","type":"uint16"},{"indexed":false,"internalType":"bool","name":"isLong","type":"bool"}],"name":"CancelLimitOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"requestor","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"indexIdx","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"desiredPrice","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"leverage","type":"uint16"},{"indexed":false,"internalType":"bool","name":"isLong","type":"bool"}],"name":"CreateLimitOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"indexIdx","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"executedPrice","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"leverage","type":"uint16"},{"indexed":false,"internalType":"bool","name":"isLong","type":"bool"}],"name":"ProcessLimitOrder","type":"event"},{"inputs":[{"internalType":"uint256","name":"_openOrderIdx","type":"uint256"},{"internalType":"uint256","name":"_currentPrice","type":"uint256"}],"name":"checkUpkeep","outputs":[{"internalType":"bool","name":"upkeepNeeded","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_positionUser","type":"address"},{"internalType":"address","name":"_collToken","type":"address"},{"internalType":"uint256","name":"_indexIdx","type":"uint256"},{"internalType":"uint256","name":"_desiredPrice","type":"uint256"},{"internalType":"uint256","name":"_collateral","type":"uint256"},{"internalType":"uint16","name":"_leverage","type":"uint16"},{"internalType":"bool","name":"_isLong","type":"bool"}],"name":"createOrder","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"enabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllOpenOrders","outputs":[{"components":[{"internalType":"bytes32","name":"uid","type":"bytes32"},{"internalType":"uint256","name":"openFeePaid","type":"uint256"},{"components":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"address","name":"requester","type":"address"},{"internalType":"uint256","name":"indexIdx","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"uint16","name":"leverage","type":"uint16"},{"internalType":"uint256","name":"openSlippage","type":"uint256"},{"internalType":"uint256","name":"desiredIdxPriceStart","type":"uint256"}],"internalType":"struct IPerpetualFutures.ActionRequest","name":"positionInfo","type":"tuple"}],"internalType":"struct PerpetualFuturesLimitOrders.LimitOrder[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOpenOrdersLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"openOrders","outputs":[{"internalType":"bytes32","name":"uid","type":"bytes32"},{"internalType":"uint256","name":"openFeePaid","type":"uint256"},{"components":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"address","name":"requester","type":"address"},{"internalType":"uint256","name":"indexIdx","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"uint16","name":"leverage","type":"uint16"},{"internalType":"uint256","name":"openSlippage","type":"uint256"},{"internalType":"uint256","name":"desiredIdxPriceStart","type":"uint256"}],"internalType":"struct IPerpetualFutures.ActionRequest","name":"positionInfo","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"openServiceFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_openOrderIdx","type":"uint256"},{"internalType":"uint256","name":"_currentPrice","type":"uint256"}],"name":"performUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"perps","outputs":[{"internalType":"contract IPerpetualFutures","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"removeOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_isEnabled","type":"bool"}],"name":"setEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_wei","type":"uint256"}],"name":"setOpenServiceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040526002805460ff60a01b1916600160a01b17905566071afd498d00006003553480156200002f57600080fd5b50604051620020d3380380620020d38339810160408190526200005291620000d7565b6200005d3362000087565b60018055600280546001600160a01b0319166001600160a01b039290921691909117905562000109565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600060208284031215620000ea57600080fd5b81516001600160a01b03811681146200010257600080fd5b9392505050565b611fba80620001196000396000f3fe6080604052600436106100fe5760003560e01c80638da5cb5b11610095578063a2e641b611610064578063a2e641b6146102a5578063af2b0ce9146102bb578063e8bd883f146102db578063f14210a6146102fb578063f2fde38b1461031b57600080fd5b80638da5cb5b146102205780639645337a146102525780639de8528f14610272578063a1db97821461028557600080fd5b8063447c1e8c116100d1578063447c1e8c1461019a57806356952b1a146101c95780635bd1bcfa146101e9578063715018a61461020b57600080fd5b8063018c1d611461010357806315b0e94b14610125578063238dafe014610149578063328d8f721461017a575b600080fd5b34801561010f57600080fd5b5061012361011e366004611bf0565b61033b565b005b34801561013157600080fd5b506005545b6040519081526020015b60405180910390f35b34801561015557600080fd5b5060025461016a90600160a01b900460ff1681565b6040519015158152602001610140565b34801561018657600080fd5b50610123610195366004611c17565b610348565b3480156101a657600080fd5b506101ba6101b5366004611bf0565b6103c6565b60405161014093929190611ce1565b3480156101d557600080fd5b506101236101e4366004611cfd565b61048c565b3480156101f557600080fd5b506101fe61059a565b6040516101409190611d1f565b34801561021757600080fd5b506101236106a0565b34801561022c57600080fd5b506000546001600160a01b03165b6040516001600160a01b039091168152602001610140565b34801561025e57600080fd5b5061012361026d366004611bf0565b6106b4565b610123610280366004611d98565b6109fc565b34801561029157600080fd5b506101236102a0366004611e1a565b610ef2565b3480156102b157600080fd5b5061013660035481565b3480156102c757600080fd5b5060025461023a906001600160a01b031681565b3480156102e757600080fd5b5061016a6102f6366004611cfd565b610f96565b34801561030757600080fd5b50610123610316366004611bf0565b610fc5565b34801561032757600080fd5b50610123610336366004611e46565b61107c565b6103436110f5565b600355565b6103506110f5565b801515600260149054906101000a900460ff161515036103a85760405162461bcd60e51b815260206004820152600e60248201526d454e41424c453a20746f67676c6560901b60448201526064015b60405180910390fd5b60028054911515600160a01b0260ff60a01b19909216919091179055565b600581815481106103d657600080fd5b6000918252602091829020600c909102018054600182015460408051610160810182526002850154815260038501546001600160a01b039081169682019690965260048501549181019190915260058401546060820152600684015485166080820152600784015490941660a0850152600883015460c0850152600983015460ff8116151560e086015261ffff610100918290041690850152600a830154610120850152600b9092015461014084015292509083565b60025460405163cb8d406f60e01b81523360048201526001600160a01b039091169063cb8d406f90602401602060405180830381865afa1580156104d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f89190611e63565b61053a5760405162461bcd60e51b815260206004820152601360248201527214915310564e881d5b985d5d1a1bdc9a5e9959606a1b604482015260640161039f565b600254600160a01b900460ff1661057d5760405162461bcd60e51b81526020600482015260076024820152661153905093115160ca1b604482015260640161039f565b610587828261114f565b1561059657610596828261127f565b5050565b60606005805480602002602001604051908101604052809291908181526020016000905b828210156106975760008481526020908190206040805160608082018352600c870290930180548252600180820154838701528351610160810185526002830154815260038301546001600160a01b0390811682890152600484015482870152600584015496820196909652600683015486166080820152600783015490951660a0860152600882015460c0860152600982015460ff8116151560e087015261ffff610100918290041690860152600a820154610120860152600b909101546101408501529181019290925290835290920191016105be565b50505050905090565b6106a86110f5565b6106b2600061154d565b565b6002600154036107065760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161039f565b600260018190555060006005828154811061072357610723611e80565b60009182526020918290206040805160608082018352600c909402909201805483526001810154838601528151610160810183526002820154815260038201546001600160a01b039081169682019690965260048201548184015260058201549481019490945260068101548516608085019081526007820154861660a0860152600882015460c0860152600982015460ff8116151560e087015261ffff610100918290041690860152600a820154610120860152600b90910154610140850152908201929092529051909250166107f83390565b6001600160a01b0316148061081757506000546001600160a01b031633145b6108525760405162461bcd60e51b815260206004820152600c60248201526b0a48a9a9eac8a7440c2eae8d60a31b604482015260640161039f565b6020810151156108f95760008160400151608001516001600160a01b0316826020015160405160006040518083038185875af1925050503d80600081146108b5576040519150601f19603f3d011682016040523d82523d6000602084013e6108ba565b606091505b50509050806108f75760405162461bcd60e51b815260206004820152600960248201526811915154915195539160ba1b604482015260640161039f565b505b604080820151608081015160a082015160c08301519383015161014084015161010085015160e090950151600096610934969093929161159d565b6000818152600460205260409081902080546001600160a01b0319169055830151608081015160c082015160a09092015192935061097b926001600160a01b031691611619565b61098483611681565b604080830151608081015160a082015160c08301518385015161014085015161010086015160e09096015196516001600160a01b03909516967f9dd03547985269c0c89b1f4555a48984ea8fd32be022413935be7f4bfaad571b966109eb96909190611e96565b60405180910390a250506001805550565b600260015403610a4e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161039f565b6002600181905554600160a01b900460ff16610a9e5760405162461bcd60e51b815260206004820152600f60248201526e10d4915055114e88195b98589b1959608a1b604482015260640161039f565b6002546040805163268a453760e21b815290516000926001600160a01b031691639a2914dc9160048083019260209291908290030181865afa158015610ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0c9190611ecf565b905080600354610b1c9190611efe565b3414610b585760405162461bcd60e51b815260206004820152600b60248201526a4352454154453a2066656560a81b604482015260640161039f565b60035415610bf057600080546003546040516001600160a01b03909216918381818185875af1925050503d8060008114610bae576040519150601f19603f3d011682016040523d82523d6000602084013e610bb3565b606091505b5050905080610bee5760405162461bcd60e51b815260206004820152600760248201526611915154d1539160ca1b604482015260640161039f565b505b6001600160a01b03881615610c055787610c07565b335b9750610c1e6001600160a01b038816333087611846565b6000610c2f3389878a8a898961159d565b6000818152600460205260409020549091506001600160a01b031615610c825760405162461bcd60e51b8152602060048201526008602482015267222aa827a92222a960c11b604482015260640161039f565b60008181526004602090815260409182902080546001600160a01b0319166001600160a01b038d1617905581516060810183528381528082018590528251610160810184524281526005939192918301918101336001600160a01b031681526020018b8152602001600081526020018d6001600160a01b031681526020018c6001600160a01b0316815260200189815260200187151581526020018861ffff168152602001603281526020018a81525081525090806001815401808255809150506001900390600052602060002090600c020160009091909190915060008201518160000155602082015181600101556040820151816002016000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550604082015181600201556060820151816003015560808201518160040160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060a08201518160050160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e08201518160070160006101000a81548160ff0219169083151502179055506101008201518160070160016101000a81548161ffff021916908361ffff1602179055506101208201518160080155610140820151816009015550505050886001600160a01b0316610e993390565b6001600160a01b03167f5ea8ccf2224c15b1e992aefc2413256588f558af4f5c7ec3657dc754f625780a8a888b8b8a8a604051610edb96959493929190611e96565b60405180910390a350506001805550505050505050565b610efa6110f5565b8015610f065780610f6e565b6040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015610f4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f6e9190611ecf565b9050610596610f856000546001600160a01b031690565b6001600160a01b0384169083611619565b600254600090600160a01b900460ff16610fb257506000610fbf565b610fbc838361114f565b90505b92915050565b610fcd6110f5565b8015610fd95780610fdb565b475b90506000610ff16000546001600160a01b031690565b6001600160a01b03168260405160006040518083038185875af1925050503d806000811461103b576040519150601f19603f3d011682016040523d82523d6000602084013e611040565b606091505b50509050806105965760405162461bcd60e51b8152602060048201526008602482015267574954484452415760c01b604482015260640161039f565b6110846110f5565b6001600160a01b0381166110e95760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161039f565b6110f28161154d565b50565b6000546001600160a01b031633146106b25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161039f565b6000806005848154811061116557611165611e80565b60009182526020918290206040805160608082018352600c909402909201805483526001810154838601528151610160810183526002820154815260038201546001600160a01b0390811696820196909652600482015481840152600582015494810194909452600681015485166080850152600781015490941660a0840152600884015460c0840152600984015460ff8116151560e0850190815261ffff610100928390041691850191909152600a850154610120850152600b9094015461014084015281019190915290519091501561125a5780604001516101400151831115611255576000915050610fbf565b611275565b80604001516101400151831015611275576000915050610fbf565b5060019392505050565b60006005838154811061129457611294611e80565b600091825260208083206040805160608082018352600c909502909201805483526001810154838501528151610160810183526002820154815260038201546001600160a01b0390811695820195909552600482015481840152600582015495810195909552600681015484166080860152600781015490931660a0850152600883015460c0850152600983015460ff8116151560e086015261ffff610100918290041690850152600a830154610120850152600b90920154610140840152908101919091529150611366848461114f565b9050806113735750505050565b600254604083015160c081015160a09091015161139e926001600160a01b0391821692911690611884565b6002546040805163268a453760e21b815290516001600160a01b039092169163cafc836a918391639a2914dc916004808201926020929091908290030181865afa1580156113f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114149190611ecf565b60408581015160a08101518183015161012083015160c084015161010085015160e0808701516080909701519751908a901b6001600160e01b03191681526001600160a01b0395861660048201526024810194909452604484018d90526064840192909252608483015261ffff1660a482015291151560c4830152600060e4830152909116610104820152610124016000604051808303818588803b1580156114bc57600080fd5b505af11580156114d0573d6000803e3d6000fd5b50505050506114de84611681565b604080830151608081015160a082015160c08301518385015161010085015160e09095015195516001600160a01b03909416957febc4df80406235377ac0be1a9b4cc83a2fe9cb4bc1fe63b8a6d904a6782729349561153f958b9290611e96565b60405180910390a250505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60408051606098891b6bffffffffffffffffffffffff199081166020808401919091529890991b909816603489015260488801959095526068870193909352608886019190915260f01b6001600160f01b03191660a8850152151560f81b60aa8401528051608b81850301815260ab9093019052815191012090565b6040516001600160a01b03831660248201526044810182905261167c90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611999565b505050565b6005805461169190600190611f11565b815481106116a1576116a1611e80565b90600052602060002090600c0201600582815481106116c2576116c2611e80565b600091825260209091208254600c90920201908155600180830154908201556002808301549082015560038083015490820180546001600160a01b03199081166001600160a01b0393841617909155600480850154908401556005808501548185015560068086015490850180548416918516919091179055600780860154908501805490931693169290921790556008808401549083015560098084018054918401805460ff909316151560ff19841681178255915461ffff61010091829004160262ffff001990921662ffffff1990931692909217179055600a8084015490830155600b9283015492909101919091558054806117c3576117c3611f24565b600082815260208120600c6000199093019283020181815560018101829055600281018290556003810180546001600160a01b031990811690915560048201839055600582018390556006820180548216905560078201805490911690556008810182905560098101805462ffffff19169055600a8101829055600b0155905550565b6040516001600160a01b038085166024830152831660448201526064810182905261187e9085906323b872dd60e01b90608401611645565b50505050565b8015806118fe5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa1580156118d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fc9190611ecf565b155b6119695760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161039f565b6040516001600160a01b03831660248201526044810182905261167c90849063095ea7b360e01b90606401611645565b60006119ee826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611a6b9092919063ffffffff16565b80519091501561167c5780806020019051810190611a0c9190611e63565b61167c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161039f565b6060611a7a8484600085611a84565b90505b9392505050565b606082471015611ae55760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161039f565b6001600160a01b0385163b611b3c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161039f565b600080866001600160a01b03168587604051611b589190611f5e565b60006040518083038185875af1925050503d8060008114611b95576040519150601f19603f3d011682016040523d82523d6000602084013e611b9a565b606091505b5091509150611baa828286611bb7565b925050505b949350505050565b60608315611bc6575081611a7d565b825115611bd65782518084602001fd5b8160405162461bcd60e51b815260040161039f9190611f7a565b600060208284031215611c0257600080fd5b5035919050565b80151581146110f257600080fd5b600060208284031215611c2957600080fd5b8135611a7d81611c09565b805182526020810151611c5260208401826001600160a01b03169052565b5060408101516040830152606081015160608301526080810151611c8160808401826001600160a01b03169052565b5060a0810151611c9c60a08401826001600160a01b03169052565b5060c081015160c083015260e0810151611cba60e084018215159052565b506101008181015161ffff1690830152610120808201519083015261014090810151910152565b838152602081018390526101a08101611baf6040830184611c34565b60008060408385031215611d1057600080fd5b50508035926020909101359150565b602080825282518282018190526000919060409081850190868401855b82811015611d76578151805185528681015187860152850151611d6186860182611c34565b506101a0939093019290850190600101611d3c565b5091979650505050505050565b6001600160a01b03811681146110f257600080fd5b600080600080600080600060e0888a031215611db357600080fd5b8735611dbe81611d83565b96506020880135611dce81611d83565b955060408801359450606088013593506080880135925060a088013561ffff81168114611dfa57600080fd5b915060c0880135611e0a81611c09565b8091505092959891949750929550565b60008060408385031215611e2d57600080fd5b8235611e3881611d83565b946020939093013593505050565b600060208284031215611e5857600080fd5b8135611a7d81611d83565b600060208284031215611e7557600080fd5b8151611a7d81611c09565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0396909616865260208601949094526040850192909252606084015261ffff166080830152151560a082015260c00190565b600060208284031215611ee157600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610fbf57610fbf611ee8565b81810381811115610fbf57610fbf611ee8565b634e487b7160e01b600052603160045260246000fd5b60005b83811015611f55578181015183820152602001611f3d565b50506000910152565b60008251611f70818460208701611f3a565b9190910192915050565b6020815260008251806020840152611f99816040850160208701611f3a565b601f01601f1916919091016040019291505056fea164736f6c6343000810000a000000000000000000000000148645f23913ddb250eb946d88ad6902bcd01baa

Deployed Bytecode

0x6080604052600436106100fe5760003560e01c80638da5cb5b11610095578063a2e641b611610064578063a2e641b6146102a5578063af2b0ce9146102bb578063e8bd883f146102db578063f14210a6146102fb578063f2fde38b1461031b57600080fd5b80638da5cb5b146102205780639645337a146102525780639de8528f14610272578063a1db97821461028557600080fd5b8063447c1e8c116100d1578063447c1e8c1461019a57806356952b1a146101c95780635bd1bcfa146101e9578063715018a61461020b57600080fd5b8063018c1d611461010357806315b0e94b14610125578063238dafe014610149578063328d8f721461017a575b600080fd5b34801561010f57600080fd5b5061012361011e366004611bf0565b61033b565b005b34801561013157600080fd5b506005545b6040519081526020015b60405180910390f35b34801561015557600080fd5b5060025461016a90600160a01b900460ff1681565b6040519015158152602001610140565b34801561018657600080fd5b50610123610195366004611c17565b610348565b3480156101a657600080fd5b506101ba6101b5366004611bf0565b6103c6565b60405161014093929190611ce1565b3480156101d557600080fd5b506101236101e4366004611cfd565b61048c565b3480156101f557600080fd5b506101fe61059a565b6040516101409190611d1f565b34801561021757600080fd5b506101236106a0565b34801561022c57600080fd5b506000546001600160a01b03165b6040516001600160a01b039091168152602001610140565b34801561025e57600080fd5b5061012361026d366004611bf0565b6106b4565b610123610280366004611d98565b6109fc565b34801561029157600080fd5b506101236102a0366004611e1a565b610ef2565b3480156102b157600080fd5b5061013660035481565b3480156102c757600080fd5b5060025461023a906001600160a01b031681565b3480156102e757600080fd5b5061016a6102f6366004611cfd565b610f96565b34801561030757600080fd5b50610123610316366004611bf0565b610fc5565b34801561032757600080fd5b50610123610336366004611e46565b61107c565b6103436110f5565b600355565b6103506110f5565b801515600260149054906101000a900460ff161515036103a85760405162461bcd60e51b815260206004820152600e60248201526d454e41424c453a20746f67676c6560901b60448201526064015b60405180910390fd5b60028054911515600160a01b0260ff60a01b19909216919091179055565b600581815481106103d657600080fd5b6000918252602091829020600c909102018054600182015460408051610160810182526002850154815260038501546001600160a01b039081169682019690965260048501549181019190915260058401546060820152600684015485166080820152600784015490941660a0850152600883015460c0850152600983015460ff8116151560e086015261ffff610100918290041690850152600a830154610120850152600b9092015461014084015292509083565b60025460405163cb8d406f60e01b81523360048201526001600160a01b039091169063cb8d406f90602401602060405180830381865afa1580156104d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f89190611e63565b61053a5760405162461bcd60e51b815260206004820152601360248201527214915310564e881d5b985d5d1a1bdc9a5e9959606a1b604482015260640161039f565b600254600160a01b900460ff1661057d5760405162461bcd60e51b81526020600482015260076024820152661153905093115160ca1b604482015260640161039f565b610587828261114f565b1561059657610596828261127f565b5050565b60606005805480602002602001604051908101604052809291908181526020016000905b828210156106975760008481526020908190206040805160608082018352600c870290930180548252600180820154838701528351610160810185526002830154815260038301546001600160a01b0390811682890152600484015482870152600584015496820196909652600683015486166080820152600783015490951660a0860152600882015460c0860152600982015460ff8116151560e087015261ffff610100918290041690860152600a820154610120860152600b909101546101408501529181019290925290835290920191016105be565b50505050905090565b6106a86110f5565b6106b2600061154d565b565b6002600154036107065760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161039f565b600260018190555060006005828154811061072357610723611e80565b60009182526020918290206040805160608082018352600c909402909201805483526001810154838601528151610160810183526002820154815260038201546001600160a01b039081169682019690965260048201548184015260058201549481019490945260068101548516608085019081526007820154861660a0860152600882015460c0860152600982015460ff8116151560e087015261ffff610100918290041690860152600a820154610120860152600b90910154610140850152908201929092529051909250166107f83390565b6001600160a01b0316148061081757506000546001600160a01b031633145b6108525760405162461bcd60e51b815260206004820152600c60248201526b0a48a9a9eac8a7440c2eae8d60a31b604482015260640161039f565b6020810151156108f95760008160400151608001516001600160a01b0316826020015160405160006040518083038185875af1925050503d80600081146108b5576040519150601f19603f3d011682016040523d82523d6000602084013e6108ba565b606091505b50509050806108f75760405162461bcd60e51b815260206004820152600960248201526811915154915195539160ba1b604482015260640161039f565b505b604080820151608081015160a082015160c08301519383015161014084015161010085015160e090950151600096610934969093929161159d565b6000818152600460205260409081902080546001600160a01b0319169055830151608081015160c082015160a09092015192935061097b926001600160a01b031691611619565b61098483611681565b604080830151608081015160a082015160c08301518385015161014085015161010086015160e09096015196516001600160a01b03909516967f9dd03547985269c0c89b1f4555a48984ea8fd32be022413935be7f4bfaad571b966109eb96909190611e96565b60405180910390a250506001805550565b600260015403610a4e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161039f565b6002600181905554600160a01b900460ff16610a9e5760405162461bcd60e51b815260206004820152600f60248201526e10d4915055114e88195b98589b1959608a1b604482015260640161039f565b6002546040805163268a453760e21b815290516000926001600160a01b031691639a2914dc9160048083019260209291908290030181865afa158015610ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0c9190611ecf565b905080600354610b1c9190611efe565b3414610b585760405162461bcd60e51b815260206004820152600b60248201526a4352454154453a2066656560a81b604482015260640161039f565b60035415610bf057600080546003546040516001600160a01b03909216918381818185875af1925050503d8060008114610bae576040519150601f19603f3d011682016040523d82523d6000602084013e610bb3565b606091505b5050905080610bee5760405162461bcd60e51b815260206004820152600760248201526611915154d1539160ca1b604482015260640161039f565b505b6001600160a01b03881615610c055787610c07565b335b9750610c1e6001600160a01b038816333087611846565b6000610c2f3389878a8a898961159d565b6000818152600460205260409020549091506001600160a01b031615610c825760405162461bcd60e51b8152602060048201526008602482015267222aa827a92222a960c11b604482015260640161039f565b60008181526004602090815260409182902080546001600160a01b0319166001600160a01b038d1617905581516060810183528381528082018590528251610160810184524281526005939192918301918101336001600160a01b031681526020018b8152602001600081526020018d6001600160a01b031681526020018c6001600160a01b0316815260200189815260200187151581526020018861ffff168152602001603281526020018a81525081525090806001815401808255809150506001900390600052602060002090600c020160009091909190915060008201518160000155602082015181600101556040820151816002016000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550604082015181600201556060820151816003015560808201518160040160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060a08201518160050160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e08201518160070160006101000a81548160ff0219169083151502179055506101008201518160070160016101000a81548161ffff021916908361ffff1602179055506101208201518160080155610140820151816009015550505050886001600160a01b0316610e993390565b6001600160a01b03167f5ea8ccf2224c15b1e992aefc2413256588f558af4f5c7ec3657dc754f625780a8a888b8b8a8a604051610edb96959493929190611e96565b60405180910390a350506001805550505050505050565b610efa6110f5565b8015610f065780610f6e565b6040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015610f4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f6e9190611ecf565b9050610596610f856000546001600160a01b031690565b6001600160a01b0384169083611619565b600254600090600160a01b900460ff16610fb257506000610fbf565b610fbc838361114f565b90505b92915050565b610fcd6110f5565b8015610fd95780610fdb565b475b90506000610ff16000546001600160a01b031690565b6001600160a01b03168260405160006040518083038185875af1925050503d806000811461103b576040519150601f19603f3d011682016040523d82523d6000602084013e611040565b606091505b50509050806105965760405162461bcd60e51b8152602060048201526008602482015267574954484452415760c01b604482015260640161039f565b6110846110f5565b6001600160a01b0381166110e95760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161039f565b6110f28161154d565b50565b6000546001600160a01b031633146106b25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161039f565b6000806005848154811061116557611165611e80565b60009182526020918290206040805160608082018352600c909402909201805483526001810154838601528151610160810183526002820154815260038201546001600160a01b0390811696820196909652600482015481840152600582015494810194909452600681015485166080850152600781015490941660a0840152600884015460c0840152600984015460ff8116151560e0850190815261ffff610100928390041691850191909152600a850154610120850152600b9094015461014084015281019190915290519091501561125a5780604001516101400151831115611255576000915050610fbf565b611275565b80604001516101400151831015611275576000915050610fbf565b5060019392505050565b60006005838154811061129457611294611e80565b600091825260208083206040805160608082018352600c909502909201805483526001810154838501528151610160810183526002820154815260038201546001600160a01b0390811695820195909552600482015481840152600582015495810195909552600681015484166080860152600781015490931660a0850152600883015460c0850152600983015460ff8116151560e086015261ffff610100918290041690850152600a830154610120850152600b90920154610140840152908101919091529150611366848461114f565b9050806113735750505050565b600254604083015160c081015160a09091015161139e926001600160a01b0391821692911690611884565b6002546040805163268a453760e21b815290516001600160a01b039092169163cafc836a918391639a2914dc916004808201926020929091908290030181865afa1580156113f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114149190611ecf565b60408581015160a08101518183015161012083015160c084015161010085015160e0808701516080909701519751908a901b6001600160e01b03191681526001600160a01b0395861660048201526024810194909452604484018d90526064840192909252608483015261ffff1660a482015291151560c4830152600060e4830152909116610104820152610124016000604051808303818588803b1580156114bc57600080fd5b505af11580156114d0573d6000803e3d6000fd5b50505050506114de84611681565b604080830151608081015160a082015160c08301518385015161010085015160e09095015195516001600160a01b03909416957febc4df80406235377ac0be1a9b4cc83a2fe9cb4bc1fe63b8a6d904a6782729349561153f958b9290611e96565b60405180910390a250505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60408051606098891b6bffffffffffffffffffffffff199081166020808401919091529890991b909816603489015260488801959095526068870193909352608886019190915260f01b6001600160f01b03191660a8850152151560f81b60aa8401528051608b81850301815260ab9093019052815191012090565b6040516001600160a01b03831660248201526044810182905261167c90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611999565b505050565b6005805461169190600190611f11565b815481106116a1576116a1611e80565b90600052602060002090600c0201600582815481106116c2576116c2611e80565b600091825260209091208254600c90920201908155600180830154908201556002808301549082015560038083015490820180546001600160a01b03199081166001600160a01b0393841617909155600480850154908401556005808501548185015560068086015490850180548416918516919091179055600780860154908501805490931693169290921790556008808401549083015560098084018054918401805460ff909316151560ff19841681178255915461ffff61010091829004160262ffff001990921662ffffff1990931692909217179055600a8084015490830155600b9283015492909101919091558054806117c3576117c3611f24565b600082815260208120600c6000199093019283020181815560018101829055600281018290556003810180546001600160a01b031990811690915560048201839055600582018390556006820180548216905560078201805490911690556008810182905560098101805462ffffff19169055600a8101829055600b0155905550565b6040516001600160a01b038085166024830152831660448201526064810182905261187e9085906323b872dd60e01b90608401611645565b50505050565b8015806118fe5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa1580156118d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fc9190611ecf565b155b6119695760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161039f565b6040516001600160a01b03831660248201526044810182905261167c90849063095ea7b360e01b90606401611645565b60006119ee826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611a6b9092919063ffffffff16565b80519091501561167c5780806020019051810190611a0c9190611e63565b61167c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161039f565b6060611a7a8484600085611a84565b90505b9392505050565b606082471015611ae55760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161039f565b6001600160a01b0385163b611b3c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161039f565b600080866001600160a01b03168587604051611b589190611f5e565b60006040518083038185875af1925050503d8060008114611b95576040519150601f19603f3d011682016040523d82523d6000602084013e611b9a565b606091505b5091509150611baa828286611bb7565b925050505b949350505050565b60608315611bc6575081611a7d565b825115611bd65782518084602001fd5b8160405162461bcd60e51b815260040161039f9190611f7a565b600060208284031215611c0257600080fd5b5035919050565b80151581146110f257600080fd5b600060208284031215611c2957600080fd5b8135611a7d81611c09565b805182526020810151611c5260208401826001600160a01b03169052565b5060408101516040830152606081015160608301526080810151611c8160808401826001600160a01b03169052565b5060a0810151611c9c60a08401826001600160a01b03169052565b5060c081015160c083015260e0810151611cba60e084018215159052565b506101008181015161ffff1690830152610120808201519083015261014090810151910152565b838152602081018390526101a08101611baf6040830184611c34565b60008060408385031215611d1057600080fd5b50508035926020909101359150565b602080825282518282018190526000919060409081850190868401855b82811015611d76578151805185528681015187860152850151611d6186860182611c34565b506101a0939093019290850190600101611d3c565b5091979650505050505050565b6001600160a01b03811681146110f257600080fd5b600080600080600080600060e0888a031215611db357600080fd5b8735611dbe81611d83565b96506020880135611dce81611d83565b955060408801359450606088013593506080880135925060a088013561ffff81168114611dfa57600080fd5b915060c0880135611e0a81611c09565b8091505092959891949750929550565b60008060408385031215611e2d57600080fd5b8235611e3881611d83565b946020939093013593505050565b600060208284031215611e5857600080fd5b8135611a7d81611d83565b600060208284031215611e7557600080fd5b8151611a7d81611c09565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0396909616865260208601949094526040850192909252606084015261ffff166080830152151560a082015260c00190565b600060208284031215611ee157600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610fbf57610fbf611ee8565b81810381811115610fbf57610fbf611ee8565b634e487b7160e01b600052603160045260246000fd5b60005b83811015611f55578181015183820152602001611f3d565b50506000910152565b60008251611f70818460208701611f3a565b9190910192915050565b6020815260008251806020840152611f99816040850160208701611f3a565b601f01601f1916919091016040019291505056fea164736f6c6343000810000a

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

000000000000000000000000148645f23913ddb250eb946d88ad6902bcd01baa

-----Decoded View---------------
Arg [0] : _perps (address): 0x148645F23913DDB250eb946D88AD6902bcD01Baa

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000148645f23913ddb250eb946d88ad6902bcd01baa


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.