Contract Address Details

0x344A2849fB94bF5635C0768B07471B64E2A388C1

Contract Name
EnergyBridge
Creator
0x8be58f–437e45 at 0x93e6e0–4a01b7
Balance
0 VT
Tokens
Fetching tokens...
Transactions
1 Transactions
Transfers
0 Transfers
Gas Used
24,605
Last Balance Update
29738744
Contract name:
EnergyBridge




Optimization enabled
true
Compiler version
v0.8.17+commit.8df45f5f




Optimization runs
200
Verified at
2023-08-04T09:34:46.009720Z

contracts/EnergyBridge.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/// @title Bridging contract between Energy Web tier 1 (T1) and AVN tier 2 (T2) blockchains
/// @author Aventus Network Services
/** @notice
  Enables POS collators to periodically publish the transactional state of T2 to this contract.
  Enables collators to be added and removed from participating in consensus.
  Enables the "lifting" of any EWT or ERC20 tokens received, locking them in the contract to be recreated on T2.
  Enables the "lowering" of EWT and ERC20 tokens, unlocking them from the contract via proof of their destruction on T2.
*/
/// @dev Proxy upgradeable implementation utilising EIP-1822

import "./interfaces/IEnergyBridge.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract EnergyBridge is IEnergyBridge, Initializable, UUPSUpgradeable, OwnableUpgradeable {
  uint256 constant internal SIGNATURE_LENGTH = 65;
  uint256 constant internal LIFT_LIMIT = type(uint128).max;
  address constant internal PSEUDO_EWT_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

  /// @notice Query a collator's current registration status by their internal ID
  mapping (uint256 => bool) public isRegisteredCollator;
  /// @notice Query a collator's current activation status by their internal ID
  mapping (uint256 => bool) public isActiveCollator;
  /// @notice Query a collator's persistent internal collator ID by their T1 address
  mapping (address => uint256) public t1AddressToId;
  /// @notice Query a collator's persistent internal collator ID by their T2 public key
  mapping (bytes32 => uint256) public t2PublicKeyToId;
  /// @notice Query a collator's persistent T1 address by their internal collator ID
  mapping (uint256 => address) public idToT1Address;
  /// @notice Query a collator's persistent T2 public key by their internal collator ID
  mapping (uint256 => bytes32) public idToT2PublicKey;
  /// @notice Mapping of T2 extrinsic IDs to the number of bytes that require traversing in a leaf before reaching lower data
  mapping (bytes2 => uint256) public numBytesToLowerData;
  /// @notice Query whether a particular Merkle tree root hash of T2 state has been published
  mapping (bytes32 => bool) public isPublishedRootHash;
  /// @notice Query whether a unique T2 transaction ID has been used
  mapping (uint256 => bool) public isUsedT2TransactionId;
  /// @notice Query whether the hash of a T2 lower transaction leaf has been used to claim its lowered funds on T1
  mapping (bytes32 => bool) public hasLowered;

  uint256[2] public quorum;
  uint256 public numActiveCollators;
  uint256 public nextCollatorId;
  bool public collatorFunctionsAreEnabled;
  bool public liftingIsEnabled;
  bool public loweringIsEnabled;

  error LiftingIsDisabled();
  error CollatorFunctionsAreDisabled();
  error MissingCollatorKeys();
  error AddressAlreadyInUse(address t1Address);
  error T2PublicKeyAlreadyInUse(bytes32 t2PublicKey);
  error AddressMismatch(address t1Address, bytes t1PublicKey);
  error InvalidQuorum();
  error CannotReceiveEWTUnlessLifting();
  error AmountCannotBeZero();
  error OwnerOnly();
  error InvalidT1PublicKey();
  error CollatorAlreadyRegistered();
  error CannotChangeT2PublicKey(bytes32 existingT2PublicKey);
  error CollatorNotRegistered();
  error RootHashAlreadyPublished();
  error LiftLimitExceeded();
  error LoweringIsDisabled();
  error InvalidLowerData();
  error LowerAlreadyUsed();
  error UnsignedTransaction();
  error NotALowerTransaction();
  error PaymentFailed();
  error InvalidConfirmations();
  error TransactionIdAlreadyUsed();
  error InvalidT2PublicKey();

  function initialize()
    public
    initializer
  {
    __Ownable_init();
    numBytesToLowerData[0x5900] = 133; // callID (2 bytes) + proof (2 prefix + 32 relayer + 32 signer + 1 prefix + 64 signature)
    numBytesToLowerData[0x5700] = 133; // callID (2 bytes) + proof (2 prefix + 32 relayer + 32 signer + 1 prefix + 64 signature)
    numBytesToLowerData[0x5702] = 2;   // callID (2 bytes)
    collatorFunctionsAreEnabled = true;
    liftingIsEnabled = true;
    loweringIsEnabled = true;
    nextCollatorId = 1;
    quorum[0] = 2;
    quorum[1] = 3;
  }

  modifier onlyWhenLiftingIsEnabled() {
    if (!liftingIsEnabled) revert LiftingIsDisabled();
    _;
  }

  modifier onlyWhenCollatorFunctionsAreEnabled() {
    if (!collatorFunctionsAreEnabled) revert CollatorFunctionsAreDisabled();
    _;
  }

  /// @notice Bulk initialise a set of collators
  /// @param t1Address Array of T1 addresses
  /// @param t1PublicKeyLHS Array of 32 leftmost bytes of T1 public keys corresponding to addresses
  /// @param t1PublicKeyRHS Array of 32 rightmost bytes of T1 public keys corresponding to addresses
  /// @param t2PublicKey Array of 32 byte sr25519 public key values
  /// @dev This is useful for seting up existing networks, after which registerCollator should be used instead
  function loadCollators(address[] calldata t1Address, bytes32[] calldata t1PublicKeyLHS, bytes32[] calldata t1PublicKeyRHS,
      bytes32[] calldata t2PublicKey)
    onlyOwner
    external
  {
    uint256 numToLoad = t1Address.length;
    bytes32 _t2PublicKey;
    address _t1Address;
    bytes memory t1PublicKey;

    if (t1PublicKeyLHS.length != numToLoad && t1PublicKeyRHS.length != numToLoad && t2PublicKey.length != numToLoad) {
      revert MissingCollatorKeys();
    }

    for (uint256 i; i < numToLoad;) {
      _t1Address = t1Address[i];
      _t2PublicKey = t2PublicKey[i];
      if (t1AddressToId[_t1Address] != 0) revert AddressAlreadyInUse(_t1Address);
      if (t2PublicKeyToId[_t2PublicKey] != 0) revert T2PublicKeyAlreadyInUse(_t2PublicKey);
      t1PublicKey = abi.encodePacked(t1PublicKeyLHS[i], t1PublicKeyRHS[i]);
      if (address(uint160(uint256(keccak256(t1PublicKey)))) != _t1Address) revert AddressMismatch(_t1Address, t1PublicKey);
      idToT1Address[nextCollatorId] = _t1Address;
      idToT2PublicKey[nextCollatorId] = _t2PublicKey;
      t1AddressToId[_t1Address] = nextCollatorId;
      t2PublicKeyToId[_t2PublicKey] = nextCollatorId;
      isRegisteredCollator[nextCollatorId] = true;
      isActiveCollator[nextCollatorId] = true;
      unchecked {
        numActiveCollators++;
        nextCollatorId++;
        i++;
      }
    }
  }

  /// @notice Set the proportion of active collators required to prove T2 collator consensus
  /// @param _quorum 2 element array of ratio's numerator followed by its denominator
  /// @dev Number of collators * quorum[0] / quorum[1] + 1 = confirmations required for a collator function to succeed
  function setQuorum(uint256[2] memory _quorum)
    onlyOwner
    public
  {
    if (_quorum[0] == 0 || _quorum[0] > _quorum[1]) revert InvalidQuorum();
    quorum = _quorum;
    emit LogQuorumUpdated(quorum);
  }

  /// @notice Switch all collator functions on or off
  /// @param state true = functions on, false = functions off
  function toggleCollatorFunctions(bool state)
    onlyOwner
    external
  {
    collatorFunctionsAreEnabled = state;
    emit LogCollatorFunctionsAreEnabled(state);
  }

  /// @notice Switch all lifting functions on or off
  /// @param state true = functions on, false = functions off
  function toggleLifting(bool state)
    onlyOwner
    external
  {
    liftingIsEnabled = state;
    emit LogLiftingIsEnabled(state);
  }

  /// @notice Switch the lower function on or off
  /// @param state true = function on, false = function off
  function toggleLowering(bool state)
    onlyOwner
    external
  {
    loweringIsEnabled = state;
    emit LogLoweringIsEnabled(state);
  }

  /// @notice Add or update T2 lower methods
  /// @param callId the call index of the extrinsic in T2
  /// @param numBytes the distance (in bytes) required to reach relevant lower data arguments encoded within a transaction leaf
  function updateLowerCall(bytes2 callId, uint256 numBytes)
    onlyOwner
    external
  {
    numBytesToLowerData[callId] = numBytes;
    emit LogLowerCallUpdated(callId, numBytes);
  }

  receive() payable external {
    revert CannotReceiveEWTUnlessLifting();
  }

  /// @notice Register a new collator, allowing them to participate in consensus
  /// @param t1PublicKey 64 byte T1 public key of collator
  /// @param t2PublicKey 32 byte sr25519 public key of collator
  /// @param t2TransactionId Unique transaction ID
  /// @param confirmations Concatenated collator-signed confirmations of the transaction details
  /** @dev
    This permanently associates the collator's T1 address with their T2 public key.
    May also be used to re-register a previously deregistered collator, providing their associated accounts do not change.
    Does not immediately activate the collator.
    Activation instead occurs upon receiving the first set of confirmations which include the newly registered collator.
    Emits a collator registration event to be read by T2.
  */
  function registerCollator(bytes memory t1PublicKey, bytes32 t2PublicKey, uint256 t2TransactionId,
      bytes calldata confirmations)
    onlyWhenCollatorFunctionsAreEnabled
    external
  {
    if (t1PublicKey.length != 64) revert InvalidT1PublicKey();
    address t1Address = address(uint160(uint256(keccak256(t1PublicKey))));
    uint256 id = t1AddressToId[t1Address];
    if (isRegisteredCollator[id]) revert CollatorAlreadyRegistered();

    // The order of the elements is the reverse of the deregisterCollatorHash
    bytes32 registerCollatorHash = keccak256(abi.encodePacked(t1PublicKey, t2PublicKey));
    _verifyConfirmations(_toConfirmationHash(registerCollatorHash, t2TransactionId), confirmations);
    _storeT2TransactionId(t2TransactionId);

    if (id == 0) {
      if (t2PublicKeyToId[t2PublicKey] != 0) revert T2PublicKeyAlreadyInUse(t2PublicKey);
      id = nextCollatorId;
      idToT1Address[id] = t1Address;
      t1AddressToId[t1Address] = id;
      idToT2PublicKey[id] = t2PublicKey;
      t2PublicKeyToId[t2PublicKey] = id;
      unchecked { nextCollatorId++; }
    } else {
      if (t2PublicKey != idToT2PublicKey[id]) revert CannotChangeT2PublicKey(idToT2PublicKey[id]);
    }

    isRegisteredCollator[id] = true;

    bytes32 t1PublicKeyLHS;
    bytes32 t1PublicKeyRHS;
    assembly {
      t1PublicKeyLHS := mload(add(t1PublicKey, 0x20))
      t1PublicKeyRHS := mload(add(t1PublicKey, 0x40))
    }

    emit LogCollatorRegistered(t1PublicKeyLHS, t1PublicKeyRHS, t2PublicKey, t2TransactionId);
  }

  /// @notice Deregister and deactivate a collator, removing them from consensus
  /// @param t1PublicKey 64 byte T1 public key of collator
  /// @param t2PublicKey 32 byte sr25519 public key of collator
  /// @param t2TransactionId Unique transaction ID
  /// @param confirmations Concatenated collator-signed confirmations of the transaction details
  /** @dev
    Collator details are retained.
    Emits a collator deregistration event to be read by T2.
  */
  function deregisterCollator(bytes memory t1PublicKey, bytes32 t2PublicKey, uint256 t2TransactionId,
      bytes calldata confirmations)
    onlyWhenCollatorFunctionsAreEnabled
    external
  {
    uint256 id = t2PublicKeyToId[t2PublicKey];
    if (!isRegisteredCollator[id]) revert CollatorNotRegistered();

    isRegisteredCollator[id] = false;

    if (isActiveCollator[id]) {
      isActiveCollator[id] = false;
      unchecked { numActiveCollators--; }
    }

    // The order of the elements is the reverse of the registerCollatorHash
    bytes32 deregisterCollatorHash = keccak256(abi.encodePacked(t2PublicKey, t1PublicKey));
    _verifyConfirmations(_toConfirmationHash(deregisterCollatorHash, t2TransactionId), confirmations);
    _storeT2TransactionId(t2TransactionId);

    bytes32 t1PublicKeyLHS;
    bytes32 t1PublicKeyRHS;
    assembly {
      t1PublicKeyLHS := mload(add(t1PublicKey, 0x20))
      t1PublicKeyRHS := mload(add(t1PublicKey, 0x40))
    }

    emit LogCollatorDeregistered(t1PublicKeyLHS, t1PublicKeyRHS, t2PublicKey, t2TransactionId);
  }

  /// @notice Stores a Merkle tree root hash representing the latest set of transactions to have occurred on T2
  /// @param rootHash 32 byte keccak256 hash of the Merkle tree root
  /// @param t2TransactionId Unique transaction ID
  /// @param confirmations Concatenated collator-signed confirmations of the transaction details
  /// @dev Emits a root published event to be read by T2
  function publishRoot(bytes32 rootHash, uint256 t2TransactionId, bytes calldata confirmations)
    onlyWhenCollatorFunctionsAreEnabled
    external
  {
    _verifyConfirmations(_toConfirmationHash(rootHash, t2TransactionId), confirmations);
    _storeT2TransactionId(t2TransactionId);
    if (isPublishedRootHash[rootHash]) revert RootHashAlreadyPublished();
    isPublishedRootHash[rootHash] = true;
    emit LogRootPublished(rootHash, t2TransactionId);
  }

  /// @notice Lift an amount of ERC20 tokens to the specified T2 recipient, providing the amount has first been approved
  /// @param erc20Address address of the ERC20 token contract
  /// @param t2PublicKey 32 byte sr25519 public key value of the T2 recipient account
  /// @param amount of token to lift (in the token's full decimals)
  /** @dev
    Locks the tokens in the contract and emits a corresponding lift event to be read by T2.
    Fails if no recipient is specified (though only the byte length of the recipient can be checked so care is required).
    Fails if it causes the total amount of the token held in this contract to exceed uint128 max (this is a T2 constraint).
  */
  function lift(address erc20Address, bytes calldata t2PublicKey, uint256 amount)
    onlyWhenLiftingIsEnabled
    external
  {
    if (amount == 0) revert AmountCannotBeZero();
    IERC20 erc20Contract = IERC20(erc20Address);
    uint256 currentBalance = erc20Contract.balanceOf(address(this));
    assert(erc20Contract.transferFrom(msg.sender, address(this), amount));
    uint256 newBalance = erc20Contract.balanceOf(address(this));
    if (newBalance > LIFT_LIMIT) revert LiftLimitExceeded();
    emit LogLifted(erc20Address, msg.sender, _checkT2PublicKey(t2PublicKey), newBalance - currentBalance);
  }


  /// @notice Lift all EWT sent to the specified T2 recipient
  /// @param t2PublicKey 32 byte sr25519 public key value of the T2 recipient account
  /** @dev
    Locks the EWT in the contract and emits a corresponding lift event to be read by T2.
    Fails if no recipient is specified (though only the byte length of the recipient can be checked so care is required).
  */
  function liftEWT(bytes calldata t2PublicKey)
    payable
    onlyWhenLiftingIsEnabled
    external
  {
    if (msg.value == 0) revert AmountCannotBeZero();
    emit LogLifted(PSEUDO_EWT_ADDRESS, msg.sender, _checkT2PublicKey(t2PublicKey), msg.value);
  }

  /// @notice Unlock ERC20/EWT to the recipient specified in the transaction leaf, providing the T2 state is published
  /// @param leaf Raw encoded T2 transaction data
  /// @param merklePath Array of hashed leaves lying between the transaction leaf and the Merkle tree root hash
  /// @dev Anyone may call this method since the recipient of the tokens is governed by the content of the leaf
  function lower(bytes memory leaf, bytes32[] calldata merklePath)
    external
  {
    if (!loweringIsEnabled) revert LoweringIsDisabled();
    bytes32 leafHash = keccak256(leaf);
    if (!confirmTransaction(leafHash, merklePath)) revert InvalidLowerData();
    if (hasLowered[leafHash]) revert LowerAlreadyUsed();
    uint256 numBytes;
    uint256 ptr;
    bytes32 t2PublicKey;
    address token;
    address t1Address;
    uint128 amount;
    bytes2 callId;
    hasLowered[leafHash] = true;

    unchecked {
      ptr += _getCompactIntegerByteSize(leaf[ptr]); // add number of bytes encoding the leaf length
      if (uint8(leaf[ptr]) & 128 == 0) revert UnsignedTransaction(); // bitwise version check to ensure leaf is a signed tx
      ptr += 99; // version(1 byte) + multiAddress type(1 byte) + sender(32 bytes) + curve type(1 byte) + signature(64 bytes)
      ptr += leaf[ptr] == 0x00 ? 1 : 2; // add number of era bytes (immortal is 1, otherwise 2)
      ptr += _getCompactIntegerByteSize(leaf[ptr]); // add number of bytes encoding the nonce
      ptr += _getCompactIntegerByteSize(leaf[ptr]); // add number of bytes encoding the tip
      ptr += 32; // account for the first 32 EVM bytes holding the leaf's length
    }

    assembly {
      callId := mload(add(leaf, ptr))
    }

    numBytes = numBytesToLowerData[callId];
    if (numBytes == 0) revert NotALowerTransaction();
    unchecked { ptr += numBytes; }

    assembly {
      t2PublicKey := mload(add(leaf, ptr)) // load next 32 bytes into 32 byte type starting at ptr
      token := mload(add(add(leaf, 20), ptr)) // load leftmost 20 of next 32 bytes into 20 byte type starting at ptr + 20
      amount := mload(add(add(leaf, 36), ptr)) // load leftmost 16 of next 32 bytes into 16 byte type starting at ptr + 20 + 16
      t1Address := mload(add(add(leaf, 56), ptr)) // load leftmost 20 of next 32 bytes type starting at ptr + 20 + 16 + 20
    }

    // amount was encoded in little endian so we need to reverse to big endian:
    amount = ((amount & 0xFF00FF00FF00FF00FF00FF00FF00FF00) >> 8) | ((amount & 0x00FF00FF00FF00FF00FF00FF00FF00FF) << 8);
    amount = ((amount & 0xFFFF0000FFFF0000FFFF0000FFFF0000) >> 16) | ((amount & 0x0000FFFF0000FFFF0000FFFF0000FFFF) << 16);
    amount = ((amount & 0xFFFFFFFF00000000FFFFFFFF00000000) >> 32) | ((amount & 0x00000000FFFFFFFF00000000FFFFFFFF) << 32);
    amount = (amount >> 64) | (amount << 64);

    if (token == PSEUDO_EWT_ADDRESS) {
      (bool success, ) = payable(t1Address).call{value: amount}("");
      if (!success) revert PaymentFailed();
    } else {
      assert(IERC20(token).transfer(t1Address, amount));
    }

    emit LogLowered(token, t1Address, t2PublicKey, amount);
  }

  /// @notice Confirm the existence of any T2 transaction in a published root
  /// @param leafHash keccak256 hash of a raw encoded T2 transaction leaf
  /// @param merklePath Array of hashed leaves lying between the transaction leaf and the Merkle tree root hash
  function confirmTransaction(bytes32 leafHash, bytes32[] memory merklePath)
    public
    view
    returns (bool)
  {
    bytes32 rootHash = leafHash;
    uint256 pathLength = merklePath.length;
    bytes32 node;

    for (uint256 i; i < pathLength;) {
      node = merklePath[i];
      if (rootHash < node)
        rootHash = keccak256(abi.encode(rootHash, node));
      else
        rootHash = keccak256(abi.encode(node, rootHash));

      unchecked { i++; }
    }

    return isPublishedRootHash[rootHash];
  }

  function _authorizeUpgrade(address) internal override onlyOwner {}

  // reference: https://docs.substrate.io/v3/advanced/scale-codec/#compactgeneral-integers
  function _getCompactIntegerByteSize(bytes1 checkByte)
    private
    pure
    returns (uint256 byteLength)
  {
    uint8 mode = uint8(checkByte) & 3; // the 2 least significant bits encode the byte mode so we do a bitwise AND on them

    if (mode == 0) { // single-byte mode
      byteLength = 1;
    } else if (mode == 1) { // two-byte mode
      byteLength = 2;
    } else if (mode == 2) { // four-byte mode
      byteLength = 4;
    } else {
      unchecked { byteLength = uint8(checkByte >> 2) + 5; } // upper 6 bits + 4 = number of bytes to follow + 1 for checkbyte
    }
  }

  function _toConfirmationHash(bytes32 data, uint256 t2TransactionId)
    private
    view
    returns (bytes32)
  {
    return keccak256(abi.encode(data, t2TransactionId, idToT2PublicKey[t1AddressToId[msg.sender]]));
  }

  function _requiredConfirmations()
    private
    view
    returns (uint256 required)
  {
    uint256 active = numActiveCollators;
    unchecked {
      required = active * quorum[0] / quorum[1];
      required = required == active ? required : required + 1;
    }
  }

  function _verifyConfirmations(bytes32 msgHash, bytes memory confirmations)
    private
  {
    bytes32 ethSignedPrefixMsgHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", msgHash));
    uint256 numConfirmations;
    uint256 requiredConfirmations;
    unchecked {
      numConfirmations = confirmations.length / SIGNATURE_LENGTH;
    }
    requiredConfirmations = _requiredConfirmations();
    uint256 validConfirmations;
    uint256 id;
    bytes32 r;
    bytes32 s;
    uint8 v;
    bool[] memory confirmed = new bool[](nextCollatorId);

    for (uint256 i; i < numConfirmations;) {
      assembly {
        let offset := mul(i, SIGNATURE_LENGTH)
        r := mload(add(confirmations, add(0x20, offset)))
        s := mload(add(confirmations, add(0x40, offset)))
        v := byte(0, mload(add(confirmations, add(0x60, offset))))
      }

      if (v < 27) {
        unchecked { v += 27; }
      }

      if (v != 27 && v != 28 || uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
        unchecked { i++; }
        continue;
      } else {
        id = t1AddressToId[ecrecover(ethSignedPrefixMsgHash, v, r, s)];

        if (!isActiveCollator[id]) {
          if (isRegisteredCollator[id]) {
            // Here we activate any previously registered but as yet unactivated collators
            isActiveCollator[id] = true;
            unchecked {
              numActiveCollators++;
              validConfirmations++;
            }
            // Update the number of required confirmations to account for the newly activated collator
            requiredConfirmations = _requiredConfirmations();

            if (validConfirmations == requiredConfirmations) break;
            confirmed[id] = true;
          }
        } else if (!confirmed[id]) {
          unchecked { validConfirmations++; }
          if (validConfirmations == requiredConfirmations) break;
          confirmed[id] = true;
        }
      }

      unchecked { i++; }
    }

    if (validConfirmations != requiredConfirmations) revert InvalidConfirmations();
  }

  function _storeT2TransactionId(uint256 t2TransactionId)
    private
  {
    if (isUsedT2TransactionId[t2TransactionId]) revert TransactionIdAlreadyUsed();
    isUsedT2TransactionId[t2TransactionId] = true;
  }

  function _checkT2PublicKey(bytes memory t2PublicKey)
    private
    pure
    returns (bytes32 checkedT2PublicKey)
  {
    if (t2PublicKey.length != 32) revert InvalidT2PublicKey();
    checkedT2PublicKey = bytes32(t2PublicKey);
  }
}
        

