ETH Price: $2,052.89 (+10.03%)
Gas: 0 Gwei

Contract

0x09FDEbEc9547B0E849F325ef875dDF78341DcB59

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SportsAMMV2LiquidityPool

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 100 runs

Other Settings:
paris EvmVersion
File 1 of 22 : SportsAMMV2LiquidityPool.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";

import "../../utils/proxy/ProxyReentrancyGuard.sol";
import "../../utils/proxy/ProxyOwned.sol";

import "@thales-dao/contracts/contracts/interfaces/IPriceFeed.sol";
import "@thales-dao/contracts/contracts/interfaces/IAddressManager.sol";

import "./SportsAMMV2LiquidityPoolRound.sol";

import "../AMM/Ticket.sol";
import "../../interfaces/ISportsAMMV2Manager.sol";
import "../../interfaces/ISportsAMMV2.sol";
import "../../interfaces/ISportsAMMV2RiskManager.sol";

contract SportsAMMV2LiquidityPool is Initializable, ProxyOwned, PausableUpgradeable, ProxyReentrancyGuard {
    /* ========== LIBRARIES ========== */

    using SafeERC20 for IERC20;

    /* ========== STRUCT DEFINITION ========== */

    struct InitParams {
        address _owner;
        address _sportsAMM;
        address _addressManager;
        IERC20 _collateral;
        uint _roundLength;
        uint _maxAllowedDeposit;
        uint _minDepositAmount;
        uint _maxAllowedUsers;
        uint _utilizationRate;
        address _safeBox;
        uint _safeBoxImpact;
        bytes32 _collateralKey;
    }

    /* ========== CONSTANTS ========== */

    uint private constant ONE = 1e18;
    uint private constant ONE_PERCENT = 1e16;
    uint private constant MAX_APPROVAL = type(uint256).max;
    uint private constant MAX_CURSOR_MOVES_PER_BATCH = 1000;

    /* ========== STATE VARIABLES ========== */

    ISportsAMMV2 public sportsAMM;
    IERC20 public collateral;

    bool public started;

    uint public round;
    uint public roundLength;
    // actually second round, as first one is default for mixed round and never closes
    uint public firstRoundStartTime;

    mapping(uint => address) public roundPools;

    mapping(uint => address[]) public usersPerRound;
    mapping(uint => mapping(address => bool)) public userInRound;
    mapping(uint => mapping(address => uint)) public balancesPerRound;
    mapping(uint => uint) public allocationPerRound;

    mapping(address => bool) public withdrawalRequested;
    mapping(address => uint) public withdrawalShare;

    mapping(uint => address[]) public tradingTicketsPerRound;
    mapping(uint => mapping(address => bool)) public isTradingTicketInARound;
    mapping(uint => mapping(address => bool)) public ticketAlreadyExercisedInRound;
    mapping(address => uint) public roundPerTicket;

    mapping(uint => uint) public profitAndLossPerRound;
    mapping(uint => uint) public cumulativeProfitAndLoss;

    uint public maxAllowedDeposit;
    uint public minDepositAmount;
    uint public maxAllowedUsers;
    uint public usersCurrentlyInPool;

    address public defaultLiquidityProvider;

    address public poolRoundMastercopy;

    uint public totalDeposited;

    bool public roundClosingPrepared;
    uint public usersProcessedInRound;

    uint public utilizationRate;

    address public safeBox;
    uint public safeBoxImpact;

    IAddressManager public addressManager;

    bytes32 public collateralKey;

    mapping(uint => uint) public nextExerciseIndexPerRound;

    /* ========== CONSTRUCTOR ========== */

    function initialize(InitParams calldata params) external initializer {
        setOwner(params._owner);
        initNonReentrant();
        sportsAMM = ISportsAMMV2(params._sportsAMM);
        addressManager = IAddressManager(params._addressManager);

        collateral = params._collateral;
        collateralKey = params._collateralKey;
        roundLength = params._roundLength;

        _setMaxAllowedDeposit(params._maxAllowedDeposit);
        _setMinDepositAmount(params._minDepositAmount);
        _setMaxAllowedUsers(params._maxAllowedUsers);

        _setUtilizationRate(params._utilizationRate);
        _setSafeBoxParams(params._safeBox, params._safeBoxImpact);

        collateral.approve(params._sportsAMM, MAX_APPROVAL);
        round = 1;
    }

    /* ========== EXTERNAL WRITE FUNCTIONS ========== */

    /// @notice start pool and begin round #2
    function start() external onlyOwner {
        require(!started, "LPHasStarted");
        require(allocationPerRound[2] > 0, "CantStartWithoutDeposits");

        firstRoundStartTime = block.timestamp;
        round = 2;

        address roundPool = _getOrCreateRoundPool(2);
        SportsAMMV2LiquidityPoolRound(roundPool).updateRoundTimes(firstRoundStartTime, getRoundEndTime(2));

        started = true;
        emit PoolStarted();
    }

    /// @notice deposit funds from user into pool for the next round
    /// @param amount value to be deposited
    function deposit(uint amount) external canDeposit(amount) nonReentrant whenNotPaused roundClosingNotPrepared {
        _deposit(amount);
    }

    /// @notice deposit funds from user into pool for the next round
    /// @param amount value to be deposited
    function _deposit(uint amount) internal {
        uint nextRound = round + 1;
        address roundPool = _getOrCreateRoundPool(nextRound);
        collateral.safeTransferFrom(msg.sender, roundPool, amount);

        require(msg.sender != defaultLiquidityProvider, "CantDepositDirectlyAsDefaultLP");

        // new user enters the pool
        if (balancesPerRound[round][msg.sender] == 0 && balancesPerRound[nextRound][msg.sender] == 0) {
            require(usersCurrentlyInPool < maxAllowedUsers, "MaxUsersReached");
            usersPerRound[nextRound].push(msg.sender);
            usersCurrentlyInPool = usersCurrentlyInPool + 1;
        }

        balancesPerRound[nextRound][msg.sender] += amount;

        allocationPerRound[nextRound] += amount;
        totalDeposited += amount;

        emit Deposited(msg.sender, amount, round);
    }

    /// @notice get collateral amount needed for trade and store ticket as trading in the round
    /// @param ticket to trade
    /// @param amount amount to get
    function commitTrade(address ticket, uint amount) external nonReentrant whenNotPaused onlyAMM roundClosingNotPrepared {
        require(started, "PoolNotStarted");
        require(amount > 0, "ZeroAmount");
        uint ticketRound = getTicketRound(ticket);
        roundPerTicket[ticket] = ticketRound;
        address liquidityPoolRound = _getOrCreateRoundPool(ticketRound);
        if (ticketRound == round) {
            collateral.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amount);
            require(
                collateral.balanceOf(liquidityPoolRound) >=
                    (allocationPerRound[round] - ((allocationPerRound[round] * utilizationRate) / ONE)),
                "AmountExceedsUtilRate"
            );
        } else if (ticketRound > round) {
            uint poolBalance = collateral.balanceOf(liquidityPoolRound);
            if (poolBalance >= amount) {
                collateral.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amount);
            } else {
                uint differenceToLPAsDefault = amount - poolBalance;
                _depositAsDefault(differenceToLPAsDefault, liquidityPoolRound, ticketRound);
                collateral.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amount);
            }
        } else {
            require(ticketRound == 1, "InvalidRound");
            _provideAsDefault(amount);
        }
        tradingTicketsPerRound[ticketRound].push(ticket);
        isTradingTicketInARound[ticketRound][ticket] = true;
    }

    /// @notice transfer collateral amount from AMM to LP (ticket liquidity pool round)
    /// @param _ticket to trade
    function transferToPool(address _ticket, uint _amount) external whenNotPaused roundClosingNotPrepared onlyAMM {
        uint ticketRound = getTicketRound(_ticket);

        // if this is a past round, but not the default one, then we send the funds to the current round
        if (ticketRound > 1 && ticketRound < round) {
            ticketRound = round;
        }
        if (_amount > 0) {
            address liquidityPoolRound = ticketRound <= 1 ? defaultLiquidityProvider : _getOrCreateRoundPool(ticketRound);
            collateral.safeTransferFrom(address(sportsAMM), liquidityPoolRound, _amount);
        }
        if (isTradingTicketInARound[ticketRound][_ticket]) {
            ticketAlreadyExercisedInRound[ticketRound][_ticket] = true;
        }
    }

    /// @notice migrate ticket to next round
    /// @param _ticket ticket to migrate
    /// @param _newRound new round (0 for next round)
    /// @param _ticketIndexInRound index of ticket in round (use 0 to perform automatic lookup through the round array)
    function migrateTicketToAnotherRound(
        address _ticket,
        uint _newRound,
        uint _ticketIndexInRound
    ) external onlyWhitelistedAddresses(msg.sender) roundClosingNotPrepared {
        uint ticketRound = getTicketRound(_ticket);
        require(ticketRound == round, "TicketNotInCurrentRound");
        _migrateTicketToNewRound(_ticket, _newRound == 0 ? round + 1 : _newRound, _ticketIndexInRound);
    }

    /// @notice migrate batch of tickets to another round
    /// @param _tickets batch of tickets to migrate
    /// @param _newRound new round (0 for next round)
    /// @param _ticketsIndexInRound index of tickets in round (use 0 to perform automatic lookup through the round array)
    function migrateBatchOfTicketsToAnotherRound(
        address[] memory _tickets,
        uint _newRound,
        uint[] memory _ticketsIndexInRound
    ) external onlyWhitelistedAddresses(msg.sender) roundClosingNotPrepared {
        _newRound = _newRound == 0 ? round + 1 : _newRound;
        if (_ticketsIndexInRound.length == 0) {
            for (uint i; i < _tickets.length; i++) {
                _migrateTicketToNewRound(_tickets[i], _newRound, 0);
            }
        } else {
            require(_tickets.length == _ticketsIndexInRound.length, "ArraysLengthsMustMatch");
            uint tradingTicketsLength = tradingTicketsPerRound[round].length;
            for (uint i = 0; i < _tickets.length; i++) {
                require(_ticketsIndexInRound[i] > 0, "TicketIndexMustBeGreaterThan0");
                // check if the ticket index has not been migrated yet
                if (_ticketsIndexInRound[i] < tradingTicketsLength - i) {
                    _migrateTicketToNewRound(_tickets[i], _newRound, _ticketsIndexInRound[i]);
                } else {
                    // if the ticket index has been migrated, find the new index
                    // the new index is one of the ticket indexes in the _ticketsIndexInRound array
                    uint n;
                    bool found = false;
                    while (n < _ticketsIndexInRound.length) {
                        if (tradingTicketsPerRound[round][_ticketsIndexInRound[n]] == _tickets[i]) {
                            found = true;
                            break;
                        }
                        ++n;
                    }
                    require(found, "TicketNotFoundInInputArray");
                    _migrateTicketToNewRound(_tickets[i], _newRound, _ticketsIndexInRound[n]);
                }
            }
        }
    }

    /// @notice request withdrawal from the LP
    function withdrawalRequest() external nonReentrant canWithdraw whenNotPaused roundClosingNotPrepared {
        if (totalDeposited > balancesPerRound[round][msg.sender]) {
            totalDeposited -= balancesPerRound[round][msg.sender];
        } else {
            totalDeposited = 0;
        }

        usersCurrentlyInPool = usersCurrentlyInPool - 1;
        withdrawalRequested[msg.sender] = true;
        emit WithdrawalRequested(msg.sender);
    }

    /// @notice request partial withdrawal from the LP
    /// @param _share the percentage the user is wihdrawing from his total deposit
    function partialWithdrawalRequest(uint _share) external nonReentrant canWithdraw whenNotPaused roundClosingNotPrepared {
        require(_share >= ONE_PERCENT * 10 && _share <= ONE_PERCENT * 90, "InvalidWithdrawalValue");

        uint toWithdraw = (balancesPerRound[round][msg.sender] * _share) / ONE;
        if (totalDeposited > toWithdraw) {
            totalDeposited -= toWithdraw;
        } else {
            totalDeposited = 0;
        }

        withdrawalRequested[msg.sender] = true;
        withdrawalShare[msg.sender] = _share;
        emit WithdrawalRequested(msg.sender);
    }

    /// @notice prepare round closing - exercise tickets and ensure there are no tickets left unresolved, handle SB profit and calculate PnL
    function prepareRoundClosing() external nonReentrant whenNotPaused roundClosingNotPrepared {
        // do this first to move the cursor if needed
        exerciseTicketsReadyToBeExercised();

        require(canCloseCurrentRound(), "CantCloseRound");

        address roundPool = roundPools[round];
        // final balance is the final amount of collateral in the round pool
        uint currentBalance = collateral.balanceOf(roundPool);

        // send profit reserved for SafeBox if positive round
        if (currentBalance > allocationPerRound[round]) {
            uint safeBoxAmount = ((currentBalance - allocationPerRound[round]) * safeBoxImpact) / ONE;
            collateral.safeTransferFrom(roundPool, safeBox, safeBoxAmount);
            currentBalance = currentBalance - safeBoxAmount;
            emit SafeBoxSharePaid(safeBoxImpact, safeBoxAmount);
        }

        // calculate PnL

        // if no allocation for current round
        if (allocationPerRound[round] == 0) {
            profitAndLossPerRound[round] = 1 ether;
        } else {
            profitAndLossPerRound[round] = (currentBalance * ONE) / allocationPerRound[round];
        }

        roundClosingPrepared = true;

        emit RoundClosingPrepared(round);
    }

    /// @notice process round closing batch - update balances and handle withdrawals
    /// @param _batchSize size of batch
    function processRoundClosingBatch(uint _batchSize) external nonReentrant whenNotPaused {
        require(roundClosingPrepared, "RoundClosingNotPrepared");
        require(usersProcessedInRound < usersPerRound[round].length, "AllUsersProcessed");
        require(_batchSize > 0, "BatchSizeZero");

        address roundPool = roundPools[round];

        uint endCursor = usersProcessedInRound + _batchSize;
        if (endCursor > usersPerRound[round].length) {
            endCursor = usersPerRound[round].length;
        }
        for (uint i = usersProcessedInRound; i < endCursor; i++) {
            address user = usersPerRound[round][i];
            uint balanceAfterCurRound = (balancesPerRound[round][user] * profitAndLossPerRound[round]) / ONE;
            if (!withdrawalRequested[user] && (profitAndLossPerRound[round] > 0)) {
                balancesPerRound[round + 1][user] = balancesPerRound[round + 1][user] + balanceAfterCurRound;
                usersPerRound[round + 1].push(user);
            } else {
                if (withdrawalShare[user] > 0) {
                    uint amountToClaim = (balanceAfterCurRound * withdrawalShare[user]) / ONE;
                    collateral.safeTransferFrom(roundPool, user, amountToClaim);
                    emit Claimed(user, amountToClaim);
                    withdrawalRequested[user] = false;
                    withdrawalShare[user] = 0;
                    usersPerRound[round + 1].push(user);
                    balancesPerRound[round + 1][user] = balanceAfterCurRound - amountToClaim;
                } else {
                    balancesPerRound[round + 1][user] = 0;
                    collateral.safeTransferFrom(roundPool, user, balanceAfterCurRound);
                    withdrawalRequested[user] = false;
                    emit Claimed(user, balanceAfterCurRound);
                }
            }
            usersProcessedInRound = usersProcessedInRound + 1;
        }

        emit RoundClosingBatchProcessed(round, _batchSize);
    }

    /// @notice close current round and begin next round - calculate cumulative PnL
    function closeRound() external nonReentrant whenNotPaused {
        require(roundClosingPrepared, "RoundClosingNotPrepared");
        require(usersProcessedInRound == usersPerRound[round].length, "NotAllUsersProcessed");
        // set for next round to false
        roundClosingPrepared = false;

        address roundPool = roundPools[round];

        // always claim for defaultLiquidityProvider
        if (balancesPerRound[round][defaultLiquidityProvider] > 0) {
            uint balanceAfterCurRound = (balancesPerRound[round][defaultLiquidityProvider] * profitAndLossPerRound[round]) /
                ONE;
            collateral.safeTransferFrom(roundPool, defaultLiquidityProvider, balanceAfterCurRound);
            emit Claimed(defaultLiquidityProvider, balanceAfterCurRound);
        }

        if (round == 2) {
            cumulativeProfitAndLoss[round] = profitAndLossPerRound[round];
        } else {
            cumulativeProfitAndLoss[round] = (cumulativeProfitAndLoss[round - 1] * profitAndLossPerRound[round]) / ONE;
        }

        // start next round
        ++round;

        //add all carried over collateral
        allocationPerRound[round] += collateral.balanceOf(roundPool);

        totalDeposited = allocationPerRound[round] - balancesPerRound[round][defaultLiquidityProvider];

        address roundPoolNewRound = _getOrCreateRoundPool(round);

        collateral.safeTransferFrom(roundPool, roundPoolNewRound, collateral.balanceOf(roundPool));

        usersProcessedInRound = 0;

        emit RoundClosed(round - 1, profitAndLossPerRound[round - 1]);
    }

    /// @notice iterate all tickets in the current round and exercise those ready to be exercised
    function exerciseTicketsReadyToBeExercised() public roundClosingNotPrepared whenNotPaused {
        _exerciseTicketsReadyToBeExercised(round);
    }

    /// @notice iterate all tickets in the default round and exercise those ready to be exercised
    function exerciseDefaultRoundTicketsReadyToBeExercised() external whenNotPaused {
        _exerciseTicketsReadyToBeExercised(1);
    }

    /// @notice iterate all tickets in the current round and exercise those ready to be exercised (batch)
    /// @param _batchSize number of tickets to be processed
    function exerciseTicketsReadyToBeExercisedBatch(
        uint _batchSize
    ) external nonReentrant whenNotPaused roundClosingNotPrepared {
        _exerciseTicketsReadyToBeExercisedBatch(_batchSize, round);
    }

    /// @notice iterate all default round tickets in the current round and exercise those ready to be exercised (batch)
    /// @param _batchSize number of tickets to be processed
    function exerciseDefaultRoundTicketsReadyToBeExercisedBatch(
        uint _batchSize
    ) external nonReentrant whenNotPaused roundClosingNotPrepared {
        _exerciseTicketsReadyToBeExercisedBatch(_batchSize, 1);
    }

    /* ========== EXTERNAL READ FUNCTIONS ========== */

    /// @notice whether the user is currently LPing
    /// @param _user to check
    /// @return isUserInLP whether the user is currently LPing
    function isUserLPing(address _user) external view returns (bool isUserInLP) {
        isUserInLP =
            (balancesPerRound[round][_user] > 0 || balancesPerRound[round + 1][_user] > 0) &&
            (!withdrawalRequested[_user] || withdrawalShare[_user] > 0);
    }

    /// @notice return the price of the pool collateral
    function getCollateralPrice() public view returns (uint) {
        return IPriceFeed(addressManager.getAddress("PriceFeed")).rateForCurrency(collateralKey);
    }

    /// @notice get the pool address for the ticket
    /// @param _ticket to check
    /// @return roundPool the pool address for the ticket
    function getTicketPool(address _ticket) external view returns (address roundPool) {
        roundPool = roundPools[getTicketRound(_ticket)];
    }

    /// @notice checks if all conditions are met to close the round
    /// @return bool
    function canCloseCurrentRound() public view returns (bool) {
        if (!started || block.timestamp < getRoundEndTime(round)) {
            return false;
        }

        Ticket ticket;
        address ticketAddress;

        uint len = tradingTicketsPerRound[round].length;
        uint cursor = nextExerciseIndexPerRound[round];

        for (uint i = cursor; i < len; ++i) {
            ticketAddress = tradingTicketsPerRound[round][i];
            if (!ticketAlreadyExercisedInRound[round][ticketAddress]) {
                ticket = Ticket(ticketAddress);
                if (!ticket.areAllMarketsResolved()) {
                    return false;
                }
            }
        }
        return true;
    }

    /// @notice iterate all tickets in the current round and return true if at least one can be exercised
    /// @return bool
    function hasTicketsReadyToBeExercised() external view returns (bool) {
        return _hasTicketsReadyToBeExercised(round);
    }

    /// @notice iterate all tickets in the default round and return true if at least one can be exercised
    /// @return bool
    function hasDefaultRoundTicketsReadyToBeExercised() external view returns (bool) {
        return _hasTicketsReadyToBeExercised(1);
    }

    function _hasTicketsReadyToBeExercised(uint _round) internal view returns (bool) {
        Ticket ticket;
        address ticketAddress;

        uint len = tradingTicketsPerRound[_round].length;
        uint cursor = nextExerciseIndexPerRound[_round];

        // Only check from the current cursor onward
        for (uint i = cursor; i < len; i++) {
            ticketAddress = tradingTicketsPerRound[_round][i];
            if (!ticketAlreadyExercisedInRound[_round][ticketAddress]) {
                ticket = Ticket(ticketAddress);
                if (ticket.isTicketExercisable() && !ticket.isUserTheWinner()) {
                    return true;
                }
            }
        }
        return false;
    }

    /// @notice return multiplied PnLs between rounds
    /// @param _roundA round number from
    /// @param _roundB round number to
    /// @return uint
    function cumulativePnLBetweenRounds(uint _roundA, uint _roundB) public view returns (uint) {
        return (cumulativeProfitAndLoss[_roundB] * profitAndLossPerRound[_roundA]) / cumulativeProfitAndLoss[_roundA];
    }

    /// @notice return the start time of the passed round
    /// @param _round number
    /// @return uint the start time of the given round
    function getRoundStartTime(uint _round) public view returns (uint) {
        return firstRoundStartTime + (_round - 2) * roundLength;
    }

    /// @notice return the end time of the passed round
    /// @param _round number
    /// @return uint the end time of the given round
    function getRoundEndTime(uint _round) public view returns (uint) {
        return firstRoundStartTime + (_round - 1) * roundLength;
    }

    /// @notice return the round to which a ticket belongs to
    /// @param _ticket to get the round for
    /// @return ticketRound the min round which the ticket belongs to
    function getTicketRound(address _ticket) public view returns (uint ticketRound) {
        ticketRound = roundPerTicket[_ticket];
        if (ticketRound == 0) {
            Ticket ticket = Ticket(_ticket);
            uint maturity;
            uint16 sportId;

            for (uint i = 0; i < ticket.numOfMarkets(); i++) {
                (, sportId, , maturity, , , , , ) = ticket.markets(i);
                bool isFuture = ISportsAMMV2RiskManager(addressManager.getAddress("SportsAMMV2RiskManager")).isSportIdFuture(
                    sportId
                );
                if (maturity > firstRoundStartTime && !isFuture) {
                    if (i == 0) {
                        ticketRound = (maturity - firstRoundStartTime) / roundLength + 2;
                    } else {
                        // if ticket is cross rounds, use the default round
                        if (((maturity - firstRoundStartTime) / roundLength + 2) != ticketRound) {
                            ticketRound = 1;
                            break;
                        }
                    }
                } else {
                    ticketRound = 1;
                    break;
                }
            }
        }
    }

    /// @notice return the count of users in current round
    /// @return uint the count of users in current round
    function getUsersCountInCurrentRound() external view returns (uint) {
        return usersPerRound[round].length;
    }

    /// @notice return the number of tickets in current rount
    /// @return numOfTickets the number of tickets in urrent rount
    function getNumberOfTradingTicketsPerRound(uint _round) external view returns (uint numOfTickets) {
        numOfTickets = tradingTicketsPerRound[_round].length;
    }

    /// @notice Get the index of a ticket in a specific round's trading tickets array
    /// @param _ticket The address of the ticket to find
    /// @param _round The round number to search in
    /// @param _startIndex The starting index to search from
    /// @param _endIndex The ending index to search until
    /// @return index The index of the ticket if found, otherwise returns _endIndex
    /// @return found Whether the ticket was found
    function getTicketIndexInTicketRound(
        address _ticket,
        uint _round,
        uint _startIndex,
        uint _endIndex
    ) external view returns (uint index, bool found) {
        uint finalIndex = tradingTicketsPerRound[_round].length > _endIndex
            ? _endIndex
            : tradingTicketsPerRound[_round].length;
        for (uint i = _startIndex; i < finalIndex; ++i) {
            if (tradingTicketsPerRound[_round][i] == _ticket) {
                return (i, true);
            }
        }
        return (_endIndex, false);
    }

    /* ========== INTERNAL FUNCTIONS ========== */

    function _exerciseTicketsReadyToBeExercisedBatch(uint _batchSize, uint _roundNumber) internal {
        require(_batchSize > 0, "BatchSizeZero");

        uint len = tradingTicketsPerRound[_roundNumber].length;
        uint cursor = nextExerciseIndexPerRound[_roundNumber];
        uint cursorMoves;

        // 0) Pre-compaction: skip already exercised tickets, up to 1000 moves
        while (
            cursor < len &&
            ticketAlreadyExercisedInRound[_roundNumber][tradingTicketsPerRound[_roundNumber][cursor]] &&
            cursorMoves < MAX_CURSOR_MOVES_PER_BATCH
        ) {
            unchecked {
                ++cursor;
                ++cursorMoves;
            }
        }

        // ✅ Early exit if we spent this batch just moving the cursor
        if (cursorMoves >= MAX_CURSOR_MOVES_PER_BATCH) {
            nextExerciseIndexPerRound[_roundNumber] = cursor;
            return;
        }

        uint processed;

        // 1) Process at most _batchSize *exercised* tickets starting from the current cursor
        for (uint i = cursor; i < len && processed < _batchSize; ++i) {
            if (_exerciseTicket(_roundNumber, tradingTicketsPerRound[_roundNumber][i])) {
                unchecked {
                    ++processed;
                }
            }
        }

        // 2) Post-compaction: move cursor again, up to the same remaining allowance
        while (
            cursor < len &&
            ticketAlreadyExercisedInRound[_roundNumber][tradingTicketsPerRound[_roundNumber][cursor]] &&
            cursorMoves < MAX_CURSOR_MOVES_PER_BATCH
        ) {
            unchecked {
                ++cursor;
                ++cursorMoves;
            }
        }

        nextExerciseIndexPerRound[_roundNumber] = cursor;
    }

    function _exerciseTicketsReadyToBeExercised(uint _roundNumber) internal {
        uint len = tradingTicketsPerRound[_roundNumber].length;
        uint cursor = nextExerciseIndexPerRound[_roundNumber];

        // 0) Pre-compaction: skip over any tickets that were marked exercised
        // since last time (e.g. via transferToPool or batch calls)
        while (cursor < len && ticketAlreadyExercisedInRound[_roundNumber][tradingTicketsPerRound[_roundNumber][cursor]]) {
            unchecked {
                ++cursor;
            }
        }

        // 1) Process from the (updated) cursor onward
        for (uint i = cursor; i < len; ++i) {
            _exerciseTicket(_roundNumber, tradingTicketsPerRound[_roundNumber][i]);
        }

        // 2) Post-compaction: some tickets starting at `cursor` may now be exercised;
        // move cursor forward over that newly-exercised prefix.
        while (cursor < len && ticketAlreadyExercisedInRound[_roundNumber][tradingTicketsPerRound[_roundNumber][cursor]]) {
            unchecked {
                ++cursor;
            }
        }

        nextExerciseIndexPerRound[_roundNumber] = cursor;
    }

    function _exerciseTicket(uint _roundNumber, address ticketAddress) internal returns (bool exercised) {
        if (!ticketAlreadyExercisedInRound[_roundNumber][ticketAddress]) {
            Ticket ticket = Ticket(ticketAddress);
            bool isWinner = ticket.isUserTheWinner();

            bool isSystemExercisable = false;
            bool isSystem = false;
            if (_roundNumber > 1) {
                isSystem = ticket.isSystem();
            }
            // in case round needs to be closed, ensure all system bets are exercised too, as there could be money in those that needs to be returned to LP rounds
            if (isSystem && block.timestamp > getRoundEndTime(_roundNumber)) {
                isSystemExercisable = true;
            }
            if (ticket.isTicketExercisable() && (!isWinner || isSystemExercisable)) {
                sportsAMM.handleTicketResolving(ticketAddress, ISportsAMMV2.TicketAction.Exercise);
            }
            if ((isWinner && !isSystem) || ticket.resolved()) {
                ticketAlreadyExercisedInRound[_roundNumber][ticketAddress] = true;
                exercised = true;
            }
        }
    }

    function _depositAsDefault(uint _amount, address _roundPool, uint _round) internal {
        require(defaultLiquidityProvider != address(0), "DefaultLPNotSet");

        collateral.safeTransferFrom(defaultLiquidityProvider, _roundPool, _amount);

        balancesPerRound[_round][defaultLiquidityProvider] += _amount;
        allocationPerRound[_round] += _amount;

        emit Deposited(defaultLiquidityProvider, _amount, _round);
    }

    function _provideAsDefault(uint _amount) internal {
        require(defaultLiquidityProvider != address(0), "DefaultLPNotSet");

        collateral.safeTransferFrom(defaultLiquidityProvider, address(sportsAMM), _amount);

        balancesPerRound[1][defaultLiquidityProvider] += _amount;
        allocationPerRound[1] += _amount;

        emit Deposited(defaultLiquidityProvider, _amount, 1);
    }

    function _getOrCreateRoundPool(uint _round) internal returns (address roundPool) {
        roundPool = roundPools[_round];
        if (roundPool == address(0)) {
            if (_round == 1) {
                roundPools[_round] = defaultLiquidityProvider;
                roundPool = defaultLiquidityProvider;
            } else {
                require(poolRoundMastercopy != address(0), "RoundPoolMastercopyNotSet");
                SportsAMMV2LiquidityPoolRound newRoundPool = SportsAMMV2LiquidityPoolRound(
                    Clones.clone(poolRoundMastercopy)
                );
                newRoundPool.initialize(
                    address(this),
                    collateral,
                    _round,
                    getRoundEndTime(_round - 1),
                    getRoundEndTime(_round)
                );
                roundPool = address(newRoundPool);
                roundPools[_round] = roundPool;
                emit RoundPoolCreated(_round, roundPool);
            }
        }
    }

    function _migrateTicketToNewRound(address _ticket, uint _newRound, uint _ticketIndexInRound) internal {
        require(_newRound > round || _newRound == 1, "RoundAlreadyClosed");
        uint ticketRound = getTicketRound(_ticket);
        require(ticketRound == round, "TicketNotInRound");
        require(isTradingTicketInARound[ticketRound][_ticket], "TicketNotInCurrentRound");
        require(!ticketAlreadyExercisedInRound[ticketRound][_ticket], "TicketAlreadyExercised");
        require(!Ticket(_ticket).resolved(), "TicketAlreadyResolved");

        // removing from old round
        delete isTradingTicketInARound[ticketRound][_ticket];
        _removeTicketFromRound(ticketRound, _ticket, _ticketIndexInRound);

        // transfer funds from new pool to old pool
        address oldLiquidityPoolRound = _getOrCreateRoundPool(ticketRound);
        address newLiquidityPoolRound = _getOrCreateRoundPool(_newRound);
        uint transferAmountNewToOld = collateral.balanceOf(_ticket) - Ticket(_ticket).buyInAmount();
        uint newPoolBalance = collateral.balanceOf(newLiquidityPoolRound);
        if (transferAmountNewToOld > newPoolBalance) {
            uint differenceToLPAsDefault = transferAmountNewToOld - newPoolBalance;
            _depositAsDefault(differenceToLPAsDefault, newLiquidityPoolRound, _newRound);
        }
        collateral.safeTransferFrom(newLiquidityPoolRound, oldLiquidityPoolRound, transferAmountNewToOld);

        // adding ticket to new round
        roundPerTicket[_ticket] = _newRound;
        isTradingTicketInARound[_newRound][_ticket] = true;
        tradingTicketsPerRound[_newRound].push(_ticket);
        emit TicketMigratedToNextRound(_ticket, ticketRound, _newRound);
    }

    function _removeTicketFromRound(uint _round, address _ticket, uint _ticketIndexInRound) internal {
        // if _ticketIndexInRound is 0, we need to find the ticket in the round and remove it
        // lookup is performed by iterating through the array
        bool found;
        if (_ticketIndexInRound == 0) {
            for (uint i; i < tradingTicketsPerRound[_round].length; ++i) {
                if (tradingTicketsPerRound[_round][i] == _ticket) {
                    found = true;
                    _ticketIndexInRound = i;
                    break;
                }
            }
        } else {
            found =
                _ticketIndexInRound < tradingTicketsPerRound[_round].length &&
                tradingTicketsPerRound[_round][_ticketIndexInRound] == _ticket;
        }
        require(found, "TicketNotFound");

        // adjust cursor if needed so we don't skip anything
        uint cursor = nextExerciseIndexPerRound[_round];
        if (_ticketIndexInRound < cursor) {
            nextExerciseIndexPerRound[_round] = _ticketIndexInRound;
        }

        tradingTicketsPerRound[_round][_ticketIndexInRound] = tradingTicketsPerRound[_round][
            tradingTicketsPerRound[_round].length - 1
        ];
        tradingTicketsPerRound[_round].pop();
    }

    /* ========== SETTERS ========== */

    /// @notice Pause/unpause LP
    /// @param _setPausing true/false
    function setPaused(bool _setPausing) external onlyOwner {
        _setPausing ? _pause() : _unpause();
    }

    /// @notice Set _poolRoundMastercopy
    /// @param _poolRoundMastercopy to clone round pools from
    function setPoolRoundMastercopy(address _poolRoundMastercopy) external onlyOwner {
        require(_poolRoundMastercopy != address(0), "ZeroAddress");
        poolRoundMastercopy = _poolRoundMastercopy;
        emit PoolRoundMastercopyChanged(poolRoundMastercopy);
    }

    /// @notice Set max allowed deposit
    /// @param _maxAllowedDeposit Deposit value
    function setMaxAllowedDeposit(uint _maxAllowedDeposit) external onlyOwner {
        _setMaxAllowedDeposit(_maxAllowedDeposit);
    }

    /// @notice Set min allowed deposit
    /// @param _minDepositAmount Deposit value
    function setMinAllowedDeposit(uint _minDepositAmount) external onlyOwner {
        _setMinDepositAmount(_minDepositAmount);
    }

    /// @notice Set _maxAllowedUsers
    /// @param _maxAllowedUsers Deposit value
    function setMaxAllowedUsers(uint _maxAllowedUsers) external onlyOwner {
        _setMaxAllowedUsers(_maxAllowedUsers);
    }

    // ==================== INTERNAL HELPERS ====================

    function _setMaxAllowedDeposit(uint _maxAllowedDeposit) internal {
        maxAllowedDeposit = _maxAllowedDeposit;
        emit MaxAllowedDepositChanged(_maxAllowedDeposit);
    }

    function _setMinDepositAmount(uint _minDepositAmount) internal {
        minDepositAmount = _minDepositAmount;
        emit MinAllowedDepositChanged(_minDepositAmount);
    }

    function _setMaxAllowedUsers(uint _maxAllowedUsers) internal {
        maxAllowedUsers = _maxAllowedUsers;
        emit MaxAllowedUsersChanged(_maxAllowedUsers);
    }

    /// @notice Set SportsAMM contract
    /// @param _sportsAMM SportsAMM address
    function setSportsAMM(ISportsAMMV2 _sportsAMM) external onlyOwner {
        require(address(_sportsAMM) != address(0), "ZeroAddress");
        if (address(sportsAMM) != address(0)) {
            collateral.approve(address(sportsAMM), 0);
        }
        sportsAMM = _sportsAMM;
        collateral.approve(address(sportsAMM), MAX_APPROVAL);
        emit SportAMMChanged(address(_sportsAMM));
    }

    /// @notice Set defaultLiquidityProvider wallet
    /// @param _defaultLiquidityProvider default liquidity provider
    function setDefaultLiquidityProvider(address _defaultLiquidityProvider) external onlyOwner {
        require(_defaultLiquidityProvider != address(0), "ZeroAddress");
        defaultLiquidityProvider = _defaultLiquidityProvider;
        emit DefaultLiquidityProviderChanged(_defaultLiquidityProvider);
    }

    /// @notice Set length of rounds
    /// @param _roundLength Length of a round in seconds
    function setRoundLength(uint _roundLength) external onlyOwner {
        require(!started, "CantChangeAfterPoolStart");
        roundLength = _roundLength;
        emit RoundLengthChanged(_roundLength);
    }

    /// @notice set utilization rate parameter
    /// @param _utilizationRate value as percentage
    function setUtilizationRate(uint _utilizationRate) external onlyOwner {
        _setUtilizationRate(_utilizationRate);
    }

    /// @notice set SafeBox params
    /// @param _safeBox where to send a profit reserved for protocol from each round
    /// @param _safeBoxImpact how much is the SafeBox percentage
    function setSafeBoxParams(address _safeBox, uint _safeBoxImpact) external onlyOwner {
        _setSafeBoxParams(_safeBox, _safeBoxImpact);
    }

    function _setUtilizationRate(uint _utilizationRate) internal {
        require(_utilizationRate <= ONE, "UtilRateTooHigh");
        utilizationRate = _utilizationRate;
        emit UtilizationRateChanged(_utilizationRate);
    }

    function _setSafeBoxParams(address _safeBox, uint _safeBoxImpact) internal {
        require(_safeBoxImpact <= ONE, "SafeBoxImpactTooHigh");
        safeBox = _safeBox;
        safeBoxImpact = _safeBoxImpact;
        emit SetSafeBoxParams(_safeBox, _safeBoxImpact);
    }

    /* ========== MODIFIERS ========== */

    modifier canDeposit(uint amount) {
        require(!withdrawalRequested[msg.sender], "CantDepositDuringWithdrawalRequested");
        require(totalDeposited + amount <= maxAllowedDeposit, "AmountExceedsLPCap");
        if (balancesPerRound[round][msg.sender] == 0 && balancesPerRound[round + 1][msg.sender] == 0) {
            require(amount >= minDepositAmount, "AmountLessThanMinDeposit");
        }
        _;
    }

    modifier canWithdraw() {
        require(started, "PoolNotStarted");
        require(!withdrawalRequested[msg.sender], "WithdrawalAlreadyRequested");
        require(balancesPerRound[round][msg.sender] > 0, "NothingToWithdraw");
        require(balancesPerRound[round + 1][msg.sender] == 0, "CantWithdrawWhenDepositedForNextRound");
        _;
    }

    modifier onlyAMM() {
        require(msg.sender == address(sportsAMM), "OnlyFromAMM");
        _;
    }

    modifier roundClosingNotPrepared() {
        require(!roundClosingPrepared, "NotAllowedWhenRoundClosingPrepared");
        _;
    }

    modifier onlyWhitelistedAddresses(address sender) {
        require(
            sender == owner || sportsAMM.manager().isWhitelistedAddress(sender, ISportsAMMV2Manager.Role.MARKET_RESOLVING),
            "InvalidSender"
        );
        _;
    }

    /* ========== EVENTS ========== */

    event PoolStarted();
    event RoundPoolCreated(uint round, address roundPool);
    event Deposited(address user, uint amount, uint round);
    event WithdrawalRequested(address user);

    event SafeBoxSharePaid(uint safeBoxShare, uint safeBoxAmount);
    event RoundClosingPrepared(uint round);
    event Claimed(address user, uint amount);
    event RoundClosingBatchProcessed(uint round, uint batchSize);
    event RoundClosed(uint round, uint roundPnL);

    event PoolRoundMastercopyChanged(address newMastercopy);
    event SportAMMChanged(address sportAMM);
    event DefaultLiquidityProviderChanged(address newProvider);

    event RoundLengthChanged(uint roundLength);
    event MaxAllowedDepositChanged(uint maxAllowedDeposit);
    event MinAllowedDepositChanged(uint minAllowedDeposit);
    event MaxAllowedUsersChanged(uint maxAllowedUsersChanged);
    event UtilizationRateChanged(uint utilizationRate);
    event SetSafeBoxParams(address safeBox, uint safeBoxImpact);

    event TicketMigratedToNextRound(address ticket, uint oldRound, uint newRound);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Pausable
    struct PausableStorage {
        bool _paused;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;

    function _getPausableStorage() private pure returns (PausableStorage storage $) {
        assembly {
            $.slot := PausableStorageLocation
        }
    }

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        PausableStorage storage $ = _getPausableStorage();
        return $._paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = false;
        emit Unpaused(_msgSender());
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Clones.sol)