@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

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

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

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

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
          

@openzeppelin/contracts-upgradeable/interfaces/IERC1967Upgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 *
 * _Available since v4.8.3._
 */
interface IERC1967Upgradeable {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}
          

@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822ProxiableUpgradeable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}
          

@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import "../utils/Initializable.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
    function __ERC1967Upgrade_init() internal onlyInitializing {
    }

    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
    }
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
        // Upgrades from old implementations will perform a rollback test. This test requires the new
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
        // this special case will break upgrade paths from old UUPS implementation to new ones.
        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
            _setImplementation(newImplementation);
        } else {
            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
            } catch {
                revert("ERC1967Upgrade: new implementation is not UUPS");
            }
            _upgradeToAndCall(newImplementation, data, forceCall);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
        }
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
          

@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeaconUpgradeable {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}
          

@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol

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

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @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 Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 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 functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _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 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _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() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @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 {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

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

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

@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.0;

import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
        _;
    }

    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
        return _IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeTo(address newImplementation) public virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
          

@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol

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

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

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

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

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

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

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

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

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

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

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}
          

@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol

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

pragma solidity ^0.8.0;
import "../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;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
          

@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlotUpgradeable {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}
          

@openzeppelin/contracts/interfaces/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";
          

@openzeppelin/contracts/token/ERC20/IERC20.sol

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

contracts/interfaces/IEnergyBridge.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface IEnergyBridge {
  event LogQuorumUpdated(uint256[2] quorum);
  event LogCollatorFunctionsAreEnabled(bool state);
  event LogLiftingIsEnabled(bool state);
  event LogLoweringIsEnabled(bool state);
  event LogLowerCallUpdated(bytes2 callId, uint256 numBytes);

  event LogCollatorRegistered(bytes32 indexed t1PublicKeyLHS, bytes32 t1PublicKeyRHS, bytes32 indexed t2PublicKey,
      uint256 indexed t2TransactionId);
  event LogCollatorDeregistered(bytes32 indexed t1PublicKeyLHS, bytes32 t1PublicKeyRHS, bytes32 indexed t2PublicKey,
      uint256 indexed t2TransactionId);
  event LogRootPublished(bytes32 indexed rootHash, uint256 indexed t2TransactionId);

  event LogLifted(address indexed token, address indexed t1Address, bytes32 indexed t2PublicKey, uint256 amount);
  event LogLowered(address indexed token, address indexed t1Address, bytes32 indexed t2PublicKey, uint256 amount);

  // Owner only
  function loadCollators(address[] calldata t1Address, bytes32[] calldata t1PublicKeyLHS, bytes32[] calldata t1PublicKeyRHS,
      bytes32[] calldata t2PublicKey) external;
  function setQuorum(uint256[2] memory quorum) external;
  function toggleCollatorFunctions(bool state) external;
  function toggleLifting(bool state) external;
  function toggleLowering(bool state) external;
  function updateLowerCall(bytes2 callId, uint256 numBytes) external;

  // Collators only
  function registerCollator(bytes memory t1PublicKey, bytes32 t2PublicKey, uint256 t2TransactionId,
      bytes calldata confirmations) external;
  function deregisterCollator(bytes memory t1PublicKey, bytes32 t2PublicKey, uint256 t2TransactionId,
      bytes calldata confirmations) external;
  function publishRoot(bytes32 rootHash, uint256 t2TransactionId, bytes calldata confirmations) external;

  // Public
  function lift(address erc20Address, bytes calldata t2PublicKey, uint256 amount) external;
  function liftEWT(bytes calldata t2PublicKey) external payable;
  function lower(bytes memory leaf, bytes32[] calldata merklePath) external;
  function confirmTransaction(bytes32 leafHash, bytes32[] memory merklePath) external view returns (bool);
}
          