pragma solidity ^0.8.20;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 */
library Clones {
    /**
     * @dev A clone instance deployment failed.
     */
    error ERC1167FailedCreateClone();

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create(0, 0x09, 0x37)
        }
        if (instance == address(0)) {
            revert ERC1167FailedCreateClone();
        }
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create2(0, 0x09, 0x37, salt)
        }
        if (instance == address(0)) {
            revert ERC1167FailedCreateClone();
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(add(ptr, 0x38), deployer)
            mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
            mstore(add(ptr, 0x14), implementation)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
            mstore(add(ptr, 0x58), salt)
            mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
            predicted := keccak256(add(ptr, 0x43), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt
    ) internal view returns (address predicted) {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @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.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
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].
     *
     * CAUTION: See Security Considerations above.
     */
    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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // 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 cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @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 or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * 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.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @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`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // 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 FailedInnerCall();
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

interface IAddressManager {
    struct Addresses {
        address safeBox;
        address referrals;
        address stakingThales;
        address multiCollateralOnOffRamp;
        address pyth;
        address speedMarketsAMM;
    }

    function safeBox() external view returns (address);

    function referrals() external view returns (address);

    function stakingThales() external view returns (address);

    function multiCollateralOnOffRamp() external view returns (address);

    function pyth() external view returns (address);

    function speedMarketsAMM() external view returns (address);

    function getAddresses() external view returns (Addresses memory);

    function getAddresses(string[] calldata _contractNames) external view returns (address[] memory contracts);

    function getAddress(string memory _contractName) external view returns (address contract_);

    function checkIfContractExists(string memory _contractName) external view returns (bool contractExists);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

interface IPriceFeed {
    // Structs
    struct RateAndUpdatedTime {
        uint216 rate;
        uint40 time;
    }

    // Mutative functions
    function addAggregator(bytes32 currencyKey, address aggregatorAddress) external;

    function removeAggregator(bytes32 currencyKey) external;

    // Views

    function rateForCurrency(bytes32 currencyKey) external view returns (uint);

    function rateAndUpdatedTime(bytes32 currencyKey) external view returns (uint rate, uint time);

    function getRates() external view returns (uint[] memory);

    function getCurrencies() external view returns (bytes32[] memory);
}

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

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
// internal
import "../../interfaces/ISportsAMMV2Manager.sol";
import "../../interfaces/ISportsAMMV2.sol";

contract Ticket {
    using SafeERC20 for IERC20;
    uint private constant ONE = 1e18;

    enum Phase {
        Trading,
        Maturity,
        Expiry
    }

    struct MarketData {
        bytes32 gameId;
        uint16 sportId;
        uint16 typeId;
        uint maturity;
        uint8 status;
        int24 line;
        uint24 playerId;
        uint8 position;
        uint odd;
        ISportsAMMV2.CombinedPosition[] combinedPositions;
    }

    struct TicketInit {
        MarketData[] _markets;
        uint _buyInAmount;
        uint _fees;
        uint _totalQuote;
        address _sportsAMM;
        address _ticketOwner;
        IERC20 _collateral;
        uint _expiry;
        bool _isLive;
        uint8 _systemBetDenominator;
        bool _isSGP;
    }

    ISportsAMMV2 public sportsAMM;
    address public ticketOwner;
    IERC20 public collateral;

    uint public buyInAmount;
    uint public fees;
    uint public totalQuote;
    uint public numOfMarkets;
    uint public expiry;
    uint public createdAt;

    bool public resolved;
    bool public paused;
    bool public initialized;
    bool public cancelled;

    bool public isLive;

    mapping(uint => MarketData) public markets;

    uint public finalPayout;

    bool public isSystem;

    uint8 public systemBetDenominator;

    bool public isSGP;

    bool public isMarkedAsLost;

    uint public expectedFinalPayout;

    /* ========== CONSTRUCTOR and INITIALIZERS========== */

    /// @notice initialize the ticket contract
    /// @param params all parameters for Init
    function initialize(TicketInit calldata params) external {
        require(!initialized, "Ticket already initialized");
        initialized = true;
        sportsAMM = ISportsAMMV2(params._sportsAMM);
        numOfMarkets = params._markets.length;
        for (uint i = 0; i < numOfMarkets; i++) {
            markets[i] = params._markets[i];
        }
        buyInAmount = params._buyInAmount;
        fees = params._fees;
        totalQuote = params._totalQuote;
        ticketOwner = params._ticketOwner;
        collateral = params._collateral;
        expiry = params._expiry;
        isLive = params._isLive;
        createdAt = block.timestamp;
        systemBetDenominator = params._systemBetDenominator;
        isSystem = systemBetDenominator > 0;
        isSGP = params._isSGP;
    }

    /**
     * @notice Sets the expected final payout amount for this ticket.
     * @dev
     * - Can only be called by the SportsAMM contract.
     * - This value represents the total amount of collateral (including fees)
     *   that was initially funded to the ticket upon creation.
     * - Used later in `exercise()` to prevent manipulation or overfunding attacks,
     *   ensuring payout calculations rely only on the original committed collateral
     *   and not on the current token balance of the contract.
     * - Once set, this value should remain constant throughout the ticket lifecycle.
     *
     * @param amount The total expected collateral amount that should be held by this ticket.
     *               Must include both user buy-in and fees.
     *
     * Emits a {ExpectedFinalPayoutSet} event.
     */
    function setExpectedFinalPayout(uint amount) external onlyAMM {
        expectedFinalPayout = amount;
        emit ExpectedFinalPayoutSet(amount);
    }

    /* ========== EXTERNAL READ FUNCTIONS ========== */

    /// @notice checks if the user lost the ticket
    /// @return isTicketLost true/false
    function isTicketLost() public view returns (bool) {
        if (isMarkedAsLost) {
            return true;
        } else {
            uint lostMarketsCount = 0;
            for (uint i = 0; i < numOfMarkets; i++) {
                (bool isMarketResolved, bool isWinningMarketPosition) = sportsAMM
                    .resultManager()
                    .isMarketResolvedAndPositionWinning(
                        markets[i].gameId,
                        markets[i].typeId,
                        markets[i].playerId,
                        markets[i].line,
                        markets[i].position,
                        markets[i].combinedPositions
                    );
                if (isMarketResolved && !isWinningMarketPosition) {
                    if (!isSystem) {
                        return true;
                    } else {
                        lostMarketsCount++;
                        if (lostMarketsCount > (numOfMarkets - systemBetDenominator)) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    }

    /// @notice checks are all markets of the ticket resolved
    /// @return areAllMarketsResolved true/false
    function areAllMarketsResolved() public view returns (bool) {
        for (uint i = 0; i < numOfMarkets; i++) {
            if (
                !sportsAMM.resultManager().isMarketResolved(
                    markets[i].gameId,
                    markets[i].typeId,
                    markets[i].playerId,
                    markets[i].line,
                    markets[i].combinedPositions
                )
            ) {
                return false;
            }
        }
        return true;
    }

    /// @notice checks if the user won the ticket
    /// @return hasUserWon true/false
    function isUserTheWinner() external view returns (bool hasUserWon) {
        hasUserWon = _isUserTheWinner();
    }

    /// @notice checks if the ticket ready to be exercised
    /// @return isExercisable true/false
    function isTicketExercisable() public view returns (bool isExercisable) {
        isExercisable = !resolved && (areAllMarketsResolved() || isTicketLost());
    }

    /// @notice gets current phase of the ticket
    /// @return phase ticket phase
    function phase() public view returns (Phase) {
        return
            isTicketExercisable() || resolved ? ((expiry < block.timestamp) ? Phase.Expiry : Phase.Maturity) : Phase.Trading;
    }

    /// @notice gets combined positions of the game
    /// @return combinedPositions game combined positions
    function getCombinedPositions(
        uint _marketIndex
    ) public view returns (ISportsAMMV2.CombinedPosition[] memory combinedPositions) {
        return markets[_marketIndex].combinedPositions;
    }

    /// @notice return the payout for this ticket
    /// @return systemBetPayout the payout for this ticket
    function getSystemBetPayout() external view returns (uint systemBetPayout) {
        systemBetPayout = _getSystemBetPayout();
    }

    /* ========== EXTERNAL WRITE FUNCTIONS ========== */

    /// @notice exercise ticket
    function exercise(address _exerciseCollateral) external onlyAMM notPaused returns (uint) {
        bool isExercisable = isTicketExercisable();
        require(isExercisable, "Ticket not exercisable yet");
        require(expectedFinalPayout > 0, "Expected final payout not set");

        uint payoutWithFees = expectedFinalPayout;
        uint payout = payoutWithFees - fees;
        bool isCancelled = false;

        if (_isUserTheWinner()) {
            finalPayout = payout;
            isCancelled = true;
            for (uint i = 0; i < numOfMarkets; i++) {
                bool isCancelledMarketPosition = sportsAMM.resultManager().isCancelledMarketPosition(
                    markets[i].gameId,
                    markets[i].typeId,
                    markets[i].playerId,
                    markets[i].line,
                    markets[i].position,
                    markets[i].combinedPositions
                );
                if (isCancelledMarketPosition) {
                    if (isSGP) {
                        isCancelled = true;
                        break;
                    }
                    finalPayout = (finalPayout * markets[i].odd) / ONE;
                } else {
                    isCancelled = false;
                }
            }

            finalPayout = isCancelled ? buyInAmount : (isSystem ? _getSystemBetPayout() : finalPayout);

            collateral.safeTransfer(
                _exerciseCollateral == address(0) || _exerciseCollateral == address(collateral)
                    ? address(ticketOwner)
                    : address(sportsAMM),
                finalPayout
            );
        }

        // if user is lost or if the user payout was less than anticipated due to cancelled games, send the remainder to AMM
        uint balance = collateral.balanceOf(address(this));
        if (balance != 0) {
            collateral.safeTransfer(address(sportsAMM), balance);
        }

        _resolve(!isTicketLost(), isCancelled);
        return finalPayout;
    }

    /// @notice expire ticket
    function expire(address _beneficiary) external onlyAMM {
        require(phase() == Phase.Expiry, "Ticket not in expiry phase");
        require(!resolved, "Can't expire resolved ticket");
        emit Expired(_beneficiary);
        _selfDestruct(_beneficiary);
    }

    /// @notice cancel the ticket
    function cancel() external onlyAMM notPaused returns (uint) {
        finalPayout = buyInAmount;
        collateral.safeTransfer(address(ticketOwner), finalPayout);

        uint balance = collateral.balanceOf(address(this));
        if (balance != 0) {
            collateral.safeTransfer(address(sportsAMM), balance);
        }

        _resolve(true, true);
        return finalPayout;
    }

    /// @notice mark the ticket as lost
    function markAsLost() external onlyAMM notPaused returns (uint) {
        uint balance = collateral.balanceOf(address(this));
        if (balance != 0) {
            collateral.safeTransfer(address(sportsAMM), balance);
        }

        _resolve(false, false);
        isMarkedAsLost = true;
        return 0;
    }

    /// @notice withdraw collateral from the ticket
    function withdrawCollateral(address recipient) external onlyAMM {
        collateral.safeTransfer(recipient, collateral.balanceOf(address(this)));
    }

    /* ========== INTERNAL FUNCTIONS ========== */

    function _resolve(bool _hasUserWon, bool _cancelled) internal {
        resolved = true;
        cancelled = _cancelled;
        emit Resolved(_hasUserWon, _cancelled);
    }

    function _selfDestruct(address beneficiary) internal {
        uint balance = collateral.balanceOf(address(this));
        if (balance != 0) {
            collateral.safeTransfer(beneficiary, balance);
        }
    }

    function _isUserTheWinner() internal view returns (bool hasUserWon) {
        if (areAllMarketsResolved()) {
            hasUserWon = !isTicketLost();
        }
    }

    /* ========== SETTERS ========== */

    function setPaused(bool _paused) external {
        require(msg.sender == address(sportsAMM.manager()), "Invalid sender");
        if (paused == _paused) return;
        paused = _paused;
        emit PauseUpdated(_paused);
    }

    /* ========== SYSTEM BET UTILS ========== */

    function _getSystemBetPayout() internal view returns (uint systemBetPayout) {
        if (isSystem) {
            uint8[][] memory systemCombinations = sportsAMM.riskManager().generateCombinations(
                uint8(numOfMarkets),
                systemBetDenominator
            );
            uint totalCombinations = systemCombinations.length;
            uint buyinPerCombination = ((buyInAmount * ONE) / totalCombinations) / ONE;

            bool[] memory winningMarkets = new bool[](numOfMarkets);
            bool[] memory cancelledMarkets = new bool[](numOfMarkets);

            for (uint i = 0; i < numOfMarkets; i++) {
                if (
                    !sportsAMM.resultManager().isMarketResolved(
                        markets[i].gameId,
                        markets[i].typeId,
                        markets[i].playerId,
                        markets[i].line,
                        markets[i].combinedPositions
                    )
                ) {
                    return 0;
                }
                winningMarkets[i] = sportsAMM.resultManager().isWinningMarketPosition(
                    markets[i].gameId,
                    markets[i].typeId,
                    markets[i].playerId,
                    markets[i].line,
                    markets[i].position,
                    markets[i].combinedPositions
                );

                cancelledMarkets[i] = sportsAMM.resultManager().isCancelledMarketPosition(
                    markets[i].gameId,
                    markets[i].typeId,
                    markets[i].playerId,
                    markets[i].line,
                    markets[i].position,
                    markets[i].combinedPositions
                );
            }

            // Loop through each stored combination
            for (uint i = 0; i < totalCombinations; i++) {
                uint8[] memory currentCombination = systemCombinations[i];

                uint combinationQuote = ONE;

                for (uint j = 0; j < currentCombination.length; j++) {
                    uint8 marketIndex = currentCombination[j];
                    if (winningMarkets[marketIndex]) {
                        if (!cancelledMarkets[marketIndex]) {
                            combinationQuote = (combinationQuote * markets[marketIndex].odd) / ONE;
                        }
                    } else {
                        combinationQuote = 0;
                        break;
                    }
                }

                if (combinationQuote > 0) {
                    uint combinationPayout = (buyinPerCombination * ONE) / combinationQuote;
                    systemBetPayout += combinationPayout;
                }
            }

            uint maxPayout = (buyInAmount * ONE) / totalQuote;
            if (systemBetPayout > maxPayout) {
                systemBetPayout = maxPayout;
            }
        }
    }

    /* ========== MODIFIERS ========== */

    modifier onlyAMM() {
        require(msg.sender == address(sportsAMM), "Only the AMM may perform these methods");
        _;
    }

    modifier notPaused() {
        require(!paused, "Market paused");
        _;
    }

    /* ========== EVENTS ========== */

    event Resolved(bool isUserTheWinner, bool cancelled);
    event Expired(address beneficiary);
    event PauseUpdated(bool paused);
    event ExpectedFinalPayoutSet(uint amount);
}

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

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

contract SportsAMMV2LiquidityPoolRound {
    /* ========== LIBRARIES ========== */
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */

    // the adddress of the LP contract
    address public liquidityPool;

    // the adddress of collateral that LP accepts
    IERC20 public collateral;

    // the round number
    uint public round;

    // the round start time
    uint public roundStartTime;

    // the round end time
    uint public roundEndTime;

    // initialized flag
    bool public initialized;

    /* ========== CONSTRUCTOR ========== */

    /// @notice initialize the storage in the contract with the parameters
    /// @param _liquidityPool the adddress of the LP contract
    /// @param _collateral the adddress of collateral that LP accepts
    /// @param _round the round number
    /// @param _roundStartTime the round start time
    /// @param _roundEndTime the round end time
    function initialize(
        address _liquidityPool,
        IERC20 _collateral,
        uint _round,
        uint _roundStartTime,
        uint _roundEndTime
    ) external {
        require(!initialized, "Already initialized");
        initialized = true;
        liquidityPool = _liquidityPool;
        collateral = _collateral;
        round = _round;
        roundStartTime = _roundStartTime;
        roundEndTime = _roundEndTime;
        collateral.approve(_liquidityPool, type(uint256).max);
    }

    /// @notice update round times
    /// @param _roundStartTime the round start time
    /// @param _roundEndTime the round end time
    function updateRoundTimes(uint _roundStartTime, uint _roundEndTime) external onlyLiquidityPool {
        roundStartTime = _roundStartTime;
        roundEndTime = _roundEndTime;
        emit RoundTimesUpdated(_roundStartTime, _roundEndTime);
    }

    modifier onlyLiquidityPool() {
        require(msg.sender == liquidityPool, "Only LP may perform this method");
        _;
    }

    event RoundTimesUpdated(uint roundStartTime, uint roundEndTime);
}

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

import "./IProxyBetting.sol";

interface IFreeBetsHolder is IProxyBetting {
    function confirmLiveTrade(bytes32 requestId, address _createdTicket, uint _buyInAmount, address _collateral) external;
    function confirmSGPTrade(bytes32 requestId, address _createdTicket, uint _buyInAmount, address _collateral) external;

    function balancePerUserAndCollateral(address user, address collateral) external view returns (uint);
    function freeBetExpiration(address user, address collateral) external view returns (uint);
    function freeBetExpirationUpgrade() external view returns (uint);
    function freeBetExpirationPeriod() external view returns (uint);
}

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

interface IProxyBetting {
    function getActiveTicketsPerUser(uint _index, uint _pageSize, address _user) external view returns (address[] memory);
    function numOfActiveTicketsPerUser(address _user) external view returns (uint);
    function getResolvedTicketsPerUser(uint _index, uint _pageSize, address _user) external view returns (address[] memory);
    function numOfResolvedTicketsPerUser(address _user) external view returns (uint);

    function confirmTicketResolved(address _resolvedTicket) external;
}

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../interfaces/ISportsAMMV2Manager.sol";
import "../interfaces/ISportsAMMV2ResultManager.sol";
import "../interfaces/ISportsAMMV2RiskManager.sol";
import "../interfaces/ISportsAMMV2Manager.sol";
import "../interfaces/IFreeBetsHolder.sol";
import "../interfaces/IStakingThalesBettingProxy.sol";

interface ISportsAMMV2 {
    enum TicketAction {
        Exercise,
        Cancel,
        MarkLost
    }

    struct CombinedPosition {
        uint16 typeId;
        uint8 position;
        int24 line;
    }

    struct TradeData {
        bytes32 gameId;
        uint16 sportId;
        uint16 typeId;
        uint maturity;
        uint8 status;
        int24 line;
        uint24 playerId;
        uint[] odds;
        bytes32[] merkleProof;
        uint8 position;
        CombinedPosition[][] combinedPositions;
    }

    function defaultCollateral() external view returns (IERC20);

    function manager() external view returns (ISportsAMMV2Manager);

    function resultManager() external view returns (ISportsAMMV2ResultManager);

    function safeBoxFee() external view returns (uint);

    function handleTicketResolving(address _ticket, ISportsAMMV2.TicketAction action) external;

    function riskManager() external view returns (ISportsAMMV2RiskManager);

    function freeBetsHolder() external view returns (IFreeBetsHolder);

    function stakingThalesBettingProxy() external view returns (IStakingThalesBettingProxy);

    function tradeLive(
        TradeData[] calldata _tradeData,
        uint _buyInAmount,
        uint _expectedQuote,
        address _recipient,
        address _referrer,
        address _collateral
    ) external returns (address _createdTicket);

    function trade(
        TradeData[] calldata _tradeData,
        uint _buyInAmount,
        uint _expectedQuote,
        uint _additionalSlippage,
        address _referrer,
        address _collateral,
        bool _isEth
    ) external returns (address _createdTicket);

    function tradeSystemBet(
        TradeData[] calldata _tradeData,
        uint _buyInAmount,
        uint _expectedQuote,
        uint _additionalSlippage,
        address _referrer,
        address _collateral,
        bool _isEth,
        uint8 _systemBetDenominator
    ) external returns (address _createdTicket);

    function tradeSGP(
        ISportsAMMV2.TradeData[] calldata _tradeData,
        uint _buyInAmount,
        uint _approvedQuote,
        address _recipient,
        address _referrer,
        address _collateral
    ) external returns (address _createdTicket);

    function rootPerGame(bytes32 game) external view returns (bytes32);

    function getRootsPerGames(bytes32[] calldata _games) external view returns (bytes32[] memory _roots);

    function paused() external view returns (bool);
}

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

import "./ISportsAMMV2.sol";

interface ISportsAMMV2Manager {
    enum Role {
        ROOT_SETTING,
        RISK_MANAGING,
        MARKET_RESOLVING,
        TICKET_PAUSER
    }

    function isWhitelistedAddress(address _address, Role role) external view returns (bool);

    function decimals() external view returns (uint);

    function feeToken() external view returns (address);

    function isActiveTicket(address _ticket) external view returns (bool);

    function getActiveTickets(uint _index, uint _pageSize) external view returns (address[] memory);

    function numOfActiveTickets() external view returns (uint);

    function getActiveTicketsPerUser(uint _index, uint _pageSize, address _user) external view returns (address[] memory);

    function numOfActiveTicketsPerUser(address _user) external view returns (uint);

    function getResolvedTicketsPerUser(uint _index, uint _pageSize, address _user) external view returns (address[] memory);

    function numOfResolvedTicketsPerUser(address _user) external view returns (uint);

    function getTicketsPerGame(uint _index, uint _pageSize, bytes32 _gameId) external view returns (address[] memory);

    function numOfTicketsPerGame(bytes32 _gameId) external view returns (uint);

    function isKnownTicket(address _ticket) external view returns (bool);

    function sportsAMM() external view returns (address);

    function getTicketsPerMarket(
        uint _index,
        uint _pageSize,
        bytes32 _gameId,
        uint _typeId,
        uint _playerId
    ) external view returns (address[] memory);

    function numOfTicketsPerMarket(bytes32 _gameId, uint _typeId, uint _playerId) external view returns (uint);

    function addNewKnownTicket(ISportsAMMV2.TradeData[] memory _tradeData, address ticket, address user) external;

    function resolveKnownTicket(address ticket, address ticketOwner) external;

    function expireKnownTicket(address ticket, address ticketOwner) external;

    function isSystemTicket(address _ticket) external view returns (bool);

    function isSGPTicket(address _ticket) external view returns (bool);
}

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

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

interface ISportsAMMV2ResultManager {
    enum MarketPositionStatus {
        Open,
        Cancelled,
        Winning,
        Losing
    }

    function isMarketResolved(
        bytes32 _gameId,
        uint16 _typeId,
        uint24 _playerId,
        int24 _line,
        ISportsAMMV2.CombinedPosition[] memory combinedPositions
    ) external view returns (bool isResolved);

    function getMarketPositionStatus(
        bytes32 _gameId,
        uint16 _typeId,
        uint24 _playerId,
        int24 _line,
        uint _position,
        ISportsAMMV2.CombinedPosition[] memory _combinedPositions
    ) external view returns (MarketPositionStatus status);

    function isWinningMarketPosition(
        bytes32 _gameId,
        uint16 _typeId,
        uint24 _playerId,
        int24 _line,
        uint _position,
        ISportsAMMV2.CombinedPosition[] memory _combinedPositions
    ) external view returns (bool isWinning);

    function isCancelledMarketPosition(
        bytes32 _gameId,
        uint16 _typeId,
        uint24 _playerId,
        int24 _line,
        uint _position,
        ISportsAMMV2.CombinedPosition[] memory _combinedPositions
    ) external view returns (bool isCancelled);

    function getResultsPerMarket(
        bytes32 _gameId,
        uint16 _typeId,
        uint24 _playerId
    ) external view returns (int24[] memory results);

    function resultTypePerMarketType(uint _typeId) external view returns (uint8 marketType);

    function isMarketResolvedAndPositionWinning(
        bytes32 _gameId,
        uint16 _typeId,
        uint24 _playerId,
        int24 _line,
        uint _position,
        ISportsAMMV2.CombinedPosition[] memory _combinedPositions
    ) external view returns (bool isResolved, bool isWinning);

    function setResultsPerMarkets(
        bytes32[] memory _gameIds,
        uint16[] memory _typeIds,
        uint24[] memory _playerIds,
        int24[][] memory _results
    ) external;

    function isGameCancelled(bytes32 _gameId) external view returns (bool);

    function cancelGames(bytes32[] memory _gameIds) external;

    function cancelMarkets(
        bytes32[] memory _gameIds,
        uint16[] memory _typeIds,
        uint24[] memory _playerIds,
        int24[] memory _lines
    ) external;

    function cancelMarket(bytes32 _gameId, uint16 _typeId, uint24 _playerId, int24 _line) external;

    function cancelGame(bytes32 _gameId) external;
}

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

import "./ISportsAMMV2.sol";

interface ISportsAMMV2RiskManager {
    struct TypeCap {
        uint typeId;
        uint cap;
    }

    struct CapData {
        uint capPerSport;
        uint capPerChild;
        TypeCap[] capPerType;
    }

    struct DynamicLiquidityData {
        uint cutoffTimePerSport;
        uint cutoffDividerPerSport;
    }

    struct RiskData {
        uint sportId;
        CapData capData;
        uint riskMultiplierPerSport;
        DynamicLiquidityData dynamicLiquidityData;
    }

    enum RiskStatus {
        NoRisk,
        OutOfLiquidity,
        InvalidCombination
    }

    function minBuyInAmount() external view returns (uint);

    function maxTicketSize() external view returns (uint);

    function maxSupportedAmount() external view returns (uint);

    function maxSupportedOdds() external view returns (uint);

    function maxAllowedSystemCombinations() external view returns (uint);

    function expiryDuration() external view returns (uint);

    function liveTradingPerSportAndTypeEnabled(uint _sportId, uint _typeId) external view returns (bool _enabled);

    function calculateCapToBeUsed(
        bytes32 _gameId,
        uint16 _sportId,
        uint16 _typeId,
        uint24 _playerId,
        int24 _line,
        uint _maturity,
        bool _isLive
    ) external view returns (uint cap);

    function calculateTotalRiskOnGame(
        bytes32 _gameId,
        uint16 _sportId,
        uint _maturity
    ) external view returns (uint totalRisk);

    function checkRisks(
        ISportsAMMV2.TradeData[] memory _tradeData,
        uint _buyInAmount,
        bool _isLive,
        uint8 _systemBetDenominator
    ) external view returns (ISportsAMMV2RiskManager.RiskStatus riskStatus, bool[] memory isMarketOutOfLiquidity);

    function checkLimits(
        uint _buyInAmount,
        uint _totalQuote,
        uint _payout,
        uint _expectedPayout,
        uint _additionalSlippage,
        uint _ticketSize
    ) external view;

    function spentOnGame(bytes32 _gameId) external view returns (uint);

    function riskPerMarketTypeAndPosition(
        bytes32 _gameId,
        uint _typeId,
        uint _playerId,
        uint _position
    ) external view returns (int);

    function checkAndUpdateRisks(
        ISportsAMMV2.TradeData[] memory _tradeData,
        uint _buyInAmount,
        uint _payout,
        bool _isLive,
        uint8 _systemBetDenominator,
        bool _isSGP
    ) external;

    function verifyMerkleTree(ISportsAMMV2.TradeData memory _marketTradeData, bytes32 _rootPerGame) external pure;

    function batchVerifyMerkleTree(
        ISportsAMMV2.TradeData[] memory _marketTradeData,
        bytes32[] memory _rootPerGame
    ) external pure;

    function isSportIdFuture(uint16 _sportsId) external view returns (bool);

    function sgpOnSportIdEnabled(uint16 _sportsId) external view returns (bool);

    function getMaxSystemBetPayout(
        ISportsAMMV2.TradeData[] memory _tradeData,
        uint8 _systemBetDenominator,
        uint _buyInAmount,
        uint _addedPayoutPercentage
    ) external view returns (uint systemBetPayout, uint systemBetQuote);

    function generateCombinations(uint8 n, uint8 k) external pure returns (uint8[][] memory);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./IProxyBetting.sol";

interface IStakingThalesBettingProxy is IProxyBetting {
    function preConfirmLiveTrade(bytes32 requestId, uint _buyInAmount) external;
    function confirmLiveTrade(bytes32 requestId, address _createdTicket, uint _buyInAmount) external;
    function preConfirmSGPTrade(bytes32 requestId, uint _buyInAmount) external;
    function confirmSGPTrade(bytes32 requestId, address _createdTicket, uint _buyInAmount) external;
}

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

// Clone of syntetix contract without constructor
contract ProxyOwned {
    address public owner;
    address public nominatedOwner;
    bool private _initialized;
    bool private _transferredAtInit;

    function setOwner(address _owner) public {
        require(_owner != address(0), "Owner address cannot be 0");
        require(!_initialized, "Already initialized, use nominateNewOwner");
        _initialized = true;
        owner = _owner;
        emit OwnerChanged(address(0), _owner);
    }

    function nominateNewOwner(address _owner) external onlyOwner {
        nominatedOwner = _owner;
        emit OwnerNominated(_owner);
    }

    function acceptOwnership() external {
        require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership");
        emit OwnerChanged(owner, nominatedOwner);
        owner = nominatedOwner;
        nominatedOwner = address(0);
    }

    function transferOwnershipAtInit(address proxyAddress) external onlyOwner {
        require(proxyAddress != address(0), "Invalid address");
        require(!_transferredAtInit, "Already transferred");
        owner = proxyAddress;
        _transferredAtInit = true;
        emit OwnerChanged(owner, proxyAddress);
    }

    modifier onlyOwner() {
        _onlyOwner();
        _;
    }

    function _onlyOwner() private view {
        require(msg.sender == owner, "Only the contract owner may perform this action");
    }

    event OwnerNominated(address newOwner);
    event OwnerChanged(address oldOwner, address newOwner);
}

File 22 of 22 : ProxyReentrancyGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the `nonReentrant` modifier
 * available, which can be aplied 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.
 */
contract ProxyReentrancyGuard {
    /// @dev counter to allow mutex lock with only one SSTORE operation
    uint256 private _guardCounter;
    bool private _initialized;

    function initNonReentrant() public {
        require(!_initialized, "Already initialized");
        _initialized = true;
        _guardCounter = 1;
    }

    /**
     * @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 make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _guardCounter += 1;
        uint256 localCounter = _guardCounter;
        _;
        require(localCounter == _guardCounter, "ReentrancyGuard: reentrant call");
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 100
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"ERC1167FailedCreateClone","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newProvider","type":"address"}],"name":"DefaultLiquidityProviderChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxAllowedDeposit","type":"uint256"}],"name":"MaxAllowedDepositChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxAllowedUsersChanged","type":"uint256"}],"name":"MaxAllowedUsersChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minAllowedDeposit","type":"uint256"}],"name":"MinAllowedDepositChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newMastercopy","type":"address"}],"name":"PoolRoundMastercopyChanged","type":"event"},{"anonymous":false,"inputs":[],"name":"PoolStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"roundPnL","type":"uint256"}],"name":"RoundClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"batchSize","type":"uint256"}],"name":"RoundClosingBatchProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"}],"name":"RoundClosingPrepared","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"roundLength","type":"uint256"}],"name":"RoundLengthChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"address","name":"roundPool","type":"address"}],"name":"RoundPoolCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"safeBoxShare","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"safeBoxAmount","type":"uint256"}],"name":"SafeBoxSharePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"safeBox","type":"address"},{"indexed":false,"internalType":"uint256","name":"safeBoxImpact","type":"uint256"}],"name":"SetSafeBoxParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sportAMM","type":"address"}],"name":"SportAMMChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"ticket","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldRound","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newRound","type":"uint256"}],"name":"TicketMigratedToNextRound","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"utilizationRate","type":"uint256"}],"name":"UtilizationRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"WithdrawalRequested","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressManager","outputs":[{"internalType":"contract IAddressManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allocationPerRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"balancesPerRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"canCloseCurrentRound","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"closeRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collateral","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralKey","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"ticket","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"commitTrade","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_roundA","type":"uint256"},{"internalType":"uint256","name":"_roundB","type":"uint256"}],"name":"cumulativePnLBetweenRounds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"cumulativeProfitAndLoss","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultLiquidityProvider","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exerciseDefaultRoundTicketsReadyToBeExercised","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_batchSize","type":"uint256"}],"name":"exerciseDefaultRoundTicketsReadyToBeExercisedBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exerciseTicketsReadyToBeExercised","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_batchSize","type":"uint256"}],"name":"exerciseTicketsReadyToBeExercisedBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"firstRoundStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCollateralPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_round","type":"uint256"}],"name":"getNumberOfTradingTicketsPerRound","outputs":[{"internalType":"uint256","name":"numOfTickets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_round","type":"uint256"}],"name":"getRoundEndTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_round","type":"uint256"}],"name":"getRoundStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ticket","type":"address"},{"internalType":"uint256","name":"_round","type":"uint256"},{"internalType":"uint256","name":"_startIndex","type":"uint256"},{"internalType":"uint256","name":"_endIndex","type":"uint256"}],"name":"getTicketIndexInTicketRound","outputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"bool","name":"found","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ticket","type":"address"}],"name":"getTicketPool","outputs":[{"internalType":"address","name":"roundPool","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_ticket","type":"address"}],"name":"getTicketRound","outputs":[{"internalType":"uint256","name":"ticketRound","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUsersCountInCurrentRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hasDefaultRoundTicketsReadyToBeExercised","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hasTicketsReadyToBeExercised","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initNonReentrant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_sportsAMM","type":"address"},{"internalType":"address","name":"_addressManager","type":"address"},{"internalType":"contract IERC20","name":"_collateral","type":"address"},{"internalType":"uint256","name":"_roundLength","type":"uint256"},{"internalType":"uint256","name":"_maxAllowedDeposit","type":"uint256"},{"internalType":"uint256","name":"_minDepositAmount","type":"uint256"},{"internalType":"uint256","name":"_maxAllowedUsers","type":"uint256"},{"internalType":"uint256","name":"_utilizationRate","type":"uint256"},{"internalType":"address","name":"_safeBox","type":"address"},{"internalType":"uint256","name":"_safeBoxImpact","type":"uint256"},{"internalType":"bytes32","name":"_collateralKey","type":"bytes32"}],"internalType":"struct SportsAMMV2LiquidityPool.InitParams","name":"params","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"isTradingTicketInARound","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"isUserLPing","outputs":[{"internalType":"bool","name":"isUserInLP","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxAllowedDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxAllowedUsers","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tickets","type":"address[]"},{"internalType":"uint256","name":"_newRound","type":"uint256"},{"internalType":"uint256[]","name":"_ticketsIndexInRound","type":"uint256[]"}],"name":"migrateBatchOfTicketsToAnotherRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_ticket","type":"address"},{"internalType":"uint256","name":"_newRound","type":"uint256"},{"internalType":"uint256","name":"_ticketIndexInRound","type":"uint256"}],"name":"migrateTicketToAnotherRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minDepositAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nextExerciseIndexPerRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_share","type":"uint256"}],"name":"partialWithdrawalRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolRoundMastercopy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"prepareRoundClosing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_batchSize","type":"uint256"}],"name":"processRoundClosingBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"profitAndLossPerRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"round","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roundClosingPrepared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roundLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"roundPerTicket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"roundPools","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"safeBox","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"safeBoxImpact","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_defaultLiquidityProvider","type":"address"}],"name":"setDefaultLiquidityProvider","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxAllowedDeposit","type":"uint256"}],"name":"setMaxAllowedDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxAllowedUsers","type":"uint256"}],"name":"setMaxAllowedUsers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minDepositAmount","type":"uint256"}],"name":"setMinAllowedDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_setPausing","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_poolRoundMastercopy","type":"address"}],"name":"setPoolRoundMastercopy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_roundLength","type":"uint256"}],"name":"setRoundLength","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_safeBox","type":"address"},{"internalType":"uint256","name":"_safeBoxImpact","type":"uint256"}],"name":"setSafeBoxParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISportsAMMV2","name":"_sportsAMM","type":"address"}],"name":"setSportsAMM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_utilizationRate","type":"uint256"}],"name":"setUtilizationRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sportsAMM","outputs":[{"internalType":"contract ISportsAMMV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"start","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"started","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"ticketAlreadyExercisedInRound","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalDeposited","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"tradingTicketsPerRound","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"proxyAddress","type":"address"}],"name":"transferOwnershipAtInit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_ticket","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"transferToPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"userInRound","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"usersCurrentlyInPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"usersPerRound","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"usersProcessedInRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"utilizationRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawalRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"withdrawalRequested","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"withdrawalShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50615e6180620000216000396000f3fe608060405234801561001057600080fd5b506004361061048b5760003560e01c80636c321c8a11610262578063c9f4ff4611610151578063ddc6ac23116100ce578063e95d39ca11610092578063e95d39ca14610a71578063ebc7977214610a84578063ee161cce14610a8c578063f61fcb8b14610a94578063f7683bbc14610ab4578063ff50abdc14610abc57600080fd5b8063ddc6ac2314610a28578063ddcc8fe914610a3b578063e278fe6f14610a4e578063e81e52ee14610a56578063e8362b7714610a6957600080fd5b8063d7efa12911610115578063d7efa129146109c9578063d8dfeb45146109dc578063d95ad45c146109ef578063db7e364814610a02578063db7f92d414610a1557600080fd5b8063c9f4ff4614610989578063d03c02731461099c578063d27c0797146109a4578063d69fb668146109ad578063d728e910146109b657600080fd5b80639bd2e61b116101df578063b9b1be8b116101a3578063b9b1be8b1461093a578063bdcc22e91461094d578063be9a655514610956578063c3b83f5f1461095e578063c99252881461097157600080fd5b80639bd2e61b146108d0578063a6644f96146108e3578063a8df539f14610911578063b562a1ab1461091e578063b6b55f251461092757600080fd5b80637fa946d9116102265780637fa946d91461086c5780638b649b941461088c5780638b844412146108955780638c54c8121461089d5780638da5cb5b146108bd57600080fd5b80636c321c8a1461081557806374094edd1461081e57806377332fc51461083e57806379ba5097146108515780637a1e0aa81461085957600080fd5b80634218c4d81161037e5780635c7b396e116102fb578063634e0d97116102bf578063634e0d97146107a1578063645006ca146107cf57806365e0e725146107d85780636685fdc2146107eb578063681312f51461080257600080fd5b80635c7b396e146107345780635c975abb1461073d5780635ddd3e8314610745578063610589e1146107705780636131dc711461077957600080fd5b80634d549a42116103425780634d549a42146106e057806353a47bb7146106f357806353e8bdb714610706578063582ab2f91461070e57806358c09cc01461072157600080fd5b80634218c4d8146106695780634651f0801461067157806348663e951461069a5780634a96fc84146106ad5780634ae7937f146106c057600080fd5b80631daae1731161040c578063336d30ed116103d0578063336d30ed146105fd578063343e4f9f1461061d5780633ab76e9f146106305780633b92d7581461064357806340774ff61461065657600080fd5b80631daae1731461056d5780631f2698ab146105a0578063202ffce8146105b457806327c28442146105c7578063311c56df146105f557600080fd5b8063146ca53111610453578063146ca531146105225780631627540c1461052b57806316c38b3c1461053e5780631b2a52d8146105515780631baa88561461056457600080fd5b806303d868db1461049057806309b17b3d146104b957806312b19a13146104ce57806313af4035146104ef578063145dee7d14610502575b600080fd5b6104a361049e366004615572565b610ac5565b6040516104b09190615594565b60405180910390f35b6104cc6104c73660046155a8565b610afd565b005b6104e16104dc3660046155c1565b610da3565b6040519081526020016104b0565b6104cc6104fd3660046155ef565b610dd1565b6104e16105103660046155c1565b6000908152600f602052604090205490565b6104e160055481565b6104cc6105393660046155ef565b610eed565b6104cc61054c36600461561a565b610f40565b6104cc61055f3660046155c1565b610f60565b6104e160075481565b61059061057b3660046155ef565b600d6020526000908152604090205460ff1681565b60405190151581526020016104b0565b60045461059090600160a01b900460ff1681565b6104cc6105c23660046155c1565b6114a8565b6105906105d5366004615637565b601160209081526000928352604080842090915290825290205460ff1681565b6104cc6114b9565b6104e161060b3660046155c1565b60146020526000908152604090205481565b6104a361062b366004615572565b6116c9565b6021546104a3906001600160a01b031681565b6019546104a3906001600160a01b031681565b6104cc6106643660046155c1565b6116e5565b6104cc6116f6565b6104a361067f3660046155c1565b6008602052600090815260409020546001600160a01b031681565b601f546104a3906001600160a01b031681565b6104cc6106bb3660046155c1565b61170a565b6104e16106ce3660046155c1565b600c6020526000908152604090205481565b6104cc6106ee3660046155ef565b61177d565b6001546104a3906001600160a01b031681565b6104cc6117f7565b6104cc61071c366004615667565b61182d565b6104cc61072f36600461569c565b6119c1565b6104e1601d5481565b610590611dc4565b6104e1610753366004615637565b600b60209081526000928352604080842090915290825290205481565b6104e160175481565b61078c6107873660046156c8565b611dd9565b604080519283529015156020830152016104b0565b6105906107af366004615637565b600a60209081526000928352604080842090915290825290205460ff1681565b6104e160165481565b6104cc6107e63660046155ef565b611e8a565b6005546000908152600960205260409020546104e1565b6104cc6108103660046155c1565b611f03565b6104e1601e5481565b6104e161082c3660046155c1565b60136020526000908152604090205481565b6104a361084c3660046155ef565b611f95565b6104cc611fc4565b6104cc61086736600461569c565b61209c565b6104e161087a3660046155c1565b60236020526000908152604090205481565b6104e160065481565b6104cc6120ae565b6104e16108ab3660046155ef565b60126020526000908152604090205481565b6000546104a3906001600160a01b031681565b6104cc6108de3660046155c1565b61237e565b6105906108f1366004615637565b601060209081526000928352604080842090915290825290205460ff1681565b601c546105909060ff1681565b6104e160225481565b6104cc6109353660046155c1565b612605565b601a546104a3906001600160a01b031681565b6104e160185481565b6104cc6127e1565b6104cc61096c3660046155ef565b61296f565b6003546104a39061010090046001600160a01b031681565b6104e1610997366004615572565b612a5f565b610590612a9f565b6104e160155481565b6104e160205481565b6104cc6109c43660046157d9565b612ab0565b6104cc6109d736600461569c565b612ece565b6004546104a3906001600160a01b031681565b6105906109fd3660046155ef565b613001565b6104e1610a103660046155ef565b6130c0565b6104cc610a233660046155c1565b613377565b6104e1610a363660046155c1565b613388565b6104cc610a493660046155c1565b613399565b6104cc6133aa565b6104cc610a643660046155ef565b6137b5565b610590613940565b6104cc610a7f3660046155c1565b61394d565b6104cc61399e565b6105906139fc565b6104e1610aa23660046155ef565b600e6020526000908152604090205481565b6104e1613b45565b6104e1601b5481565b600f6020528160005260406000208181548110610ae157600080fd5b6000918252602090912001546001600160a01b03169150829050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff16600081158015610b435750825b905060008267ffffffffffffffff166001148015610b605750303b155b905081158015610b6e575080155b15610b8c5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610bb657845460ff60401b1916600160401b1785555b610bc66104fd60208801886155ef565b610bce61399e565b610bde60408701602088016155ef565b600380546001600160a01b039290921661010002610100600160a81b0319909216919091179055610c1560608701604088016155ef565b602180546001600160a01b0319166001600160a01b0392909216919091179055610c4560808701606088016155ef565b600480546001600160a01b0319166001600160a01b03929092169190911790556101608601356022556080860135600655610c8360a0870135613c3c565b610c908660c00135613c71565b610c9d8660e00135613ca6565b610cab866101000135613cdb565b610ccb610cc0610140880161012089016155ef565b876101400135613d5a565b6004546001600160a01b031663095ea7b3610cec6040890160208a016155ef565b6000196040518363ffffffff1660e01b8152600401610d0c9291906158a4565b6020604051808303816000875af1158015610d2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4f91906158bd565b5060016005558315610d9b57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050565b600654600090610db46001846158f0565b610dbe9190615903565b600754610dcb919061591a565b92915050565b6001600160a01b038116610e285760405162461bcd60e51b815260206004820152601960248201527804f776e657220616464726573732063616e6e6f74206265203603c1b60448201526064015b60405180910390fd5b600154600160a01b900460ff1615610e945760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610e1f565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b0383166001600160a01b0319909116178155604051600080516020615dcc83398151915291610ee291849061592d565b60405180910390a150565b610ef5613e07565b600180546001600160a01b0319166001600160a01b0383161790556040517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290610ee2908390615594565b610f48613e07565b80610f5857610f55613e79565b50565b610f55613ec5565b600160026000828254610f73919061591a565b9091555050600254610f83613f0c565b601c5460ff16610fa55760405162461bcd60e51b8152600401610e1f90615947565b600554600090815260096020526040902054601d5410610ffb5760405162461bcd60e51b8152602060048201526011602482015270105b1b155cd95c9cd41c9bd8d95cdcd959607a1b6044820152606401610e1f565b6000821161101b5760405162461bcd60e51b8152600401610e1f90615978565b600554600090815260086020526040812054601d546001600160a01b03909116919061104890859061591a565b60055460009081526009602052604090205490915081111561107857506005546000908152600960205260409020545b601d545b818110156114445760055460009081526009602052604081208054839081106110a7576110a761599f565b6000918252602080832090910154600554835260138252604080842054600b84528185206001600160a01b0390931680865292909352832054909350670de0b6b3a7640000916110f691615903565b61110091906159b5565b6001600160a01b0383166000908152600d602052604090205490915060ff1615801561113c575060055460009081526013602052604090205415155b1561122c5780600b60006005546001611155919061591a565b81526020019081526020016000206000846001600160a01b03166001600160a01b0316815260200190815260200160002054611191919061591a565b600b600060055460016111a4919061591a565b81526020019081526020016000206000846001600160a01b03166001600160a01b03168152602001908152602001600020819055506009600060055460016111ec919061591a565b8152602080820192909252604001600090812080546001810182559082529190200180546001600160a01b0319166001600160a01b03841617905561141e565b6001600160a01b0382166000908152600e602052604090205415611387576001600160a01b0382166000908152600e6020526040812054670de0b6b3a7640000906112779084615903565b61128191906159b5565b60045490915061129c906001600160a01b0316878584613f32565b600080516020615dec83398151915283826040516112bb9291906158a4565b60405180910390a16001600160a01b0383166000908152600d60209081526040808320805460ff19169055600e90915281208190556005546009919061130290600161591a565b8152602080820192909252604001600090812080546001810182559082529190200180546001600160a01b0319166001600160a01b03851617905561134781836158f0565b600b6000600554600161135a919061591a565b8152602080820192909252604090810160009081206001600160a01b03881682529092529020555061141e565b6000600b6000600554600161139c919061591a565b8152602080820192909252604090810160009081206001600160a01b038088168352935220919091556004546113d59116868484613f32565b6001600160a01b0382166000908152600d602052604090819020805460ff1916905551600080516020615dec8339815191529061141590849084906158a4565b60405180910390a15b601d5461142c90600161591a565b601d555081905061143c816159d7565b91505061107c565b5060055460408051918252602082018690527f2e692c8fcabe33ba22535323e79dcb54ef22dccdb8e4ebdd9f2a7ffb1a28856c910160405180910390a1505060025481146114a45760405162461bcd60e51b8152600401610e1f906159f0565b5050565b6114b0613e07565b610f5581613ca6565b6001600260008282546114cc919061591a565b9091555050600254600454600160a01b900460ff166114fd5760405162461bcd60e51b8152600401610e1f90615a27565b336000908152600d602052604090205460ff161561152d5760405162461bcd60e51b8152600401610e1f90615a4f565b6005546000908152600b602090815260408083203384529091529020546115665760405162461bcd60e51b8152600401610e1f90615a86565b600b60006005546001611579919061591a565b815260208082019290925260409081016000908120338252909252902054156115b45760405162461bcd60e51b8152600401610e1f90615ab1565b6115bc613f0c565b601c5460ff16156115df5760405162461bcd60e51b8152600401610e1f90615af6565b6005546000908152600b60209081526040808320338452909152902054601b541115611640576005546000908152600b60209081526040808320338452909152812054601b8054919290916116359084906158f0565b909155506116469050565b6000601b555b600160185461165591906158f0565b601855336000818152600d602052604090819020805460ff19166001179055517fe5892ff2a8b08efb903ffbba1f0514c1d3e22eea34dd5b89cf30aabce03dde5a916116a091615594565b60405180910390a16002548114610f555760405162461bcd60e51b8152600401610e1f906159f0565b60096020528160005260406000208181548110610ae157600080fd5b6116ed613e07565b610f5581613cdb565b6116fe613f0c565b6117086001613f8c565b565b60016002600082825461171d919061591a565b909155505060025461172d613f0c565b601c5460ff16156117505760405162461bcd60e51b8152600401610e1f90615af6565b61175c826005546140f5565b60025481146114a45760405162461bcd60e51b8152600401610e1f906159f0565b611785613e07565b6001600160a01b0381166117ab5760405162461bcd60e51b8152600401610e1f90615b38565b601a80546001600160a01b0319166001600160a01b0383169081179091556040517fa65a5aa86bb6f8e75752296da3ebda45474c8a302fc640c3b62868793862a03391610ee291615594565b601c5460ff161561181a5760405162461bcd60e51b8152600401610e1f90615af6565b611822613f0c565b611708600554613f8c565b60005433906001600160a01b03168114806119295750600360019054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b8152600401602060405180830381865afa158015611896573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ba9190615b5d565b6001600160a01b031663e760c3958260026040518363ffffffff1660e01b81526004016118e8929190615b90565b602060405180830381865afa158015611905573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061192991906158bd565b6119455760405162461bcd60e51b8152600401610e1f90615bbd565b601c5460ff16156119685760405162461bcd60e51b8152600401610e1f90615af6565b6000611973856130c0565b905060055481146119965760405162461bcd60e51b8152600401610e1f90615be4565b6119ba8585156119a657856119b4565b6005546119b490600161591a565b856142c8565b5050505050565b6001600260008282546119d4919061591a565b90915550506002546119e4613f0c565b60035461010090046001600160a01b03163314611a135760405162461bcd60e51b8152600401610e1f90615c15565b601c5460ff1615611a365760405162461bcd60e51b8152600401610e1f90615af6565b600454600160a01b900460ff16611a5f5760405162461bcd60e51b8152600401610e1f90615a27565b60008211611a9c5760405162461bcd60e51b815260206004820152600a60248201526916995c9bd05b5bdd5b9d60b21b6044820152606401610e1f565b6000611aa7846130c0565b6001600160a01b0385166000908152601260205260408120829055909150611ace8261474b565b90506005548203611c0657600354600454611afd916001600160a01b0391821691849161010090041687613f32565b601e546005546000908152600c6020526040902054670de0b6b3a764000091611b2591615903565b611b2f91906159b5565b6005546000908152600c6020526040902054611b4b91906158f0565b600480546040516370a0823160e01b81526001600160a01b03909116916370a0823191611b7a91869101615594565b602060405180830381865afa158015611b97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bbb9190615c3a565b1015611c015760405162461bcd60e51b8152602060048201526015602482015274416d6f756e74457863656564735574696c5261746560581b6044820152606401610e1f565b611d42565b600554821115611cfa57600480546040516370a0823160e01b81526000926001600160a01b03909216916370a0823191611c4291869101615594565b602060405180830381865afa158015611c5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c839190615c3a565b9050848110611cb557600354600454611cb0916001600160a01b0391821691859161010090041688613f32565b611cf4565b6000611cc182876158f0565b9050611cce818486614925565b600354600454611cf2916001600160a01b0391821691869161010090041689613f32565b505b50611d42565b81600114611d395760405162461bcd60e51b815260206004820152600c60248201526b125b9d985b1a59149bdd5b9960a21b6044820152606401610e1f565b611d4284614a03565b506000818152600f602090815260408083208054600180820183559185528385200180546001600160a01b0319166001600160a01b038a1690811790915594845260108352818420948452939091529020805460ff191690911790556002548114611dbf5760405162461bcd60e51b8152600401610e1f906159f0565b505050565b600080611dcf614b15565b5460ff1692915050565b6000838152600f6020526040812054819081908410611e06576000868152600f6020526040902054611e08565b835b9050845b81811015611e77576000878152600f6020526040902080546001600160a01b038a16919083908110611e4057611e4061599f565b6000918252602090912001546001600160a01b031603611e6757925060019150611e819050565b611e70816159d7565b9050611e0c565b5083600092509250505b94509492505050565b611e92613e07565b6001600160a01b038116611eb85760405162461bcd60e51b8152600401610e1f90615b38565b601980546001600160a01b0319166001600160a01b0383161790556040517faaf6f0738515c3cf390f1b3faec649d2dacb169d024089afc43bbe2fe66cd2d890610ee2908390615594565b611f0b613e07565b600454600160a01b900460ff1615611f605760405162461bcd60e51b815260206004820152601860248201527710d85b9d10da185b99d950599d195c941bdbdb14dd185c9d60421b6044820152606401610e1f565b60068190556040518181527f1d1fb7111c3779798bd4aefb2daea07ee8257a13c7eaceba89b4b1ccd405050d90602001610ee2565b600060086000611fa4846130c0565b81526020810191909152604001600020546001600160a01b031692915050565b6001546001600160a01b0316331461203c5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610e1f565b600054600154604051600080516020615dcc8339815191529261206d926001600160a01b039182169291169061592d565b60405180910390a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b6120a4613e07565b6114a48282613d5a565b6001600260008282546120c1919061591a565b90915550506002546120d1613f0c565b601c5460ff16156120f45760405162461bcd60e51b8152600401610e1f90615af6565b6120fc6117f7565b6121046139fc565b6121415760405162461bcd60e51b815260206004820152600e60248201526d10d85b9d10db1bdcd9549bdd5b9960921b6044820152606401610e1f565b600554600090815260086020526040808220546004805492516370a0823160e01b81526001600160a01b039283169493909216916370a082319161218791869101615594565b602060405180830381865afa1580156121a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121c89190615c3a565b6005546000908152600c602052604090205490915081111561229757602080546005546000908152600c9092526040822054670de0b6b3a7640000919061220f90856158f0565b6122199190615903565b61222391906159b5565b601f54600454919250612245916001600160a01b039081169186911684613f32565b61224f81836158f0565b91507fb8379d05082aa2dd32963972d72cc2d46257811133341855b63bb2fddda6ca3e6020548260405161228d929190918252602082015260400190565b60405180910390a1505b6005546000908152600c602052604081205490036122d0576005546000908152601360205260409020670de0b6b3a76400009055612311565b6005546000908152600c60205260409020546122f4670de0b6b3a764000083615903565b6122fe91906159b5565b6005546000908152601360205260409020555b601c805460ff191660011790556005546040517fa224cce482b24082d1d3128437615f7f5ce87b97453a11114846ea442a100272916123539190815260200190565b60405180910390a150506002548114610f555760405162461bcd60e51b8152600401610e1f906159f0565b600160026000828254612391919061591a565b9091555050600254600454600160a01b900460ff166123c25760405162461bcd60e51b8152600401610e1f90615a27565b336000908152600d602052604090205460ff16156123f25760405162461bcd60e51b8152600401610e1f90615a4f565b6005546000908152600b6020908152604080832033845290915290205461242b5760405162461bcd60e51b8152600401610e1f90615a86565b600b6000600554600161243e919061591a565b815260208082019290925260409081016000908120338252909252902054156124795760405162461bcd60e51b8152600401610e1f90615ab1565b612481613f0c565b601c5460ff16156124a45760405162461bcd60e51b8152600401610e1f90615af6565b6124b6662386f26fc10000600a615903565b82101580156124d657506124d2662386f26fc10000605a615903565b8211155b61251b5760405162461bcd60e51b8152602060048201526016602482015275496e76616c69645769746864726177616c56616c756560501b6044820152606401610e1f565b6005546000908152600b60209081526040808320338452909152812054670de0b6b3a76400009061254d908590615903565b61255791906159b5565b905080601b5411156125805780601b600082825461257591906158f0565b909155506125869050565b6000601b555b336000818152600d60209081526040808320805460ff19166001179055600e90915290819020859055517fe5892ff2a8b08efb903ffbba1f0514c1d3e22eea34dd5b89cf30aabce03dde5a916125db91615594565b60405180910390a15060025481146114a45760405162461bcd60e51b8152600401610e1f906159f0565b336000908152600d6020526040902054819060ff16156126735760405162461bcd60e51b8152602060048201526024808201527f43616e744465706f736974447572696e675769746864726177616c52657175656044820152631cdd195960e21b6064820152608401610e1f565b60155481601b54612684919061591a565b11156126c75760405162461bcd60e51b81526020600482015260126024820152710416d6f756e74457863656564734c504361760741b6044820152606401610e1f565b6005546000908152600b6020908152604080832033845290915290205415801561271f5750600b600060055460016126ff919061591a565b815260208082019290925260409081016000908120338252909252902054155b15612771576016548110156127715760405162461bcd60e51b8152602060048201526018602482015277105b5bdd5b9d13195cdcd51a185b935a5b91195c1bdcda5d60421b6044820152606401610e1f565b600160026000828254612784919061591a565b9091555050600254612794613f0c565b601c5460ff16156127b75760405162461bcd60e51b8152600401610e1f90615af6565b6127c083614b39565b6002548114611dbf5760405162461bcd60e51b8152600401610e1f906159f0565b6127e9613e07565b600454600160a01b900460ff16156128325760405162461bcd60e51b815260206004820152600c60248201526b131412185cd4dd185c9d195960a21b6044820152606401610e1f565b6002600052600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd720546128a55760405162461bcd60e51b815260206004820152601860248201527743616e745374617274576974686f75744465706f7369747360401b6044820152606401610e1f565b42600755600260058190556000906128bc9061474b565b9050806001600160a01b0316637d3de7ce6007546128da6002610da3565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401600060405180830381600087803b15801561291857600080fd5b505af115801561292c573d6000803e3d6000fd5b50506004805460ff60a01b1916600160a01b17905550506040517f960682678fca98f3ed131eaf165e59544bcd738e948f0b3c64f58fa9e1c65e6090600090a150565b612977613e07565b6001600160a01b0381166129bf5760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610e1f565b600154600160a81b900460ff1615612a0f5760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610e1f565b600080546001600160a01b0383166001600160a01b031990911681179091556001805460ff60a81b1916600160a81b179055604051600080516020615dcc83398151915291610ee291849061592d565b6000828152601460208181526040808420546013835281852054868652939092528320549091612a8e91615903565b612a9891906159b5565b9392505050565b6000612aab6001614d25565b905090565b60005433906001600160a01b0316811480612bac5750600360019054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b3d9190615b5d565b6001600160a01b031663e760c3958260026040518363ffffffff1660e01b8152600401612b6b929190615b90565b602060405180830381865afa158015612b88573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bac91906158bd565b612bc85760405162461bcd60e51b8152600401610e1f90615bbd565b601c5460ff1615612beb5760405162461bcd60e51b8152600401610e1f90615af6565b8215612bf75782612c05565b600554612c0590600161591a565b92508151600003612c595760005b8451811015612c5357612c41858281518110612c3157612c3161599f565b60200260200101518560006142c8565b80612c4b816159d7565b915050612c13565b50612ec8565b8151845114612ca35760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e698cadccee8d0e69aeae6e89ac2e8c6d60531b6044820152606401610e1f565b6005546000908152600f6020526040812054905b8551811015610d9b576000848281518110612cd457612cd461599f565b602002602001015111612d295760405162461bcd60e51b815260206004820152601d60248201527f5469636b6574496e6465784d7573744265477265617465725468616e300000006044820152606401610e1f565b612d3381836158f0565b848281518110612d4557612d4561599f565b60200260200101511015612d9557612d90868281518110612d6857612d6861599f565b602002602001015186868481518110612d8357612d8361599f565b60200260200101516142c8565b612eb6565b6000805b8551821015612e3657878381518110612db457612db461599f565b60200260200101516001600160a01b0316600f60006005548152602001908152602001600020878481518110612dec57612dec61599f565b602002602001015181548110612e0457612e0461599f565b6000918252602090912001546001600160a01b031603612e2657506001612e36565b612e2f826159d7565b9150612d99565b80612e835760405162461bcd60e51b815260206004820152601a60248201527f5469636b65744e6f74466f756e64496e496e70757441727261790000000000006044820152606401610e1f565b612eb3888481518110612e9857612e9861599f565b602002602001015188888581518110612d8357612d8361599f565b50505b80612ec0816159d7565b915050612cb7565b50505050565b612ed6613f0c565b601c5460ff1615612ef95760405162461bcd60e51b8152600401610e1f90615af6565b60035461010090046001600160a01b03163314612f285760405162461bcd60e51b8152600401610e1f90615c15565b6000612f33836130c0565b9050600181118015612f46575060055481105b15612f5057506005545b8115612fa45760006001821115612f6f57612f6a8261474b565b612f7c565b6019546001600160a01b03165b600354600454919250612fa2916001600160a01b03908116916101009004168386613f32565b505b60008181526010602090815260408083206001600160a01b038716845290915290205460ff1615611dbf5760008181526011602090815260408083206001600160a01b03871684529091529020805460ff19166001179055505050565b6005546000908152600b602090815260408083206001600160a01b038516845290915281205415158061307857506000600b60006005546001613044919061591a565b81526020019081526020016000206000846001600160a01b03166001600160a01b0316815260200190815260200160002054115b8015610dcb57506001600160a01b0382166000908152600d602052604090205460ff161580610dcb5750506001600160a01b03166000908152600e6020526040902054151590565b6001600160a01b038116600090815260126020526040812054908190036133725781600080805b836001600160a01b03166362e5c8196040518163ffffffff1660e01b8152600401602060405180830381865afa158015613125573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131499190615c3a565b81101561336d5760405163b1283e7760e01b8152600481018290526001600160a01b0385169063b1283e779060240161012060405180830381865afa158015613196573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ba9190615c76565b505060215460405163bf40fac160e01b815260206004820152601660248201527529b837b93a39a0a6a6ab192934b9b5a6b0b730b3b2b960511b6044820152949a5095985060009650506001600160a01b03909416935063bf40fac1925050606401602060405180830381865afa158015613239573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061325d9190615b5d565b6040516349ef3bc960e11b815261ffff851660048201526001600160a01b0391909116906393de779290602401602060405180830381865afa1580156132a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132cb91906158bd565b9050600754841180156132dc575080155b156133505781600003613315576006546007546132f990866158f0565b61330391906159b5565b61330e90600261591a565b955061335a565b856006546007548661332791906158f0565b61333191906159b5565b61333c90600261591a565b1461334b57600195505061336d565b61335a565b600195505061336d565b5080613365816159d7565b9150506130e7565b505050505b919050565b61337f613e07565b610f5581613c71565b600654600090610db46002846158f0565b6133a1613e07565b610f5581613c3c565b6001600260008282546133bd919061591a565b90915550506002546133cd613f0c565b601c5460ff166133ef5760405162461bcd60e51b8152600401610e1f90615947565b600554600090815260096020526040902054601d54146134485760405162461bcd60e51b8152602060048201526014602482015273139bdd105b1b155cd95c9cd41c9bd8d95cdcd95960621b6044820152606401610e1f565b601c805460ff19169055600554600090815260086020908152604080832054600b83528184206019546001600160a01b03908116865293529220549116901561353157600554600090815260136020908152604080832054600b83528184206019546001600160a01b03168552909252822054670de0b6b3a7640000916134ce91615903565b6134d891906159b5565b6019546004549192506134fa916001600160a01b039081169185911684613f32565b601954604051600080516020615dec83398151915291613527916001600160a01b039091169084906158a4565b60405180910390a1505b60055460020361355e576005546000908152601360209081526040808320546014909252909120556135c1565b600554600081815260136020526040812054670de0b6b3a764000092909160149161358b906001906158f0565b8152602001908152602001600020546135a49190615903565b6135ae91906159b5565b6005546000908152601460205260409020555b6005600081546135d0906159d7565b90915550600480546040516370a0823160e01b81526001600160a01b03909116916370a082319161360391859101615594565b602060405180830381865afa158015613620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136449190615c3a565b6005546000908152600c60205260408120805490919061366590849061591a565b90915550506005546000818152600b602090815260408083206019546001600160a01b03168452825280832054938352600c9091529020546136a791906158f0565b601b556005546000906136b99061474b565b600480546040516370a0823160e01b815292935061374692859285926001600160a01b0316916370a08231916136f191869101615594565b602060405180830381865afa15801561370e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137329190615c3a565b6004546001600160a01b0316929190613f32565b6000601d556005547fc67dda8e11f1aa941c7e74466b1859a07a32f46aaf641d29b83be348424d93cd9061377c906001906158f0565b60136000600160055461378f91906158f0565b815260200190815260200160002054604051612353929190918252602082015260400190565b6137bd613e07565b6001600160a01b0381166137e35760405162461bcd60e51b8152600401610e1f90615b38565b60035461010090046001600160a01b031615613878576004805460035460405163095ea7b360e01b81526001600160a01b039283169363095ea7b3936138339361010090041691600091016158a4565b6020604051808303816000875af1158015613852573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061387691906158bd565b505b60038054610100600160a81b0319166101006001600160a01b03848116820292909217928390556004805460405163095ea7b360e01b81529084169463095ea7b3946138cd94909104169160001991016158a4565b6020604051808303816000875af11580156138ec573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061391091906158bd565b507f576297e5fcc8cd907ee80b240284865eb3d821bdc5232e6ee9e4d78a12531c0981604051610ee29190615594565b6000612aab600554614d25565b600160026000828254613960919061591a565b9091555050600254613970613f0c565b601c5460ff16156139935760405162461bcd60e51b8152600401610e1f90615af6565b61175c8260016140f5565b60035460ff16156139e75760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610e1f565b6003805460ff19166001908117909155600255565b600454600090600160a01b900460ff161580613a215750613a1e600554610da3565b42105b15613a2c5750600090565b6005546000908152600f60209081526040808320546023909252822054829190805b82811015613b39576005546000908152600f60205260409020805482908110613a7957613a7961599f565b600091825260208083209091015460055483526011825260408084206001600160a01b039092168085529190925291205490945060ff16613b2957839450846001600160a01b031663b0c56f056040518163ffffffff1660e01b8152600401602060405180830381865afa158015613af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b1991906158bd565b613b295760009550505050505090565b613b32816159d7565b9050613a4e565b50600194505050505090565b60215460405163bf40fac160e01b8152602060048201526009602482015268141c9a58d95199595960ba1b60448201526000916001600160a01b03169063bf40fac190606401602060405180830381865afa158015613ba8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bcc9190615b5d565b6001600160a01b031663ac82f6086022546040518263ffffffff1660e01b8152600401613bfb91815260200190565b602060405180830381865afa158015613c18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612aab9190615c3a565b60158190556040518181527f8c43aa02599ac8f8bab4724621ceea5e7a06b07bbbfaf3b7bd0386cbe481ea3c90602001610ee2565b60168190556040518181527f990717cc219e5348c1b88bb0ff530d804f0b6f54f3b03844a2bfbe4eb1e9c5d690602001610ee2565b60178190556040518181527fe7c2c09f66c8b970b4a99250f4d0844e1496b9d51d4760a17b0134ddd52023e190602001610ee2565b670de0b6b3a7640000811115613d255760405162461bcd60e51b815260206004820152600f60248201526e0aae8d2d8a4c2e8caa8dede90d2ced608b1b6044820152606401610e1f565b601e8190556040518181527fc117ccf765672707ebe3c1606037488c1e27dc1f42b5266e3d6b496db7d4209e90602001610ee2565b670de0b6b3a7640000811115613da95760405162461bcd60e51b81526020600482015260146024820152730a6c2ccca84def092dae0c2c6e8a8dede90d2ced60631b6044820152606401610e1f565b601f80546001600160a01b0319166001600160a01b03841617905560208190556040517fa1a8623472ca4e2879372be60dfd1ff0675778e49f7379eedd98ca57cf36b21a90613dfb90849084906158a4565b60405180910390a15050565b6000546001600160a01b031633146117085760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610e1f565b613e81614ea7565b6000613e8b614b15565b805460ff1916815590507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051610ee29190615594565b613ecd613f0c565b6000613ed7614b15565b805460ff1916600117815590507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613eb83390565b613f14611dc4565b156117085760405163d93c066560e01b815260040160405180910390fd5b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052612ec8908590614ecc565b6000818152600f60209081526040808320546023909252909120545b818110801561400857506000838152601160209081526040808320600f9092528220805491929184908110613fdf57613fdf61599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b1561401557600101613fa8565b805b82811015614070576000848152600f60205260409020805461405f918691849081106140455761404561599f565b6000918252602090912001546001600160a01b0316614f26565b50614069816159d7565b9050614017565b505b81811080156140d257506000838152601160209081526040808320600f90925282208054919291849081106140a9576140a961599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b156140df57600101614072565b6000928352602360205260409092209190915550565b600082116141155760405162461bcd60e51b8152600401610e1f90615978565b6000818152600f6020908152604080832054602390925282205490915b828210801561419257506000848152601160209081526040808320600f90925282208054919291859081106141695761416961599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b801561419f57506103e881105b156141b05760019182019101614132565b6103e881106141d15750600092835260236020526040909220919091555050565b6000825b84811080156141e357508682105b1561422a576000868152600f60205260409020805461420e918891849081106140455761404561599f565b1561421a578160010191505b614223816159d7565b90506141d5565b505b838310801561428c57506000858152601160209081526040808320600f90925282208054919291869081106142635761426361599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b801561429957506103e882105b156142af5782600101925081600101915061422c565b5050600092835260236020526040909220919091555050565b6005548211806142d85750816001145b6143195760405162461bcd60e51b8152602060048201526012602482015271149bdd5b99105b1c9958591e50db1bdcd95960721b6044820152606401610e1f565b6000614324846130c0565b9050600554811461436a5760405162461bcd60e51b815260206004820152601060248201526f151a58dad95d139bdd125b949bdd5b9960821b6044820152606401610e1f565b60008181526010602090815260408083206001600160a01b038816845290915290205460ff166143ac5760405162461bcd60e51b8152600401610e1f90615be4565b60008181526011602090815260408083206001600160a01b038816845290915290205460ff16156144185760405162461bcd60e51b8152602060048201526016602482015275151a58dad95d105b1c9958591e515e195c98da5cd95960521b6044820152606401610e1f565b836001600160a01b0316633f6fa6556040518163ffffffff1660e01b8152600401602060405180830381865afa158015614456573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061447a91906158bd565b156144bf5760405162461bcd60e51b8152602060048201526015602482015274151a58dad95d105b1c9958591e54995cdbdb1d9959605a1b6044820152606401610e1f565b60008181526010602090815260408083206001600160a01b03881684529091529020805460ff191690556144f48185846151e1565b60006144ff8261474b565b9050600061450c8561474b565b90506000866001600160a01b031663d165dac26040518163ffffffff1660e01b8152600401602060405180830381865afa15801561454e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145729190615c3a565b600480546040516370a0823160e01b81526001600160a01b03909116916370a08231916145a1918c9101615594565b602060405180830381865afa1580156145be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145e29190615c3a565b6145ec91906158f0565b600480546040516370a0823160e01b81529293506000926001600160a01b03909116916370a082319161462191879101615594565b602060405180830381865afa15801561463e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146629190615c3a565b90508082111561468757600061467882846158f0565b905061468581858a614925565b505b60045461469f906001600160a01b0316848685613f32565b6001600160a01b03881660008181526012602090815260408083208b90558a8352601082528083208484528252808320805460ff191660019081179091558b8452600f8352818420805491820181558452919092200180546001600160a01b031916909217909155517fd8edac6470af12f863b07d43de4b58079798e80230a8b7f899a4f55ecdac618090614739908a9088908b90615d1c565b60405180910390a15050505050505050565b6000818152600860205260409020546001600160a01b03168061337257816001036147a5575060198054600083815260086020526040902080546001600160a01b0319166001600160a01b03928316179055905416919050565b601a546001600160a01b03166147f95760405162461bcd60e51b8152602060048201526019602482015278149bdd5b99141bdbdb13585cdd195c98dbdc1e539bdd14d95d603a1b6044820152606401610e1f565b601a54600090614811906001600160a01b0316615407565b6004549091506001600160a01b038083169163d13f90b4913091168661483b6104dc6001836158f0565b61484489610da3565b6040516001600160e01b031960e088901b1681526001600160a01b03958616600482015294909316602485015260448401919091526064830152608482015260a401600060405180830381600087803b1580156148a057600080fd5b505af11580156148b4573d6000803e3d6000fd5b50505060008481526008602090815260409182902080546001600160a01b0319166001600160a01b03861690811790915582518781529182015292935083927f24c1b21b902a85b5039d7d72427d9376657229eea77880ec9e62031dc950f6ba92500160405180910390a150919050565b6019546001600160a01b031661494d5760405162461bcd60e51b8152600401610e1f90615d3d565b60195460045461496b916001600160a01b0391821691168486613f32565b6000818152600b602090815260408083206019546001600160a01b031684529091528120805485929061499f90849061591a565b90915550506000818152600c6020526040812080548592906149c290849061591a565b9091555050601954604051600080516020615e0c833981519152916149f6916001600160a01b039091169086908590615d1c565b60405180910390a1505050565b6019546001600160a01b0316614a2b5760405162461bcd60e51b8152600401610e1f90615d3d565b601954600354600454614a55926001600160a01b0391821692908216916101009091041684613f32565b6019546001600160a01b031660009081527f72c6bfb7988af3a1efa6568f02a999bc52252641c659d85961ca3d372b57d5cf602052604081208054839290614a9e90849061591a565b909155505060016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c8054839290614ae090849061591a565b9091555050601954604051600080516020615e0c83398151915291610ee2916001600160a01b03909116908490600190615d1c565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330090565b60006005546001614b4a919061591a565b90506000614b578261474b565b600454909150614b72906001600160a01b0316338386613f32565b6019546001600160a01b03163303614bcc5760405162461bcd60e51b815260206004820152601e60248201527f43616e744465706f7369744469726563746c79417344656661756c744c5000006044820152606401610e1f565b6005546000908152600b60209081526040808320338452909152902054158015614c0d57506000828152600b60209081526040808320338452909152902054155b15614c985760175460185410614c575760405162461bcd60e51b815260206004820152600f60248201526e13585e155cd95c9cd4995858da1959608a1b6044820152606401610e1f565b60008281526009602090815260408220805460018181018355918452919092200180546001600160a01b03191633179055601854614c949161591a565b6018555b6000828152600b6020908152604080832033845290915281208054859290614cc190849061591a565b90915550506000828152600c602052604081208054859290614ce490849061591a565b9250508190555082601b6000828254614cfd919061591a565b9091555050600554604051600080516020615e0c833981519152916149f69133918791615d1c565b6000818152600f6020908152604080832054602390925282205482918291805b82811015614e9a576000878152600f60205260409020805482908110614d6d57614d6d61599f565b60009182526020808320909101548983526011825260408084206001600160a01b039092168085529190925291205490945060ff16614e8857839450846001600160a01b031663e74d3c476040518163ffffffff1660e01b8152600401602060405180830381865afa158015614de7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e0b91906158bd565b8015614e765750846001600160a01b0316633356a35a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614e50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e7491906158bd565b155b15614e88575060019695505050505050565b80614e92816159d7565b915050614d45565b5060009695505050505050565b614eaf611dc4565b61170857604051638dfc202b60e01b815260040160405180910390fd5b6000614ee16001600160a01b03841683615474565b90508051600014158015614f06575080806020019051810190614f0491906158bd565b155b15611dbf5782604051635274afe760e01b8152600401610e1f9190615594565b60008281526011602090815260408083206001600160a01b038516845290915281205460ff16610dcb5760008290506000816001600160a01b0316633356a35a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614f95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614fb991906158bd565b9050600080600187111561502c57836001600160a01b0316634652e3306040518163ffffffff1660e01b8152600401602060405180830381865afa158015615005573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061502991906158bd565b90505b808015615040575061503d87610da3565b42115b1561504a57600191505b836001600160a01b031663e74d3c476040518163ffffffff1660e01b8152600401602060405180830381865afa158015615088573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906150ac91906158bd565b80156150bd57508215806150bd5750815b1561512c57600354604051630f8a940b60e41b81526101009091046001600160a01b03169063f8a940b0906150f9908990600090600401615d66565b600060405180830381600087803b15801561511357600080fd5b505af1158015615127573d6000803e3d6000fd5b505050505b828015615137575080155b8061519f5750836001600160a01b0316633f6fa6556040518163ffffffff1660e01b8152600401602060405180830381865afa15801561517b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061519f91906158bd565b156151d75760008781526011602090815260408083206001600160a01b038a1684529091529020805460ff1916600190811790915594505b5050505092915050565b60008160000361526c5760005b6000858152600f6020526040902054811015615266576000858152600f6020526040902080546001600160a01b0386169190839081106152305761523061599f565b6000918252602090912001546001600160a01b0316036152565760019150809250615266565b61525f816159d7565b90506151ee565b506152ca565b6000848152600f6020526040902054821080156152c757506000848152600f6020526040902080546001600160a01b0385169190849081106152b0576152b061599f565b6000918252602090912001546001600160a01b0316145b90505b806153085760405162461bcd60e51b815260206004820152600e60248201526d151a58dad95d139bdd119bdd5b9960921b6044820152606401610e1f565b600084815260236020526040902054808310156153315760008581526023602052604090208390555b6000858152600f60205260409020805461534d906001906158f0565b8154811061535d5761535d61599f565b6000918252602080832090910154878352600f909152604090912080546001600160a01b0390921691859081106153965761539661599f565b600091825260208083209190910180546001600160a01b0319166001600160a01b039490941693909317909255868152600f909152604090208054806153de576153de615d86565b600082815260209020810160001990810180546001600160a01b03191690550190555050505050565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008260601b60e81c176000526e5af43d82803e903d91602b57fd5bf38260781b17602052603760096000f090506001600160a01b038116613372576040516330be1a3d60e21b815260040160405180910390fd5b6060612a988383600084600080856001600160a01b0316848660405161549a9190615d9c565b60006040518083038185875af1925050503d80600081146154d7576040519150601f19603f3d011682016040523d82523d6000602084013e6154dc565b606091505b50915091506154ec8683836154f6565b9695505050505050565b60608261550b5761550682615549565b612a98565b815115801561552257506001600160a01b0384163b155b156155425783604051639996b31560e01b8152600401610e1f9190615594565b5080612a98565b8051156155595780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6000806040838503121561558557600080fd5b50508035926020909101359150565b6001600160a01b0391909116815260200190565b600061018082840312156155bb57600080fd5b50919050565b6000602082840312156155d357600080fd5b5035919050565b6001600160a01b0381168114610f5557600080fd5b60006020828403121561560157600080fd5b8135612a98816155da565b8015158114610f5557600080fd5b60006020828403121561562c57600080fd5b8135612a988161560c565b6000806040838503121561564a57600080fd5b82359150602083013561565c816155da565b809150509250929050565b60008060006060848603121561567c57600080fd5b8335615687816155da565b95602085013595506040909401359392505050565b600080604083850312156156af57600080fd5b82356156ba816155da565b946020939093013593505050565b600080600080608085870312156156de57600080fd5b84356156e9816155da565b966020860135965060408601359560600135945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561574257615742615703565b604052919050565b600067ffffffffffffffff82111561576457615764615703565b5060051b60200190565b600082601f83011261577f57600080fd5b8135602061579461578f8361574a565b615719565b82815260059290921b840181019181810190868411156157b357600080fd5b8286015b848110156157ce57803583529183019183016157b7565b509695505050505050565b6000806000606084860312156157ee57600080fd5b833567ffffffffffffffff8082111561580657600080fd5b818601915086601f83011261581a57600080fd5b8135602061582a61578f8361574a565b82815260059290921b8401810191818101908a84111561584957600080fd5b948201945b83861015615870578535615861816155da565b8252948201949082019061584e565b975050870135945050604086013591508082111561588d57600080fd5b5061589a8682870161576e565b9150509250925092565b6001600160a01b03929092168252602082015260400190565b6000602082840312156158cf57600080fd5b8151612a988161560c565b634e487b7160e01b600052601160045260246000fd5b81810381811115610dcb57610dcb6158da565b8082028115828204841417610dcb57610dcb6158da565b80820180821115610dcb57610dcb6158da565b6001600160a01b0392831681529116602082015260400190565b602080825260179082015276149bdd5b9910db1bdcda5b99d39bdd141c995c185c9959604a1b604082015260600190565b6020808252600d908201526c426174636853697a655a65726f60981b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6000826159d257634e487b7160e01b600052601260045260246000fd5b500490565b6000600182016159e9576159e96158da565b5060010190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6020808252600e908201526d141bdbdb139bdd14dd185c9d195960921b604082015260600190565b6020808252601a908201527f5769746864726177616c416c7265616479526571756573746564000000000000604082015260600190565b6020808252601190820152704e6f7468696e67546f576974686472617760781b604082015260600190565b60208082526025908201527f43616e7457697468647261775768656e4465706f7369746564466f724e657874604082015264149bdd5b9960da1b606082015260800190565b60208082526022908201527f4e6f74416c6c6f7765645768656e526f756e64436c6f73696e67507265706172604082015261195960f21b606082015260800190565b6020808252600b908201526a5a65726f4164647265737360a81b604082015260600190565b600060208284031215615b6f57600080fd5b8151612a98816155da565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b03831681526040810160048310615bb057615bb0615b7a565b8260208301529392505050565b6020808252600d908201526c24b73b30b634b229b2b73232b960991b604082015260600190565b602080825260179082015276151a58dad95d139bdd125b90dd5c9c995b9d149bdd5b99604a1b604082015260600190565b6020808252600b908201526a4f6e6c7946726f6d414d4d60a81b604082015260600190565b600060208284031215615c4c57600080fd5b5051919050565b805161ffff8116811461337257600080fd5b805160ff8116811461337257600080fd5b60008060008060008060008060006101208a8c031215615c9557600080fd5b89519850615ca560208b01615c53565b9750615cb360408b01615c53565b965060608a01519550615cc860808b01615c65565b945060a08a01518060020b8114615cde57600080fd5b60c08b015190945062ffffff81168114615cf757600080fd5b9250615d0560e08b01615c65565b91506101008a015190509295985092959850929598565b6001600160a01b039390931683526020830191909152604082015260600190565b6020808252600f908201526e111959985d5b1d1314139bdd14d95d608a1b604082015260600190565b6001600160a01b03831681526040810160038310615bb057615bb0615b7a565b634e487b7160e01b600052603160045260246000fd5b6000825160005b81811015615dbd5760208186018101518583015201615da3565b50600092019182525091905056feb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159cd8138f8a3f377c5259ca548e70e4c2de94f129f5a11036a15b69513cba2b426a73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488caa2646970667358221220310d75667c11da0759cc7cca5eeca112f6bf84d1871f496d888881b210675d7664736f6c63430008140033

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061048b5760003560e01c80636c321c8a11610262578063c9f4ff4611610151578063ddc6ac23116100ce578063e95d39ca11610092578063e95d39ca14610a71578063ebc7977214610a84578063ee161cce14610a8c578063f61fcb8b14610a94578063f7683bbc14610ab4578063ff50abdc14610abc57600080fd5b8063ddc6ac2314610a28578063ddcc8fe914610a3b578063e278fe6f14610a4e578063e81e52ee14610a56578063e8362b7714610a6957600080fd5b8063d7efa12911610115578063d7efa129146109c9578063d8dfeb45146109dc578063d95ad45c146109ef578063db7e364814610a02578063db7f92d414610a1557600080fd5b8063c9f4ff4614610989578063d03c02731461099c578063d27c0797146109a4578063d69fb668146109ad578063d728e910146109b657600080fd5b80639bd2e61b116101df578063b9b1be8b116101a3578063b9b1be8b1461093a578063bdcc22e91461094d578063be9a655514610956578063c3b83f5f1461095e578063c99252881461097157600080fd5b80639bd2e61b146108d0578063a6644f96146108e3578063a8df539f14610911578063b562a1ab1461091e578063b6b55f251461092757600080fd5b80637fa946d9116102265780637fa946d91461086c5780638b649b941461088c5780638b844412146108955780638c54c8121461089d5780638da5cb5b146108bd57600080fd5b80636c321c8a1461081557806374094edd1461081e57806377332fc51461083e57806379ba5097146108515780637a1e0aa81461085957600080fd5b80634218c4d81161037e5780635c7b396e116102fb578063634e0d97116102bf578063634e0d97146107a1578063645006ca146107cf57806365e0e725146107d85780636685fdc2146107eb578063681312f51461080257600080fd5b80635c7b396e146107345780635c975abb1461073d5780635ddd3e8314610745578063610589e1146107705780636131dc711461077957600080fd5b80634d549a42116103425780634d549a42146106e057806353a47bb7146106f357806353e8bdb714610706578063582ab2f91461070e57806358c09cc01461072157600080fd5b80634218c4d8146106695780634651f0801461067157806348663e951461069a5780634a96fc84146106ad5780634ae7937f146106c057600080fd5b80631daae1731161040c578063336d30ed116103d0578063336d30ed146105fd578063343e4f9f1461061d5780633ab76e9f146106305780633b92d7581461064357806340774ff61461065657600080fd5b80631daae1731461056d5780631f2698ab146105a0578063202ffce8146105b457806327c28442146105c7578063311c56df146105f557600080fd5b8063146ca53111610453578063146ca531146105225780631627540c1461052b57806316c38b3c1461053e5780631b2a52d8146105515780631baa88561461056457600080fd5b806303d868db1461049057806309b17b3d146104b957806312b19a13146104ce57806313af4035146104ef578063145dee7d14610502575b600080fd5b6104a361049e366004615572565b610ac5565b6040516104b09190615594565b60405180910390f35b6104cc6104c73660046155a8565b610afd565b005b6104e16104dc3660046155c1565b610da3565b6040519081526020016104b0565b6104cc6104fd3660046155ef565b610dd1565b6104e16105103660046155c1565b6000908152600f602052604090205490565b6104e160055481565b6104cc6105393660046155ef565b610eed565b6104cc61054c36600461561a565b610f40565b6104cc61055f3660046155c1565b610f60565b6104e160075481565b61059061057b3660046155ef565b600d6020526000908152604090205460ff1681565b60405190151581526020016104b0565b60045461059090600160a01b900460ff1681565b6104cc6105c23660046155c1565b6114a8565b6105906105d5366004615637565b601160209081526000928352604080842090915290825290205460ff1681565b6104cc6114b9565b6104e161060b3660046155c1565b60146020526000908152604090205481565b6104a361062b366004615572565b6116c9565b6021546104a3906001600160a01b031681565b6019546104a3906001600160a01b031681565b6104cc6106643660046155c1565b6116e5565b6104cc6116f6565b6104a361067f3660046155c1565b6008602052600090815260409020546001600160a01b031681565b601f546104a3906001600160a01b031681565b6104cc6106bb3660046155c1565b61170a565b6104e16106ce3660046155c1565b600c6020526000908152604090205481565b6104cc6106ee3660046155ef565b61177d565b6001546104a3906001600160a01b031681565b6104cc6117f7565b6104cc61071c366004615667565b61182d565b6104cc61072f36600461569c565b6119c1565b6104e1601d5481565b610590611dc4565b6104e1610753366004615637565b600b60209081526000928352604080842090915290825290205481565b6104e160175481565b61078c6107873660046156c8565b611dd9565b604080519283529015156020830152016104b0565b6105906107af366004615637565b600a60209081526000928352604080842090915290825290205460ff1681565b6104e160165481565b6104cc6107e63660046155ef565b611e8a565b6005546000908152600960205260409020546104e1565b6104cc6108103660046155c1565b611f03565b6104e1601e5481565b6104e161082c3660046155c1565b60136020526000908152604090205481565b6104a361084c3660046155ef565b611f95565b6104cc611fc4565b6104cc61086736600461569c565b61209c565b6104e161087a3660046155c1565b60236020526000908152604090205481565b6104e160065481565b6104cc6120ae565b6104e16108ab3660046155ef565b60126020526000908152604090205481565b6000546104a3906001600160a01b031681565b6104cc6108de3660046155c1565b61237e565b6105906108f1366004615637565b601060209081526000928352604080842090915290825290205460ff1681565b601c546105909060ff1681565b6104e160225481565b6104cc6109353660046155c1565b612605565b601a546104a3906001600160a01b031681565b6104e160185481565b6104cc6127e1565b6104cc61096c3660046155ef565b61296f565b6003546104a39061010090046001600160a01b031681565b6104e1610997366004615572565b612a5f565b610590612a9f565b6104e160155481565b6104e160205481565b6104cc6109c43660046157d9565b612ab0565b6104cc6109d736600461569c565b612ece565b6004546104a3906001600160a01b031681565b6105906109fd3660046155ef565b613001565b6104e1610a103660046155ef565b6130c0565b6104cc610a233660046155c1565b613377565b6104e1610a363660046155c1565b613388565b6104cc610a493660046155c1565b613399565b6104cc6133aa565b6104cc610a643660046155ef565b6137b5565b610590613940565b6104cc610a7f3660046155c1565b61394d565b6104cc61399e565b6105906139fc565b6104e1610aa23660046155ef565b600e6020526000908152604090205481565b6104e1613b45565b6104e1601b5481565b600f6020528160005260406000208181548110610ae157600080fd5b6000918252602090912001546001600160a01b03169150829050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff16600081158015610b435750825b905060008267ffffffffffffffff166001148015610b605750303b155b905081158015610b6e575080155b15610b8c5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610bb657845460ff60401b1916600160401b1785555b610bc66104fd60208801886155ef565b610bce61399e565b610bde60408701602088016155ef565b600380546001600160a01b039290921661010002610100600160a81b0319909216919091179055610c1560608701604088016155ef565b602180546001600160a01b0319166001600160a01b0392909216919091179055610c4560808701606088016155ef565b600480546001600160a01b0319166001600160a01b03929092169190911790556101608601356022556080860135600655610c8360a0870135613c3c565b610c908660c00135613c71565b610c9d8660e00135613ca6565b610cab866101000135613cdb565b610ccb610cc0610140880161012089016155ef565b876101400135613d5a565b6004546001600160a01b031663095ea7b3610cec6040890160208a016155ef565b6000196040518363ffffffff1660e01b8152600401610d0c9291906158a4565b6020604051808303816000875af1158015610d2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4f91906158bd565b5060016005558315610d9b57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050565b600654600090610db46001846158f0565b610dbe9190615903565b600754610dcb919061591a565b92915050565b6001600160a01b038116610e285760405162461bcd60e51b815260206004820152601960248201527804f776e657220616464726573732063616e6e6f74206265203603c1b60448201526064015b60405180910390fd5b600154600160a01b900460ff1615610e945760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610e1f565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b0383166001600160a01b0319909116178155604051600080516020615dcc83398151915291610ee291849061592d565b60405180910390a150565b610ef5613e07565b600180546001600160a01b0319166001600160a01b0383161790556040517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290610ee2908390615594565b610f48613e07565b80610f5857610f55613e79565b50565b610f55613ec5565b600160026000828254610f73919061591a565b9091555050600254610f83613f0c565b601c5460ff16610fa55760405162461bcd60e51b8152600401610e1f90615947565b600554600090815260096020526040902054601d5410610ffb5760405162461bcd60e51b8152602060048201526011602482015270105b1b155cd95c9cd41c9bd8d95cdcd959607a1b6044820152606401610e1f565b6000821161101b5760405162461bcd60e51b8152600401610e1f90615978565b600554600090815260086020526040812054601d546001600160a01b03909116919061104890859061591a565b60055460009081526009602052604090205490915081111561107857506005546000908152600960205260409020545b601d545b818110156114445760055460009081526009602052604081208054839081106110a7576110a761599f565b6000918252602080832090910154600554835260138252604080842054600b84528185206001600160a01b0390931680865292909352832054909350670de0b6b3a7640000916110f691615903565b61110091906159b5565b6001600160a01b0383166000908152600d602052604090205490915060ff1615801561113c575060055460009081526013602052604090205415155b1561122c5780600b60006005546001611155919061591a565b81526020019081526020016000206000846001600160a01b03166001600160a01b0316815260200190815260200160002054611191919061591a565b600b600060055460016111a4919061591a565b81526020019081526020016000206000846001600160a01b03166001600160a01b03168152602001908152602001600020819055506009600060055460016111ec919061591a565b8152602080820192909252604001600090812080546001810182559082529190200180546001600160a01b0319166001600160a01b03841617905561141e565b6001600160a01b0382166000908152600e602052604090205415611387576001600160a01b0382166000908152600e6020526040812054670de0b6b3a7640000906112779084615903565b61128191906159b5565b60045490915061129c906001600160a01b0316878584613f32565b600080516020615dec83398151915283826040516112bb9291906158a4565b60405180910390a16001600160a01b0383166000908152600d60209081526040808320805460ff19169055600e90915281208190556005546009919061130290600161591a565b8152602080820192909252604001600090812080546001810182559082529190200180546001600160a01b0319166001600160a01b03851617905561134781836158f0565b600b6000600554600161135a919061591a565b8152602080820192909252604090810160009081206001600160a01b03881682529092529020555061141e565b6000600b6000600554600161139c919061591a565b8152602080820192909252604090810160009081206001600160a01b038088168352935220919091556004546113d59116868484613f32565b6001600160a01b0382166000908152600d602052604090819020805460ff1916905551600080516020615dec8339815191529061141590849084906158a4565b60405180910390a15b601d5461142c90600161591a565b601d555081905061143c816159d7565b91505061107c565b5060055460408051918252602082018690527f2e692c8fcabe33ba22535323e79dcb54ef22dccdb8e4ebdd9f2a7ffb1a28856c910160405180910390a1505060025481146114a45760405162461bcd60e51b8152600401610e1f906159f0565b5050565b6114b0613e07565b610f5581613ca6565b6001600260008282546114cc919061591a565b9091555050600254600454600160a01b900460ff166114fd5760405162461bcd60e51b8152600401610e1f90615a27565b336000908152600d602052604090205460ff161561152d5760405162461bcd60e51b8152600401610e1f90615a4f565b6005546000908152600b602090815260408083203384529091529020546115665760405162461bcd60e51b8152600401610e1f90615a86565b600b60006005546001611579919061591a565b815260208082019290925260409081016000908120338252909252902054156115b45760405162461bcd60e51b8152600401610e1f90615ab1565b6115bc613f0c565b601c5460ff16156115df5760405162461bcd60e51b8152600401610e1f90615af6565b6005546000908152600b60209081526040808320338452909152902054601b541115611640576005546000908152600b60209081526040808320338452909152812054601b8054919290916116359084906158f0565b909155506116469050565b6000601b555b600160185461165591906158f0565b601855336000818152600d602052604090819020805460ff19166001179055517fe5892ff2a8b08efb903ffbba1f0514c1d3e22eea34dd5b89cf30aabce03dde5a916116a091615594565b60405180910390a16002548114610f555760405162461bcd60e51b8152600401610e1f906159f0565b60096020528160005260406000208181548110610ae157600080fd5b6116ed613e07565b610f5581613cdb565b6116fe613f0c565b6117086001613f8c565b565b60016002600082825461171d919061591a565b909155505060025461172d613f0c565b601c5460ff16156117505760405162461bcd60e51b8152600401610e1f90615af6565b61175c826005546140f5565b60025481146114a45760405162461bcd60e51b8152600401610e1f906159f0565b611785613e07565b6001600160a01b0381166117ab5760405162461bcd60e51b8152600401610e1f90615b38565b601a80546001600160a01b0319166001600160a01b0383169081179091556040517fa65a5aa86bb6f8e75752296da3ebda45474c8a302fc640c3b62868793862a03391610ee291615594565b601c5460ff161561181a5760405162461bcd60e51b8152600401610e1f90615af6565b611822613f0c565b611708600554613f8c565b60005433906001600160a01b03168114806119295750600360019054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b8152600401602060405180830381865afa158015611896573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ba9190615b5d565b6001600160a01b031663e760c3958260026040518363ffffffff1660e01b81526004016118e8929190615b90565b602060405180830381865afa158015611905573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061192991906158bd565b6119455760405162461bcd60e51b8152600401610e1f90615bbd565b601c5460ff16156119685760405162461bcd60e51b8152600401610e1f90615af6565b6000611973856130c0565b905060055481146119965760405162461bcd60e51b8152600401610e1f90615be4565b6119ba8585156119a657856119b4565b6005546119b490600161591a565b856142c8565b5050505050565b6001600260008282546119d4919061591a565b90915550506002546119e4613f0c565b60035461010090046001600160a01b03163314611a135760405162461bcd60e51b8152600401610e1f90615c15565b601c5460ff1615611a365760405162461bcd60e51b8152600401610e1f90615af6565b600454600160a01b900460ff16611a5f5760405162461bcd60e51b8152600401610e1f90615a27565b60008211611a9c5760405162461bcd60e51b815260206004820152600a60248201526916995c9bd05b5bdd5b9d60b21b6044820152606401610e1f565b6000611aa7846130c0565b6001600160a01b0385166000908152601260205260408120829055909150611ace8261474b565b90506005548203611c0657600354600454611afd916001600160a01b0391821691849161010090041687613f32565b601e546005546000908152600c6020526040902054670de0b6b3a764000091611b2591615903565b611b2f91906159b5565b6005546000908152600c6020526040902054611b4b91906158f0565b600480546040516370a0823160e01b81526001600160a01b03909116916370a0823191611b7a91869101615594565b602060405180830381865afa158015611b97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bbb9190615c3a565b1015611c015760405162461bcd60e51b8152602060048201526015602482015274416d6f756e74457863656564735574696c5261746560581b6044820152606401610e1f565b611d42565b600554821115611cfa57600480546040516370a0823160e01b81526000926001600160a01b03909216916370a0823191611c4291869101615594565b602060405180830381865afa158015611c5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c839190615c3a565b9050848110611cb557600354600454611cb0916001600160a01b0391821691859161010090041688613f32565b611cf4565b6000611cc182876158f0565b9050611cce818486614925565b600354600454611cf2916001600160a01b0391821691869161010090041689613f32565b505b50611d42565b81600114611d395760405162461bcd60e51b815260206004820152600c60248201526b125b9d985b1a59149bdd5b9960a21b6044820152606401610e1f565b611d4284614a03565b506000818152600f602090815260408083208054600180820183559185528385200180546001600160a01b0319166001600160a01b038a1690811790915594845260108352818420948452939091529020805460ff191690911790556002548114611dbf5760405162461bcd60e51b8152600401610e1f906159f0565b505050565b600080611dcf614b15565b5460ff1692915050565b6000838152600f6020526040812054819081908410611e06576000868152600f6020526040902054611e08565b835b9050845b81811015611e77576000878152600f6020526040902080546001600160a01b038a16919083908110611e4057611e4061599f565b6000918252602090912001546001600160a01b031603611e6757925060019150611e819050565b611e70816159d7565b9050611e0c565b5083600092509250505b94509492505050565b611e92613e07565b6001600160a01b038116611eb85760405162461bcd60e51b8152600401610e1f90615b38565b601980546001600160a01b0319166001600160a01b0383161790556040517faaf6f0738515c3cf390f1b3faec649d2dacb169d024089afc43bbe2fe66cd2d890610ee2908390615594565b611f0b613e07565b600454600160a01b900460ff1615611f605760405162461bcd60e51b815260206004820152601860248201527710d85b9d10da185b99d950599d195c941bdbdb14dd185c9d60421b6044820152606401610e1f565b60068190556040518181527f1d1fb7111c3779798bd4aefb2daea07ee8257a13c7eaceba89b4b1ccd405050d90602001610ee2565b600060086000611fa4846130c0565b81526020810191909152604001600020546001600160a01b031692915050565b6001546001600160a01b0316331461203c5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610e1f565b600054600154604051600080516020615dcc8339815191529261206d926001600160a01b039182169291169061592d565b60405180910390a160018054600080546001600160a01b03199081166001600160a01b03841617909155169055565b6120a4613e07565b6114a48282613d5a565b6001600260008282546120c1919061591a565b90915550506002546120d1613f0c565b601c5460ff16156120f45760405162461bcd60e51b8152600401610e1f90615af6565b6120fc6117f7565b6121046139fc565b6121415760405162461bcd60e51b815260206004820152600e60248201526d10d85b9d10db1bdcd9549bdd5b9960921b6044820152606401610e1f565b600554600090815260086020526040808220546004805492516370a0823160e01b81526001600160a01b039283169493909216916370a082319161218791869101615594565b602060405180830381865afa1580156121a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121c89190615c3a565b6005546000908152600c602052604090205490915081111561229757602080546005546000908152600c9092526040822054670de0b6b3a7640000919061220f90856158f0565b6122199190615903565b61222391906159b5565b601f54600454919250612245916001600160a01b039081169186911684613f32565b61224f81836158f0565b91507fb8379d05082aa2dd32963972d72cc2d46257811133341855b63bb2fddda6ca3e6020548260405161228d929190918252602082015260400190565b60405180910390a1505b6005546000908152600c602052604081205490036122d0576005546000908152601360205260409020670de0b6b3a76400009055612311565b6005546000908152600c60205260409020546122f4670de0b6b3a764000083615903565b6122fe91906159b5565b6005546000908152601360205260409020555b601c805460ff191660011790556005546040517fa224cce482b24082d1d3128437615f7f5ce87b97453a11114846ea442a100272916123539190815260200190565b60405180910390a150506002548114610f555760405162461bcd60e51b8152600401610e1f906159f0565b600160026000828254612391919061591a565b9091555050600254600454600160a01b900460ff166123c25760405162461bcd60e51b8152600401610e1f90615a27565b336000908152600d602052604090205460ff16156123f25760405162461bcd60e51b8152600401610e1f90615a4f565b6005546000908152600b6020908152604080832033845290915290205461242b5760405162461bcd60e51b8152600401610e1f90615a86565b600b6000600554600161243e919061591a565b815260208082019290925260409081016000908120338252909252902054156124795760405162461bcd60e51b8152600401610e1f90615ab1565b612481613f0c565b601c5460ff16156124a45760405162461bcd60e51b8152600401610e1f90615af6565b6124b6662386f26fc10000600a615903565b82101580156124d657506124d2662386f26fc10000605a615903565b8211155b61251b5760405162461bcd60e51b8152602060048201526016602482015275496e76616c69645769746864726177616c56616c756560501b6044820152606401610e1f565b6005546000908152600b60209081526040808320338452909152812054670de0b6b3a76400009061254d908590615903565b61255791906159b5565b905080601b5411156125805780601b600082825461257591906158f0565b909155506125869050565b6000601b555b336000818152600d60209081526040808320805460ff19166001179055600e90915290819020859055517fe5892ff2a8b08efb903ffbba1f0514c1d3e22eea34dd5b89cf30aabce03dde5a916125db91615594565b60405180910390a15060025481146114a45760405162461bcd60e51b8152600401610e1f906159f0565b336000908152600d6020526040902054819060ff16156126735760405162461bcd60e51b8152602060048201526024808201527f43616e744465706f736974447572696e675769746864726177616c52657175656044820152631cdd195960e21b6064820152608401610e1f565b60155481601b54612684919061591a565b11156126c75760405162461bcd60e51b81526020600482015260126024820152710416d6f756e74457863656564734c504361760741b6044820152606401610e1f565b6005546000908152600b6020908152604080832033845290915290205415801561271f5750600b600060055460016126ff919061591a565b815260208082019290925260409081016000908120338252909252902054155b15612771576016548110156127715760405162461bcd60e51b8152602060048201526018602482015277105b5bdd5b9d13195cdcd51a185b935a5b91195c1bdcda5d60421b6044820152606401610e1f565b600160026000828254612784919061591a565b9091555050600254612794613f0c565b601c5460ff16156127b75760405162461bcd60e51b8152600401610e1f90615af6565b6127c083614b39565b6002548114611dbf5760405162461bcd60e51b8152600401610e1f906159f0565b6127e9613e07565b600454600160a01b900460ff16156128325760405162461bcd60e51b815260206004820152600c60248201526b131412185cd4dd185c9d195960a21b6044820152606401610e1f565b6002600052600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd720546128a55760405162461bcd60e51b815260206004820152601860248201527743616e745374617274576974686f75744465706f7369747360401b6044820152606401610e1f565b42600755600260058190556000906128bc9061474b565b9050806001600160a01b0316637d3de7ce6007546128da6002610da3565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401600060405180830381600087803b15801561291857600080fd5b505af115801561292c573d6000803e3d6000fd5b50506004805460ff60a01b1916600160a01b17905550506040517f960682678fca98f3ed131eaf165e59544bcd738e948f0b3c64f58fa9e1c65e6090600090a150565b612977613e07565b6001600160a01b0381166129bf5760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610e1f565b600154600160a81b900460ff1615612a0f5760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610e1f565b600080546001600160a01b0383166001600160a01b031990911681179091556001805460ff60a81b1916600160a81b179055604051600080516020615dcc83398151915291610ee291849061592d565b6000828152601460208181526040808420546013835281852054868652939092528320549091612a8e91615903565b612a9891906159b5565b9392505050565b6000612aab6001614d25565b905090565b60005433906001600160a01b0316811480612bac5750600360019054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b3d9190615b5d565b6001600160a01b031663e760c3958260026040518363ffffffff1660e01b8152600401612b6b929190615b90565b602060405180830381865afa158015612b88573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bac91906158bd565b612bc85760405162461bcd60e51b8152600401610e1f90615bbd565b601c5460ff1615612beb5760405162461bcd60e51b8152600401610e1f90615af6565b8215612bf75782612c05565b600554612c0590600161591a565b92508151600003612c595760005b8451811015612c5357612c41858281518110612c3157612c3161599f565b60200260200101518560006142c8565b80612c4b816159d7565b915050612c13565b50612ec8565b8151845114612ca35760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e698cadccee8d0e69aeae6e89ac2e8c6d60531b6044820152606401610e1f565b6005546000908152600f6020526040812054905b8551811015610d9b576000848281518110612cd457612cd461599f565b602002602001015111612d295760405162461bcd60e51b815260206004820152601d60248201527f5469636b6574496e6465784d7573744265477265617465725468616e300000006044820152606401610e1f565b612d3381836158f0565b848281518110612d4557612d4561599f565b60200260200101511015612d9557612d90868281518110612d6857612d6861599f565b602002602001015186868481518110612d8357612d8361599f565b60200260200101516142c8565b612eb6565b6000805b8551821015612e3657878381518110612db457612db461599f565b60200260200101516001600160a01b0316600f60006005548152602001908152602001600020878481518110612dec57612dec61599f565b602002602001015181548110612e0457612e0461599f565b6000918252602090912001546001600160a01b031603612e2657506001612e36565b612e2f826159d7565b9150612d99565b80612e835760405162461bcd60e51b815260206004820152601a60248201527f5469636b65744e6f74466f756e64496e496e70757441727261790000000000006044820152606401610e1f565b612eb3888481518110612e9857612e9861599f565b602002602001015188888581518110612d8357612d8361599f565b50505b80612ec0816159d7565b915050612cb7565b50505050565b612ed6613f0c565b601c5460ff1615612ef95760405162461bcd60e51b8152600401610e1f90615af6565b60035461010090046001600160a01b03163314612f285760405162461bcd60e51b8152600401610e1f90615c15565b6000612f33836130c0565b9050600181118015612f46575060055481105b15612f5057506005545b8115612fa45760006001821115612f6f57612f6a8261474b565b612f7c565b6019546001600160a01b03165b600354600454919250612fa2916001600160a01b03908116916101009004168386613f32565b505b60008181526010602090815260408083206001600160a01b038716845290915290205460ff1615611dbf5760008181526011602090815260408083206001600160a01b03871684529091529020805460ff19166001179055505050565b6005546000908152600b602090815260408083206001600160a01b038516845290915281205415158061307857506000600b60006005546001613044919061591a565b81526020019081526020016000206000846001600160a01b03166001600160a01b0316815260200190815260200160002054115b8015610dcb57506001600160a01b0382166000908152600d602052604090205460ff161580610dcb5750506001600160a01b03166000908152600e6020526040902054151590565b6001600160a01b038116600090815260126020526040812054908190036133725781600080805b836001600160a01b03166362e5c8196040518163ffffffff1660e01b8152600401602060405180830381865afa158015613125573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131499190615c3a565b81101561336d5760405163b1283e7760e01b8152600481018290526001600160a01b0385169063b1283e779060240161012060405180830381865afa158015613196573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ba9190615c76565b505060215460405163bf40fac160e01b815260206004820152601660248201527529b837b93a39a0a6a6ab192934b9b5a6b0b730b3b2b960511b6044820152949a5095985060009650506001600160a01b03909416935063bf40fac1925050606401602060405180830381865afa158015613239573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061325d9190615b5d565b6040516349ef3bc960e11b815261ffff851660048201526001600160a01b0391909116906393de779290602401602060405180830381865afa1580156132a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132cb91906158bd565b9050600754841180156132dc575080155b156133505781600003613315576006546007546132f990866158f0565b61330391906159b5565b61330e90600261591a565b955061335a565b856006546007548661332791906158f0565b61333191906159b5565b61333c90600261591a565b1461334b57600195505061336d565b61335a565b600195505061336d565b5080613365816159d7565b9150506130e7565b505050505b919050565b61337f613e07565b610f5581613c71565b600654600090610db46002846158f0565b6133a1613e07565b610f5581613c3c565b6001600260008282546133bd919061591a565b90915550506002546133cd613f0c565b601c5460ff166133ef5760405162461bcd60e51b8152600401610e1f90615947565b600554600090815260096020526040902054601d54146134485760405162461bcd60e51b8152602060048201526014602482015273139bdd105b1b155cd95c9cd41c9bd8d95cdcd95960621b6044820152606401610e1f565b601c805460ff19169055600554600090815260086020908152604080832054600b83528184206019546001600160a01b03908116865293529220549116901561353157600554600090815260136020908152604080832054600b83528184206019546001600160a01b03168552909252822054670de0b6b3a7640000916134ce91615903565b6134d891906159b5565b6019546004549192506134fa916001600160a01b039081169185911684613f32565b601954604051600080516020615dec83398151915291613527916001600160a01b039091169084906158a4565b60405180910390a1505b60055460020361355e576005546000908152601360209081526040808320546014909252909120556135c1565b600554600081815260136020526040812054670de0b6b3a764000092909160149161358b906001906158f0565b8152602001908152602001600020546135a49190615903565b6135ae91906159b5565b6005546000908152601460205260409020555b6005600081546135d0906159d7565b90915550600480546040516370a0823160e01b81526001600160a01b03909116916370a082319161360391859101615594565b602060405180830381865afa158015613620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136449190615c3a565b6005546000908152600c60205260408120805490919061366590849061591a565b90915550506005546000818152600b602090815260408083206019546001600160a01b03168452825280832054938352600c9091529020546136a791906158f0565b601b556005546000906136b99061474b565b600480546040516370a0823160e01b815292935061374692859285926001600160a01b0316916370a08231916136f191869101615594565b602060405180830381865afa15801561370e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137329190615c3a565b6004546001600160a01b0316929190613f32565b6000601d556005547fc67dda8e11f1aa941c7e74466b1859a07a32f46aaf641d29b83be348424d93cd9061377c906001906158f0565b60136000600160055461378f91906158f0565b815260200190815260200160002054604051612353929190918252602082015260400190565b6137bd613e07565b6001600160a01b0381166137e35760405162461bcd60e51b8152600401610e1f90615b38565b60035461010090046001600160a01b031615613878576004805460035460405163095ea7b360e01b81526001600160a01b039283169363095ea7b3936138339361010090041691600091016158a4565b6020604051808303816000875af1158015613852573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061387691906158bd565b505b60038054610100600160a81b0319166101006001600160a01b03848116820292909217928390556004805460405163095ea7b360e01b81529084169463095ea7b3946138cd94909104169160001991016158a4565b6020604051808303816000875af11580156138ec573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061391091906158bd565b507f576297e5fcc8cd907ee80b240284865eb3d821bdc5232e6ee9e4d78a12531c0981604051610ee29190615594565b6000612aab600554614d25565b600160026000828254613960919061591a565b9091555050600254613970613f0c565b601c5460ff16156139935760405162461bcd60e51b8152600401610e1f90615af6565b61175c8260016140f5565b60035460ff16156139e75760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610e1f565b6003805460ff19166001908117909155600255565b600454600090600160a01b900460ff161580613a215750613a1e600554610da3565b42105b15613a2c5750600090565b6005546000908152600f60209081526040808320546023909252822054829190805b82811015613b39576005546000908152600f60205260409020805482908110613a7957613a7961599f565b600091825260208083209091015460055483526011825260408084206001600160a01b039092168085529190925291205490945060ff16613b2957839450846001600160a01b031663b0c56f056040518163ffffffff1660e01b8152600401602060405180830381865afa158015613af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b1991906158bd565b613b295760009550505050505090565b613b32816159d7565b9050613a4e565b50600194505050505090565b60215460405163bf40fac160e01b8152602060048201526009602482015268141c9a58d95199595960ba1b60448201526000916001600160a01b03169063bf40fac190606401602060405180830381865afa158015613ba8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bcc9190615b5d565b6001600160a01b031663ac82f6086022546040518263ffffffff1660e01b8152600401613bfb91815260200190565b602060405180830381865afa158015613c18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612aab9190615c3a565b60158190556040518181527f8c43aa02599ac8f8bab4724621ceea5e7a06b07bbbfaf3b7bd0386cbe481ea3c90602001610ee2565b60168190556040518181527f990717cc219e5348c1b88bb0ff530d804f0b6f54f3b03844a2bfbe4eb1e9c5d690602001610ee2565b60178190556040518181527fe7c2c09f66c8b970b4a99250f4d0844e1496b9d51d4760a17b0134ddd52023e190602001610ee2565b670de0b6b3a7640000811115613d255760405162461bcd60e51b815260206004820152600f60248201526e0aae8d2d8a4c2e8caa8dede90d2ced608b1b6044820152606401610e1f565b601e8190556040518181527fc117ccf765672707ebe3c1606037488c1e27dc1f42b5266e3d6b496db7d4209e90602001610ee2565b670de0b6b3a7640000811115613da95760405162461bcd60e51b81526020600482015260146024820152730a6c2ccca84def092dae0c2c6e8a8dede90d2ced60631b6044820152606401610e1f565b601f80546001600160a01b0319166001600160a01b03841617905560208190556040517fa1a8623472ca4e2879372be60dfd1ff0675778e49f7379eedd98ca57cf36b21a90613dfb90849084906158a4565b60405180910390a15050565b6000546001600160a01b031633146117085760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610e1f565b613e81614ea7565b6000613e8b614b15565b805460ff1916815590507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051610ee29190615594565b613ecd613f0c565b6000613ed7614b15565b805460ff1916600117815590507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613eb83390565b613f14611dc4565b156117085760405163d93c066560e01b815260040160405180910390fd5b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052612ec8908590614ecc565b6000818152600f60209081526040808320546023909252909120545b818110801561400857506000838152601160209081526040808320600f9092528220805491929184908110613fdf57613fdf61599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b1561401557600101613fa8565b805b82811015614070576000848152600f60205260409020805461405f918691849081106140455761404561599f565b6000918252602090912001546001600160a01b0316614f26565b50614069816159d7565b9050614017565b505b81811080156140d257506000838152601160209081526040808320600f90925282208054919291849081106140a9576140a961599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b156140df57600101614072565b6000928352602360205260409092209190915550565b600082116141155760405162461bcd60e51b8152600401610e1f90615978565b6000818152600f6020908152604080832054602390925282205490915b828210801561419257506000848152601160209081526040808320600f90925282208054919291859081106141695761416961599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b801561419f57506103e881105b156141b05760019182019101614132565b6103e881106141d15750600092835260236020526040909220919091555050565b6000825b84811080156141e357508682105b1561422a576000868152600f60205260409020805461420e918891849081106140455761404561599f565b1561421a578160010191505b614223816159d7565b90506141d5565b505b838310801561428c57506000858152601160209081526040808320600f90925282208054919291869081106142635761426361599f565b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff165b801561429957506103e882105b156142af5782600101925081600101915061422c565b5050600092835260236020526040909220919091555050565b6005548211806142d85750816001145b6143195760405162461bcd60e51b8152602060048201526012602482015271149bdd5b99105b1c9958591e50db1bdcd95960721b6044820152606401610e1f565b6000614324846130c0565b9050600554811461436a5760405162461bcd60e51b815260206004820152601060248201526f151a58dad95d139bdd125b949bdd5b9960821b6044820152606401610e1f565b60008181526010602090815260408083206001600160a01b038816845290915290205460ff166143ac5760405162461bcd60e51b8152600401610e1f90615be4565b60008181526011602090815260408083206001600160a01b038816845290915290205460ff16156144185760405162461bcd60e51b8152602060048201526016602482015275151a58dad95d105b1c9958591e515e195c98da5cd95960521b6044820152606401610e1f565b836001600160a01b0316633f6fa6556040518163ffffffff1660e01b8152600401602060405180830381865afa158015614456573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061447a91906158bd565b156144bf5760405162461bcd60e51b8152602060048201526015602482015274151a58dad95d105b1c9958591e54995cdbdb1d9959605a1b6044820152606401610e1f565b60008181526010602090815260408083206001600160a01b03881684529091529020805460ff191690556144f48185846151e1565b60006144ff8261474b565b9050600061450c8561474b565b90506000866001600160a01b031663d165dac26040518163ffffffff1660e01b8152600401602060405180830381865afa15801561454e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145729190615c3a565b600480546040516370a0823160e01b81526001600160a01b03909116916370a08231916145a1918c9101615594565b602060405180830381865afa1580156145be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145e29190615c3a565b6145ec91906158f0565b600480546040516370a0823160e01b81529293506000926001600160a01b03909116916370a082319161462191879101615594565b602060405180830381865afa15801561463e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146629190615c3a565b90508082111561468757600061467882846158f0565b905061468581858a614925565b505b60045461469f906001600160a01b0316848685613f32565b6001600160a01b03881660008181526012602090815260408083208b90558a8352601082528083208484528252808320805460ff191660019081179091558b8452600f8352818420805491820181558452919092200180546001600160a01b031916909217909155517fd8edac6470af12f863b07d43de4b58079798e80230a8b7f899a4f55ecdac618090614739908a9088908b90615d1c565b60405180910390a15050505050505050565b6000818152600860205260409020546001600160a01b03168061337257816001036147a5575060198054600083815260086020526040902080546001600160a01b0319166001600160a01b03928316179055905416919050565b601a546001600160a01b03166147f95760405162461bcd60e51b8152602060048201526019602482015278149bdd5b99141bdbdb13585cdd195c98dbdc1e539bdd14d95d603a1b6044820152606401610e1f565b601a54600090614811906001600160a01b0316615407565b6004549091506001600160a01b038083169163d13f90b4913091168661483b6104dc6001836158f0565b61484489610da3565b6040516001600160e01b031960e088901b1681526001600160a01b03958616600482015294909316602485015260448401919091526064830152608482015260a401600060405180830381600087803b1580156148a057600080fd5b505af11580156148b4573d6000803e3d6000fd5b50505060008481526008602090815260409182902080546001600160a01b0319166001600160a01b03861690811790915582518781529182015292935083927f24c1b21b902a85b5039d7d72427d9376657229eea77880ec9e62031dc950f6ba92500160405180910390a150919050565b6019546001600160a01b031661494d5760405162461bcd60e51b8152600401610e1f90615d3d565b60195460045461496b916001600160a01b0391821691168486613f32565b6000818152600b602090815260408083206019546001600160a01b031684529091528120805485929061499f90849061591a565b90915550506000818152600c6020526040812080548592906149c290849061591a565b9091555050601954604051600080516020615e0c833981519152916149f6916001600160a01b039091169086908590615d1c565b60405180910390a1505050565b6019546001600160a01b0316614a2b5760405162461bcd60e51b8152600401610e1f90615d3d565b601954600354600454614a55926001600160a01b0391821692908216916101009091041684613f32565b6019546001600160a01b031660009081527f72c6bfb7988af3a1efa6568f02a999bc52252641c659d85961ca3d372b57d5cf602052604081208054839290614a9e90849061591a565b909155505060016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c8054839290614ae090849061591a565b9091555050601954604051600080516020615e0c83398151915291610ee2916001600160a01b03909116908490600190615d1c565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330090565b60006005546001614b4a919061591a565b90506000614b578261474b565b600454909150614b72906001600160a01b0316338386613f32565b6019546001600160a01b03163303614bcc5760405162461bcd60e51b815260206004820152601e60248201527f43616e744465706f7369744469726563746c79417344656661756c744c5000006044820152606401610e1f565b6005546000908152600b60209081526040808320338452909152902054158015614c0d57506000828152600b60209081526040808320338452909152902054155b15614c985760175460185410614c575760405162461bcd60e51b815260206004820152600f60248201526e13585e155cd95c9cd4995858da1959608a1b6044820152606401610e1f565b60008281526009602090815260408220805460018181018355918452919092200180546001600160a01b03191633179055601854614c949161591a565b6018555b6000828152600b6020908152604080832033845290915281208054859290614cc190849061591a565b90915550506000828152600c602052604081208054859290614ce490849061591a565b9250508190555082601b6000828254614cfd919061591a565b9091555050600554604051600080516020615e0c833981519152916149f69133918791615d1c565b6000818152600f6020908152604080832054602390925282205482918291805b82811015614e9a576000878152600f60205260409020805482908110614d6d57614d6d61599f565b60009182526020808320909101548983526011825260408084206001600160a01b039092168085529190925291205490945060ff16614e8857839450846001600160a01b031663e74d3c476040518163ffffffff1660e01b8152600401602060405180830381865afa158015614de7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e0b91906158bd565b8015614e765750846001600160a01b0316633356a35a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614e50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e7491906158bd565b155b15614e88575060019695505050505050565b80614e92816159d7565b915050614d45565b5060009695505050505050565b614eaf611dc4565b61170857604051638dfc202b60e01b815260040160405180910390fd5b6000614ee16001600160a01b03841683615474565b90508051600014158015614f06575080806020019051810190614f0491906158bd565b155b15611dbf5782604051635274afe760e01b8152600401610e1f9190615594565b60008281526011602090815260408083206001600160a01b038516845290915281205460ff16610dcb5760008290506000816001600160a01b0316633356a35a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614f95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614fb991906158bd565b9050600080600187111561502c57836001600160a01b0316634652e3306040518163ffffffff1660e01b8152600401602060405180830381865afa158015615005573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061502991906158bd565b90505b808015615040575061503d87610da3565b42115b1561504a57600191505b836001600160a01b031663e74d3c476040518163ffffffff1660e01b8152600401602060405180830381865afa158015615088573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906150ac91906158bd565b80156150bd57508215806150bd5750815b1561512c57600354604051630f8a940b60e41b81526101009091046001600160a01b03169063f8a940b0906150f9908990600090600401615d66565b600060405180830381600087803b15801561511357600080fd5b505af1158015615127573d6000803e3d6000fd5b505050505b828015615137575080155b8061519f5750836001600160a01b0316633f6fa6556040518163ffffffff1660e01b8152600401602060405180830381865afa15801561517b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061519f91906158bd565b156151d75760008781526011602090815260408083206001600160a01b038a1684529091529020805460ff1916600190811790915594505b5050505092915050565b60008160000361526c5760005b6000858152600f6020526040902054811015615266576000858152600f6020526040902080546001600160a01b0386169190839081106152305761523061599f565b6000918252602090912001546001600160a01b0316036152565760019150809250615266565b61525f816159d7565b90506151ee565b506152ca565b6000848152600f6020526040902054821080156152c757506000848152600f6020526040902080546001600160a01b0385169190849081106152b0576152b061599f565b6000918252602090912001546001600160a01b0316145b90505b806153085760405162461bcd60e51b815260206004820152600e60248201526d151a58dad95d139bdd119bdd5b9960921b6044820152606401610e1f565b600084815260236020526040902054808310156153315760008581526023602052604090208390555b6000858152600f60205260409020805461534d906001906158f0565b8154811061535d5761535d61599f565b6000918252602080832090910154878352600f909152604090912080546001600160a01b0390921691859081106153965761539661599f565b600091825260208083209190910180546001600160a01b0319166001600160a01b039490941693909317909255868152600f909152604090208054806153de576153de615d86565b600082815260209020810160001990810180546001600160a01b03191690550190555050505050565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008260601b60e81c176000526e5af43d82803e903d91602b57fd5bf38260781b17602052603760096000f090506001600160a01b038116613372576040516330be1a3d60e21b815260040160405180910390fd5b6060612a988383600084600080856001600160a01b0316848660405161549a9190615d9c565b60006040518083038185875af1925050503d80600081146154d7576040519150601f19603f3d011682016040523d82523d6000602084013e6154dc565b606091505b50915091506154ec8683836154f6565b9695505050505050565b60608261550b5761550682615549565b612a98565b815115801561552257506001600160a01b0384163b155b156155425783604051639996b31560e01b8152600401610e1f9190615594565b5080612a98565b8051156155595780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6000806040838503121561558557600080fd5b50508035926020909101359150565b6001600160a01b0391909116815260200190565b600061018082840312156155bb57600080fd5b50919050565b6000602082840312156155d357600080fd5b5035919050565b6001600160a01b0381168114610f5557600080fd5b60006020828403121561560157600080fd5b8135612a98816155da565b8015158114610f5557600080fd5b60006020828403121561562c57600080fd5b8135612a988161560c565b6000806040838503121561564a57600080fd5b82359150602083013561565c816155da565b809150509250929050565b60008060006060848603121561567c57600080fd5b8335615687816155da565b95602085013595506040909401359392505050565b600080604083850312156156af57600080fd5b82356156ba816155da565b946020939093013593505050565b600080600080608085870312156156de57600080fd5b84356156e9816155da565b966020860135965060408601359560600135945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561574257615742615703565b604052919050565b600067ffffffffffffffff82111561576457615764615703565b5060051b60200190565b600082601f83011261577f57600080fd5b8135602061579461578f8361574a565b615719565b82815260059290921b840181019181810190868411156157b357600080fd5b8286015b848110156157ce57803583529183019183016157b7565b509695505050505050565b6000806000606084860312156157ee57600080fd5b833567ffffffffffffffff8082111561580657600080fd5b818601915086601f83011261581a57600080fd5b8135602061582a61578f8361574a565b82815260059290921b8401810191818101908a84111561584957600080fd5b948201945b83861015615870578535615861816155da565b8252948201949082019061584e565b975050870135945050604086013591508082111561588d57600080fd5b5061589a8682870161576e565b9150509250925092565b6001600160a01b03929092168252602082015260400190565b6000602082840312156158cf57600080fd5b8151612a988161560c565b634e487b7160e01b600052601160045260246000fd5b81810381811115610dcb57610dcb6158da565b8082028115828204841417610dcb57610dcb6158da565b80820180821115610dcb57610dcb6158da565b6001600160a01b0392831681529116602082015260400190565b602080825260179082015276149bdd5b9910db1bdcda5b99d39bdd141c995c185c9959604a1b604082015260600190565b6020808252600d908201526c426174636853697a655a65726f60981b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6000826159d257634e487b7160e01b600052601260045260246000fd5b500490565b6000600182016159e9576159e96158da565b5060010190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6020808252600e908201526d141bdbdb139bdd14dd185c9d195960921b604082015260600190565b6020808252601a908201527f5769746864726177616c416c7265616479526571756573746564000000000000604082015260600190565b6020808252601190820152704e6f7468696e67546f576974686472617760781b604082015260600190565b60208082526025908201527f43616e7457697468647261775768656e4465706f7369746564466f724e657874604082015264149bdd5b9960da1b606082015260800190565b60208082526022908201527f4e6f74416c6c6f7765645768656e526f756e64436c6f73696e67507265706172604082015261195960f21b606082015260800190565b6020808252600b908201526a5a65726f4164647265737360a81b604082015260600190565b600060208284031215615b6f57600080fd5b8151612a98816155da565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b03831681526040810160048310615bb057615bb0615b7a565b8260208301529392505050565b6020808252600d908201526c24b73b30b634b229b2b73232b960991b604082015260600190565b602080825260179082015276151a58dad95d139bdd125b90dd5c9c995b9d149bdd5b99604a1b604082015260600190565b6020808252600b908201526a4f6e6c7946726f6d414d4d60a81b604082015260600190565b600060208284031215615c4c57600080fd5b5051919050565b805161ffff8116811461337257600080fd5b805160ff8116811461337257600080fd5b60008060008060008060008060006101208a8c031215615c9557600080fd5b89519850615ca560208b01615c53565b9750615cb360408b01615c53565b965060608a01519550615cc860808b01615c65565b945060a08a01518060020b8114615cde57600080fd5b60c08b015190945062ffffff81168114615cf757600080fd5b9250615d0560e08b01615c65565b91506101008a015190509295985092959850929598565b6001600160a01b039390931683526020830191909152604082015260600190565b6020808252600f908201526e111959985d5b1d1314139bdd14d95d608a1b604082015260600190565b6001600160a01b03831681526040810160038310615bb057615bb0615b7a565b634e487b7160e01b600052603160045260246000fd5b6000825160005b81811015615dbd5760208186018101518583015201615da3565b50600092019182525091905056feb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159cd8138f8a3f377c5259ca548e70e4c2de94f129f5a11036a15b69513cba2b426a73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488caa2646970667358221220310d75667c11da0759cc7cca5eeca112f6bf84d1871f496d888881b210675d7664736f6c63430008140033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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