Contract ABI

[{"type":"error","name":"AddressAlreadyInUse","inputs":[{"type":"address","name":"t1Address","internalType":"address"}]},{"type":"error","name":"AddressMismatch","inputs":[{"type":"address","name":"t1Address","internalType":"address"},{"type":"bytes","name":"t1PublicKey","internalType":"bytes"}]},{"type":"error","name":"AmountCannotBeZero","inputs":[]},{"type":"error","name":"CannotChangeT2PublicKey","inputs":[{"type":"bytes32","name":"existingT2PublicKey","internalType":"bytes32"}]},{"type":"error","name":"CannotReceiveEWTUnlessLifting","inputs":[]},{"type":"error","name":"CollatorAlreadyRegistered","inputs":[]},{"type":"error","name":"CollatorFunctionsAreDisabled","inputs":[]},{"type":"error","name":"CollatorNotRegistered","inputs":[]},{"type":"error","name":"InvalidConfirmations","inputs":[]},{"type":"error","name":"InvalidLowerData","inputs":[]},{"type":"error","name":"InvalidQuorum","inputs":[]},{"type":"error","name":"InvalidT1PublicKey","inputs":[]},{"type":"error","name":"InvalidT2PublicKey","inputs":[]},{"type":"error","name":"LiftLimitExceeded","inputs":[]},{"type":"error","name":"LiftingIsDisabled","inputs":[]},{"type":"error","name":"LowerAlreadyUsed","inputs":[]},{"type":"error","name":"LoweringIsDisabled","inputs":[]},{"type":"error","name":"MissingCollatorKeys","inputs":[]},{"type":"error","name":"NotALowerTransaction","inputs":[]},{"type":"error","name":"OwnerOnly","inputs":[]},{"type":"error","name":"PaymentFailed","inputs":[]},{"type":"error","name":"RootHashAlreadyPublished","inputs":[]},{"type":"error","name":"T2PublicKeyAlreadyInUse","inputs":[{"type":"bytes32","name":"t2PublicKey","internalType":"bytes32"}]},{"type":"error","name":"TransactionIdAlreadyUsed","inputs":[]},{"type":"error","name":"UnsignedTransaction","inputs":[]},{"type":"event","name":"AdminChanged","inputs":[{"type":"address","name":"previousAdmin","internalType":"address","indexed":false},{"type":"address","name":"newAdmin","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"BeaconUpgraded","inputs":[{"type":"address","name":"beacon","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"LogCollatorDeregistered","inputs":[{"type":"bytes32","name":"t1PublicKeyLHS","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"t1PublicKeyRHS","internalType":"bytes32","indexed":false},{"type":"bytes32","name":"t2PublicKey","internalType":"bytes32","indexed":true},{"type":"uint256","name":"t2TransactionId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"LogCollatorFunctionsAreEnabled","inputs":[{"type":"bool","name":"state","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"LogCollatorRegistered","inputs":[{"type":"bytes32","name":"t1PublicKeyLHS","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"t1PublicKeyRHS","internalType":"bytes32","indexed":false},{"type":"bytes32","name":"t2PublicKey","internalType":"bytes32","indexed":true},{"type":"uint256","name":"t2TransactionId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"LogLifted","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"t1Address","internalType":"address","indexed":true},{"type":"bytes32","name":"t2PublicKey","internalType":"bytes32","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"LogLiftingIsEnabled","inputs":[{"type":"bool","name":"state","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"LogLowerCallUpdated","inputs":[{"type":"bytes2","name":"callId","internalType":"bytes2","indexed":false},{"type":"uint256","name":"numBytes","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"LogLowered","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"t1Address","internalType":"address","indexed":true},{"type":"bytes32","name":"t2PublicKey","internalType":"bytes32","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"LogLoweringIsEnabled","inputs":[{"type":"bool","name":"state","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"LogQuorumUpdated","inputs":[{"type":"uint256[2]","name":"quorum","internalType":"uint256[2]","indexed":false}],"anonymous":false},{"type":"event","name":"LogRootPublished","inputs":[{"type":"bytes32","name":"rootHash","internalType":"bytes32","indexed":true},{"type":"uint256","name":"t2TransactionId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"implementation","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"collatorFunctionsAreEnabled","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"confirmTransaction","inputs":[{"type":"bytes32","name":"leafHash","internalType":"bytes32"},{"type":"bytes32[]","name":"merklePath","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deregisterCollator","inputs":[{"type":"bytes","name":"t1PublicKey","internalType":"bytes"},{"type":"bytes32","name":"t2PublicKey","internalType":"bytes32"},{"type":"uint256","name":"t2TransactionId","internalType":"uint256"},{"type":"bytes","name":"confirmations","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasLowered","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"idToT1Address","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"idToT2PublicKey","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isActiveCollator","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPublishedRootHash","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isRegisteredCollator","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isUsedT2TransactionId","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"lift","inputs":[{"type":"address","name":"erc20Address","internalType":"address"},{"type":"bytes","name":"t2PublicKey","internalType":"bytes"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"liftEWT","inputs":[{"type":"bytes","name":"t2PublicKey","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"liftingIsEnabled","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"loadCollators","inputs":[{"type":"address[]","name":"t1Address","internalType":"address[]"},{"type":"bytes32[]","name":"t1PublicKeyLHS","internalType":"bytes32[]"},{"type":"bytes32[]","name":"t1PublicKeyRHS","internalType":"bytes32[]"},{"type":"bytes32[]","name":"t2PublicKey","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"lower","inputs":[{"type":"bytes","name":"leaf","internalType":"bytes"},{"type":"bytes32[]","name":"merklePath","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"loweringIsEnabled","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"nextCollatorId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"numActiveCollators","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"numBytesToLowerData","inputs":[{"type":"bytes2","name":"","internalType":"bytes2"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"proxiableUUID","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"publishRoot","inputs":[{"type":"bytes32","name":"rootHash","internalType":"bytes32"},{"type":"uint256","name":"t2TransactionId","internalType":"uint256"},{"type":"bytes","name":"confirmations","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"quorum","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"registerCollator","inputs":[{"type":"bytes","name":"t1PublicKey","internalType":"bytes"},{"type":"bytes32","name":"t2PublicKey","internalType":"bytes32"},{"type":"uint256","name":"t2TransactionId","internalType":"uint256"},{"type":"bytes","name":"confirmations","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setQuorum","inputs":[{"type":"uint256[2]","name":"_quorum","internalType":"uint256[2]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"t1AddressToId","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"t2PublicKeyToId","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"toggleCollatorFunctions","inputs":[{"type":"bool","name":"state","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"toggleLifting","inputs":[{"type":"bool","name":"state","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"toggleLowering","inputs":[{"type":"bool","name":"state","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateLowerCall","inputs":[{"type":"bytes2","name":"callId","internalType":"bytes2"},{"type":"uint256","name":"numBytes","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"upgradeTo","inputs":[{"type":"address","name":"newImplementation","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"upgradeToAndCall","inputs":[{"type":"address","name":"newImplementation","internalType":"address"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"receive","stateMutability":"payable"}]
            

Deployed ByteCode

0x6080604052600436106102135760003560e01c80638da5cb5b11610118578063c95970e5116100a0578063e51d09211161006f578063e51d09211461065d578063e8beede61461068d578063e8fed1d6146106bd578063f2fde38b146106ea578063f8ce560a1461070a57600080fd5b8063c95970e5146105e8578063d3578a9414610608578063d7d8ecd814610627578063dcfe8fb31461063d57600080fd5b8063b1c7eff4116100e7578063b1c7eff41461051b578063b91d8a061461054b578063b9b17e7f1461056b578063c4024f0e1461059b578063c460eb07146105bb57600080fd5b80638da5cb5b146104805780638ebd72651461049e5780638f78ea1b146104be5780639e79fe6b146104ee57600080fd5b80634f1ef2861161019b578063715018a61161016a578063715018a6146103f65780637553c4cd1461040b5780638129fc1c1461042b578063895817a9146104405780638cacd6e71461046057600080fd5b80634f1ef2861461037a5780634fa182ea1461038d57806352d1902d146103ba5780636282b019146103cf57600080fd5b80631b4097d8116101e25780631b4097d8146102e45780633083f708146103045780633659cfe6146103245780634bf31f6e146103445780634c184ff31461036757600080fd5b80630caa99481461023657806317a691aa146102585780631945e9dc146102a45780631a621052146102c457600080fd5b3661023157604051632dbe0b5d60e11b815260040160405180910390fd5b600080fd5b34801561024257600080fd5b506102566102513660046124ac565b61072a565b005b34801561026457600080fd5b5061028e61027336600461251b565b60cd602052600090815260409020546001600160a01b031681565b60405161029b919061254b565b60405180910390f35b3480156102b057600080fd5b506102566102bf366004612652565b610994565b3480156102d057600080fd5b506102566102df366004612784565b610c00565b3480156102f057600080fd5b506102566102ff3660046127b8565b610c81565b34801561031057600080fd5b5061025661031f366004612823565b610ccc565b34801561033057600080fd5b5061025661033f366004612897565b611116565b34801561035057600080fd5b5061035a60d55481565b60405161029b91906128be565b6102566103753660046128cc565b6111f5565b610256610388366004612913565b6112d1565b34801561039957600080fd5b5061035a6103a8366004612985565b60cf6020526000908152604090205481565b3480156103c657600080fd5b5061035a6113a1565b3480156103db57600080fd5b5060d7546103e99060ff1681565b60405161029b91906129ae565b34801561040257600080fd5b506102566113fe565b34801561041757600080fd5b506102566104263660046129bc565b611412565b34801561043757600080fd5b50610256611655565b34801561044c57600080fd5b5061025661045b3660046127b8565b6117b2565b34801561046c57600080fd5b5061025661047b3660046127b8565b6117f8565b34801561048c57600080fd5b506097546001600160a01b031661028e565b3480156104aa57600080fd5b506103e96104b9366004612b31565b611845565b3480156104ca57600080fd5b506103e96104d936600461251b565b60d16020526000908152604090205460ff1681565b3480156104fa57600080fd5b5061035a61050936600461251b565b60ce6020526000908152604090205481565b34801561052757600080fd5b506103e961053636600461251b565b60ca6020526000908152604090205460ff1681565b34801561055757600080fd5b50610256610566366004612652565b6118fd565b34801561057757600080fd5b506103e961058636600461251b565b60d06020526000908152604090205460ff1681565b3480156105a757600080fd5b506102566105b6366004612b7e565b611a7a565b3480156105c757600080fd5b5061035a6105d636600461251b565b60cc6020526000908152604090205481565b3480156105f457600080fd5b5060d7546103e99062010000900460ff1681565b34801561061457600080fd5b5060d7546103e990610100900460ff1681565b34801561063357600080fd5b5061035a60d65481565b34801561064957600080fd5b50610256610658366004612beb565b611b68565b34801561066957600080fd5b506103e961067836600461251b565b60d26020526000908152604090205460ff1681565b34801561069957600080fd5b506103e96106a836600461251b565b60c96020526000908152604090205460ff1681565b3480156106c957600080fd5b5061035a6106d8366004612897565b60cb6020526000908152604090205481565b3480156106f657600080fd5b50610256610705366004612897565b611bca565b34801561071657600080fd5b5061035a61072536600461251b565b611c01565b60d754610100900460ff166107525760405163f51cba7760e01b815260040160405180910390fd5b806000036107735760405163d11b25af60e01b815260040160405180910390fd5b6040516370a0823160e01b815284906000906001600160a01b038316906370a08231906107a490309060040161254b565b602060405180830381865afa1580156107c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e59190612c29565b6040516323b872dd60e01b81529091506001600160a01b038316906323b872dd9061081890339030908890600401612c4a565b6020604051808303816000875af1158015610837573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085b9190612c7d565b61086757610867612c9e565b6040516370a0823160e01b81526000906001600160a01b038416906370a082319061089690309060040161254b565b602060405180830381865afa1580156108b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108d79190612c29565b90506001600160801b0381111561090157604051636e2c048760e11b815260040160405180910390fd5b61094086868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611c1892505050565b336001600160a01b0389167f8964776336bc2fa8ecaaf70b6f8e8450807efb1ff78f8b87980707aa821f0ec06109768686612cca565b60405161098391906128be565b60405180910390a450505050505050565b60d75460ff166109b757604051632f4661f160e21b815260040160405180910390fd5b84516040146109d957604051630d4a420160e11b815260040160405180910390fd5b84516020808701919091206001600160a01b038116600090815260cb835260408082205480835260c990945290205490919060ff1615610a2c57604051634961cf8f60e11b815260040160405180910390fd5b60008787604051602001610a41929190612d26565b604051602081830303815290604052805190602001209050610aa2610a668288611c45565b86868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611c9292505050565b610aab86611f44565b81600003610b5157600087815260cc602052604090205415610aeb578660405163e75b239b60e01b8152600401610ae291906128be565b60405180910390fd5b60d68054600081815260cd6020908152604080832080546001600160a01b0319166001600160a01b038a16908117909155835260cb825280832084905583835260ce82528083208c90558b835260cc909152902081905581546001019091559150610b90565b600082815260ce60205260409020548714610b9057600082815260ce602052604090819020549051631241dd0560e21b8152610ae291906004016128be565b600082815260c96020908152604091829020805460ff1916600117905589015189820151915190919088908a9084907f3fa05e1ac566a95c0092f0c2065d35e5f7faa4a431ecd17b5de21bfe1cc5c16390610bec9086906128be565b60405180910390a450505050505050505050565b610c08611f8f565b80511580610c1a575060208101518151115b15610c385760405163d173577960e01b815260040160405180910390fd5b610c4560d38260026123c7565b507fc7d2ab69ce7a42db5ca306ca58373ae7719b64ba1a5d0a86abdccea27fcfd8f960d3604051610c769190612dbf565b60405180910390a150565b610c89611f8f565b60d7805461ff001916610100831515021790556040517f1cd6419035c493f53970c075a2a1c916d76018df8e189468f4c21c360e7c8aa990610c769083906129ae565b60d75462010000900460ff16610cf5576040516399860ded60e01b815260040160405180910390fd5b600083805190602001209050610d3e8184848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061184592505050565b610d5b576040516357bf35b360e11b815260040160405180910390fd5b600081815260d2602052604090205460ff1615610d8b57604051630cc3317f60e41b815260040160405180910390fd5b600081815260d260205260408120805460ff191660011790558451819081908190819081908190610dda908c908390610dc657610dc6612d48565b01602001516001600160f81b031916611fb9565b860195508a8681518110610df057610df0612d48565b60209101015160f81c608016600003610e1c5760405163227c863b60e21b815260040160405180910390fd5b6063860195508a8681518110610e3457610e34612d48565b01602001516001600160f81b03191615610e4f576002610e52565b60015b60ff1686019550610e6e8b8781518110610dc657610dc6612d48565b86019550610e878b8781518110610dc657610dc6612d48565b9095018a81016020908101516001600160f01b03198116600090815260cf835260408120549950919092019650879003610ed45760405163469de68760e11b815260040160405180910390fd5b9486018a8101805160148201516024830151603890930151939891975095509193506eff000000ff000000ff000000ff0000600882811c9182166fff000000ff000000ff000000ff0000009390911b92831617601090811c6cff000000ff000000ff000000ff9092166dff000000ff000000ff000000ff009093169290921790911b17602081811c6bffffffff00000000ffffffff166fffffffff00000000ffffffff000000009290911b9190911617604081811c91901b17915073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b03851601611040576000836001600160a01b0316836001600160801b0316604051610fd690612dd5565b60006040518083038185875af1925050503d8060008114611013576040519150601f19603f3d011682016040523d82523d6000602084013e611018565b606091505b505090508061103a576040516307a4ced160e51b815260040160405180910390fd5b506110bd565b60405163a9059cbb60e01b81526001600160a01b0385169063a9059cbb9061106e9086908690600401612dfe565b6020604051808303816000875af115801561108d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b19190612c7d565b6110bd576110bd612c9e565b84836001600160a01b0316856001600160a01b03167fea1b69480b8e6df6e2fba9e1fa47698276db9338f7de0d7c3a58cce4a94f450f856040516111019190612e19565b60405180910390a45050505050505050505050565b6001600160a01b037f000000000000000000000000344a2849fb94bf5635c0768b07471b64e2a388c116300361115e5760405162461bcd60e51b8152600401610ae290612e73565b7f000000000000000000000000344a2849fb94bf5635c0768b07471b64e2a388c16001600160a01b03166111a76000805160206133df833981519152546001600160a01b031690565b6001600160a01b0316146111cd5760405162461bcd60e51b8152600401610ae290612ecc565b6111d68161200f565b604080516000808252602082019092526111f291839190612017565b50565b60d754610100900460ff1661121d5760405163f51cba7760e01b815260040160405180910390fd5b3460000361123e5760405163d11b25af60e01b815260040160405180910390fd5b61127d82828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611c1892505050565b604051339073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee907f8964776336bc2fa8ecaaf70b6f8e8450807efb1ff78f8b87980707aa821f0ec0906112c59034906128be565b60405180910390a45050565b6001600160a01b037f000000000000000000000000344a2849fb94bf5635c0768b07471b64e2a388c11630036113195760405162461bcd60e51b8152600401610ae290612e73565b7f000000000000000000000000344a2849fb94bf5635c0768b07471b64e2a388c16001600160a01b03166113626000805160206133df833981519152546001600160a01b031690565b6001600160a01b0316146113885760405162461bcd60e51b8152600401610ae290612ecc565b6113918261200f565b61139d82826001612017565b5050565b6000306001600160a01b037f000000000000000000000000344a2849fb94bf5635c0768b07471b64e2a388c116146113eb5760405162461bcd60e51b8152600401610ae290612f36565b506000805160206133df83398151915290565b611406611f8f565b61141060006120fe565b565b61141a611f8f565b8660008060608884148015906114305750868414155b801561143c5750848414155b1561145a576040516333cf83b160e21b815260040160405180910390fd5b60005b84811015611646578c8c8281811061147757611477612d48565b905060200201602081019061148c9190612897565b92508686828181106114a0576114a0612d48565b6001600160a01b038616600090815260cb602090815260409091205491029290920135955050156114e657826040516307bbad8160e51b8152600401610ae2919061254b565b600084815260cc602052604090205415611515578360405163e75b239b60e01b8152600401610ae291906128be565b8a8a8281811061152757611527612d48565b9050602002013589898381811061154057611540612d48565b90506020020135604051602001611558929190612f46565b6040516020818303038152906040529150826001600160a01b0316828051906020012060001c6001600160a01b0316146115a95782826040516335c5d73760e01b8152600401610ae2929190612f94565b60d68054600090815260cd6020908152604080832080546001600160a01b0319166001600160a01b0389169081179091558454845260ce8352818420899055845490845260cb835281842081905588845260cc8352818420819055835260c98252808320805460ff1990811660019081179092558554855260ca909352922080549091168217905560d5805482019055815481019091550161145d565b50505050505050505050505050565b600054610100900460ff16158080156116755750600054600160ff909116105b8061168f5750303b15801561168f575060005460ff166001145b6116ab5760405162461bcd60e51b8152600401610ae290612fff565b6000805460ff1916600117905580156116ce576000805461ff0019166101001790555b6116d6612150565b60cf60205260857f474cf5cd8a156a285bdb013cd5ad88639478d8c2df5dd0da103de5e0c93be11f8190557f260a2a8177dfbdaed58acd0b3df5d4289c584f88be17037c5ed3bb018cde816955612b8160f11b60005260027f475ac2ade161108313ceef0815ca8140b4df68a82031c72f4e2f14414795106581905560d7805462ffffff191662010101179055600160d65560d355600360d45580156111f2576000805461ff00191690556040517f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890610c7690600190613023565b6117ba611f8f565b60d7805460ff19168215151790556040517fb5a243284ae387c315556c54d652faecf5ddb16cea0b6196257c4877986800dd90610c769083906129ae565b611800611f8f565b60d7805462ff0000191662010000831515021790556040517f236540b1dc0f95bdefe04c9e02c5edcc415f7bf4d44dac6ab16528feba25f7ed90610c769083906129ae565b8051600090839082805b828110156118df5785818151811061186957611869612d48565b60200260200101519150818410156118ab57838260405160200161188e929190613031565b6040516020818303038152906040528051906020012093506118d7565b81846040516020016118be929190613031565b6040516020818303038152906040528051906020012093505b60010161184f565b505050600090815260d0602052604090205460ff1690505b92915050565b60d75460ff1661192057604051632f4661f160e21b815260040160405180910390fd5b600084815260cc602090815260408083205480845260c99092529091205460ff1661195e5760405163d8f6342560e01b815260040160405180910390fd5b600081815260c960209081526040808320805460ff1916905560ca90915290205460ff16156119a857600081815260ca60205260409020805460ff1916905560d580546000190190555b600085876040516020016119bd92919061304c565b604051602081830303815290604052805190602001209050611a1e6119e28287611c45565b85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611c9292505050565b611a2785611f44565b602087015160408089015190518790899084907fdd40b3200c3e8f2eab10871504dd94c67d6f2f15c0ac8842069dd9d61458a8a290611a679086906128be565b60405180910390a4505050505050505050565b60d75460ff16611a9d57604051632f4661f160e21b815260040160405180910390fd5b611ae6611aaa8585611c45565b83838080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611c9292505050565b611aef83611f44565b600084815260d0602052604090205460ff1615611b1f576040516327a7ec4b60e01b815260040160405180910390fd5b600084815260d06020526040808220805460ff1916600117905551849186917ffe808338418de30500c1a16538c15061c01827981732033cf0d1b9bc046417039190a350505050565b611b70611f8f565b6001600160f01b03198216600090815260cf602052604090819020829055517f8a2052ee12aa0ad46deb771b8cc507be8e8e773fd206bf9bd3603c36d59de12290611bbe9084908490613078565b60405180910390a15050565b611bd2611f8f565b6001600160a01b038116611bf85760405162461bcd60e51b8152600401610ae2906130c9565b6111f2816120fe565b60d38160028110611c1157600080fd5b0154905081565b60008151602014611c3c57604051630c41363960e31b815260040160405180910390fd5b6118f7826130e3565b33600090815260cb6020908152604080832054835260ce8252808320549051611c749286928692909101613122565b60405160208183030381529060405280519060200120905092915050565b600082604051602001611ca5919061313d565b6040516020818303038152906040528051906020012090506000806041845181611cd157611cd1613178565b049150611cdc61217f565b905060008060008060008060d6546001600160401b03811115611d0157611d01612559565b604051908082528060200260200182016040528015611d2a578160200160208202803683370190505b50905060005b88811015611f1657604181028b016020810151604082015160609092015190965090945060001a9250601b831015611d6957601b830192505b8260ff16601b14158015611d8157508260ff16601c14155b80611dab57507f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084115b15611db857600101611d30565b60cb600060018c86898960405160008152602001604052604051611ddf9493929190613197565b6020604051602081039080840390855afa158015611e01573d6000803e3d6000fd5b505060408051601f1901516001600160a01b0316835260208381019490945291820160009081205480825260ca90945291909120549197505060ff16611ebc57600086815260c9602052604090205460ff1615611eb757600086815260ca60205260409020805460ff1916600190811790915560d58054820190559690960195611e8961217f565b9750868814611f16576001828781518110611ea657611ea6612d48565b911515602092830291909101909101525b611f0e565b818681518110611ece57611ece612d48565b6020026020010151611f0e576001808801978990030115611f16576001828781518110611efd57611efd612d48565b911515602092830291909101909101525b600101611d30565b50868614611f37576040516311ed5d1f60e31b815260040160405180910390fd5b5050505050505050505050565b600081815260d1602052604090205460ff1615611f7457604051630970e53d60e21b815260040160405180910390fd5b600090815260d160205260409020805460ff19166001179055565b6097546001600160a01b031633146114105760405162461bcd60e51b8152600401610ae29061320a565b6000600360f883901c16808203611fd35760019150612009565b8060ff16600103611fe75760029150612009565b8060ff16600203611ffb5760049150612009565b60ff600560fa85901c011691505b50919050565b6111f2611f8f565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff161561204f5761204a836121b7565b505050565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156120a9575060408051601f3d908101601f191682019092526120a691810190612c29565b60015b6120c55760405162461bcd60e51b8152600401610ae290613265565b6000805160206133df83398151915281146120f25760405162461bcd60e51b8152600401610ae2906132bb565b5061204a83838361220d565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff166121775760405162461bcd60e51b8152600401610ae290613313565b611410612238565b60d55460d45460d354600092919082028161219c5761219c613178565b0491508082146121af57816001016121b1565b815b91505090565b6001600160a01b0381163b6121de5760405162461bcd60e51b8152600401610ae29061336d565b6000805160206133df83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61221683612268565b6000825111806122235750805b1561204a5761223283836122a8565b50505050565b600054610100900460ff1661225f5760405162461bcd60e51b8152600401610ae290613313565b611410336120fe565b612271816121b7565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60606122cd83836040518060600160405280602781526020016133ff602791396122d4565b9392505050565b6060600080856001600160a01b0316856040516122f1919061337d565b600060405180830381855af49150503d806000811461232c576040519150601f19603f3d011682016040523d82523d6000602084013e612331565b606091505b50915091506123428683838761234c565b9695505050505050565b6060831561238b578251600003612384576001600160a01b0385163b6123845760405162461bcd60e51b8152600401610ae2906133bd565b5081612395565b612395838361239d565b949350505050565b8151156123ad5781518083602001fd5b8060405162461bcd60e51b8152600401610ae291906133cd565b82600281019282156123f5579160200282015b828111156123f55782518255916020019190600101906123da565b50612401929150612405565b5090565b5b808211156124015760008155600101612406565b60006001600160a01b0382166118f7565b6124348161241a565b81146111f257600080fd5b80356118f78161242b565b60008083601f84011261245f5761245f600080fd5b5081356001600160401b0381111561247957612479600080fd5b60208301915083600182028301111561249457612494600080fd5b9250929050565b80612434565b80356118f78161249b565b600080600080606085870312156124c5576124c5600080fd5b60006124d1878761243f565b94505060208501356001600160401b038111156124f0576124f0600080fd5b6124fc8782880161244a565b9350935050604061250f878288016124a1565b91505092959194509250565b60006020828403121561253057612530600080fd5b600061239584846124a1565b6125458161241a565b82525050565b602081016118f7828461253c565b634e487b7160e01b600052604160045260246000fd5b601f19601f83011681018181106001600160401b038211171561259457612594612559565b6040525050565b60006125a660405190565b90506125b2828261256f565b919050565b60006001600160401b038211156125d0576125d0612559565b601f19601f83011660200192915050565b82818337506000910152565b60006126006125fb846125b7565b61259b565b90508281526020810184848401111561261b5761261b600080fd5b6126268482856125e1565b509392505050565b600082601f83011261264257612642600080fd5b81356123958482602086016125ed565b60008060008060006080868803121561266d5761266d600080fd5b85356001600160401b0381111561268657612686600080fd5b6126928882890161262e565b95505060206126a3888289016124a1565b94505060406126b4888289016124a1565b93505060608601356001600160401b038111156126d3576126d3600080fd5b6126df8882890161244a565b92509250509295509295909350565b60006001600160401b0382111561270757612707612559565b5060200290565b600061271c6125fb846126ee565b9050806020840283018581111561273557612735600080fd5b835b81811015612759578061274a88826124a1565b84525060209283019201612737565b5050509392505050565b600082601f83011261277757612777600080fd5b600261239584828561270e565b60006040828403121561279957612799600080fd5b60006123958484612763565b801515612434565b80356118f7816127a5565b6000602082840312156127cd576127cd600080fd5b600061239584846127ad565b60008083601f8401126127ee576127ee600080fd5b5081356001600160401b0381111561280857612808600080fd5b60208301915083602082028301111561249457612494600080fd5b60008060006040848603121561283b5761283b600080fd5b83356001600160401b0381111561285457612854600080fd5b6128608682870161262e565b93505060208401356001600160401b0381111561287f5761287f600080fd5b61288b868287016127d9565b92509250509250925092565b6000602082840312156128ac576128ac600080fd5b6000612395848461243f565b80612545565b602081016118f782846128b8565b600080602083850312156128e2576128e2600080fd5b82356001600160401b038111156128fb576128fb600080fd5b6129078582860161244a565b92509250509250929050565b6000806040838503121561292957612929600080fd5b6000612935858561243f565b92505060208301356001600160401b0381111561295457612954600080fd5b6129608582860161262e565b9150509250929050565b6001600160f01b03198116612434565b80356118f78161296a565b60006020828403121561299a5761299a600080fd5b6000612395848461297a565b801515612545565b602081016118f782846129a6565b6000806000806000806000806080898b0312156129db576129db600080fd5b88356001600160401b038111156129f4576129f4600080fd5b612a008b828c016127d9565b985098505060208901356001600160401b03811115612a2157612a21600080fd5b612a2d8b828c016127d9565b965096505060408901356001600160401b03811115612a4e57612a4e600080fd5b612a5a8b828c016127d9565b945094505060608901356001600160401b03811115612a7b57612a7b600080fd5b612a878b828c016127d9565b92509250509295985092959890939650565b60006001600160401b03821115612ab257612ab2612559565b5060209081020190565b6000612aca6125fb84612a99565b83815290506020808201908402830185811115612ae957612ae9600080fd5b835b818110156127595780612afe88826124a1565b84525060209283019201612aeb565b600082601f830112612b2157612b21600080fd5b8135612395848260208601612abc565b60008060408385031215612b4757612b47600080fd5b6000612b5385856124a1565b92505060208301356001600160401b03811115612b7257612b72600080fd5b61296085828601612b0d565b60008060008060608587031215612b9757612b97600080fd5b6000612ba387876124a1565b9450506020612bb4878288016124a1565b93505060408501356001600160401b03811115612bd357612bd3600080fd5b612bdf8782880161244a565b95989497509550505050565b60008060408385031215612c0157612c01600080fd5b6000612c0d858561297a565b9250506020612960858286016124a1565b80516118f78161249b565b600060208284031215612c3e57612c3e600080fd5b60006123958484612c1e565b60608101612c58828661253c565b612c65602083018561253c565b61239560408301846128b8565b80516118f7816127a5565b600060208284031215612c9257612c92600080fd5b60006123958484612c72565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b818103818111156118f7576118f7612cb4565b60005b83811015612cf8578181015183820152602001612ce0565b50506000910152565b6000612d0b825190565b612d19818560208601612cdd565b9290920192915050565b90565b6000612d328285612d01565b9150612d3e82846128b8565b5060200192915050565b634e487b7160e01b600052603260045260246000fd5b6000612d6a83836128b8565b505060200190565b6000816118f7565b60006118f78254612d72565b6002818060005b83811015612db757612d9e82612d7a565b612da88782612d5e565b96505060019182019101612d8d565b505050505050565b604081016118f78284612d86565b6000816121b1565b60006118f782612dcd565b60006118f7612d236001600160801b03841681565b61254581612de0565b60408101612e0c828561253c565b6122cd6020830184612df5565b602081016118f78284612df5565b602c81526000602082017f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682081526b19195b1959d85d1958d85b1b60a21b602082015291505b5060400190565b602080825281016118f781612e27565b602c81526000602082017f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682081526b6163746976652070726f787960a01b60208201529150612e6c565b602080825281016118f781612e83565b603881526000602082017f555550535570677261646561626c653a206d757374206e6f742062652063616c81527f6c6564207468726f7567682064656c656761746563616c6c000000000000000060208201529150612e6c565b602080825281016118f781612edc565b6000612f5282856128b8565b602082019150612d3e82846128b8565b6000612f6c825190565b808452602084019350612f83818560208601612cdd565b601f01601f19169290920192915050565b60408101612fa2828561253c565b81810360208301526123958184612f62565b602e81526000602082017f496e697469616c697a61626c653a20636f6e747261637420697320616c72656181526d191e481a5b9a5d1a585b1a5e995960921b60208201529150612e6c565b602080825281016118f781612fb4565b600060ff82166118f7565b6125458161300f565b602081016118f7828461301a565b6040810161303f82856128b8565b6122cd60208301846128b8565b600061305882856128b8565b6020820191506123958284612d01565b6001600160f01b03198116612545565b6040810161303f8285613068565b602681526000602082017f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206181526564647265737360d01b60208201529150612e6c565b602080825281016118f781613086565b60006118f7825190565b60006130ed825190565b602083016130fa816130d9565b9250602082101561311b57613116600019836020036008021b90565b831692505b5050919050565b6060810161313082866128b8565b612c6560208301856128b8565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000008152601c01600061316f82846128b8565b50602001919050565b634e487b7160e01b600052601260045260246000fd5b60ff8116612545565b608081016131a582876128b8565b6131b2602083018661318e565b6131bf60408301856128b8565b6131cc60608301846128b8565b95945050505050565b60208082527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572910190815260005b5060200190565b602080825281016118f7816131d5565b602e81526000602082017f45524331393637557067726164653a206e657720696d706c656d656e7461746981526d6f6e206973206e6f74205555505360901b60208201529150612e6c565b602080825281016118f78161321a565b602981526000602082017f45524331393637557067726164653a20756e737570706f727465642070726f788152681a58589b195555525160ba1b60208201529150612e6c565b602080825281016118f781613275565b602b81526000602082017f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206981526a6e697469616c697a696e6760a81b60208201529150612e6c565b602080825281016118f7816132cb565b602d81526000602082017f455243313936373a206e657720696d706c656d656e746174696f6e206973206e81526c1bdd08184818dbdb9d1c9858dd609a1b60208201529150612e6c565b602080825281016118f781613323565b60006122cd8284612d01565b601d81526000602082017f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081529150613203565b602080825281016118f781613389565b602080825281016122cd8184612f6256fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220765336a72156064b84c3fcab9eb22b6c5bb7b0c19a778076d3cdf0504f2b44bd64736f6c63430008110033