POL Price: $0.706493 (+4.09%)
Gas: 0 GWei
 

Overview

POL Balance

Polygon PoS Chain LogoPolygon PoS Chain LogoPolygon PoS Chain Logo0 POL

POL Value

$0.00

Token Holdings

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Submit Vote651777922024-12-07 3:25:5310 hrs ago1733541953IN
Aave: Voting Machine
0 POL0.0173465126.00536863
Submit Vote651777782024-12-07 3:25:2310 hrs ago1733541923IN
Aave: Voting Machine
0 POL0.0173450726.00320241
Submit Vote651739682024-12-07 1:00:0512 hrs ago1733533205IN
Aave: Voting Machine
0 POL0.0097607234.19909344
Submit Vote651739612024-12-07 0:59:4912 hrs ago1733533189IN
Aave: Voting Machine
0 POL0.0097607234.19909344
Submit Vote651739552024-12-07 0:59:3712 hrs ago1733533177IN
Aave: Voting Machine
0 POL0.0097607234.19909345
Submit Vote651644892024-12-06 19:13:5418 hrs ago1733512434IN
Aave: Voting Machine
0 POL0.0107839331.00365549
Submit Vote651644502024-12-06 19:12:3218 hrs ago1733512352IN
Aave: Voting Machine
0 POL0.0109316331.42826469
Submit Vote651638842024-12-06 18:51:2318 hrs ago1733511083IN
Aave: Voting Machine
0 POL0.0206623432.98407165
Submit Vote651638422024-12-06 18:49:3118 hrs ago1733510971IN
Aave: Voting Machine
0 POL0.0205327832.77725168
Submit Vote651599732024-12-06 16:29:2121 hrs ago1733502561IN
Aave: Voting Machine
0 POL0.0457344673.21263028
Submit Vote651599042024-12-06 16:26:5521 hrs ago1733502415IN
Aave: Voting Machine
0 POL0.0453917872.66405385
Submit Vote651574452024-12-06 14:59:4122 hrs ago1733497181IN
Aave: Voting Machine
0 POL0.0543308141.6642946
Submit Vote651534392024-12-06 12:36:4225 hrs ago1733488602IN
Aave: Voting Machine
0 POL0.011383330.01632891
Submit Vote651534112024-12-06 12:35:4425 hrs ago1733488544IN
Aave: Voting Machine
0 POL0.0111292929.34654019
Submit Vote651533862024-12-06 12:34:4225 hrs ago1733488482IN
Aave: Voting Machine
0 POL0.0111281229.34623949
Submit Vote651486762024-12-06 9:46:3327 hrs ago1733478393IN
Aave: Voting Machine
0 POL0.0379758840.54787839
Submit Vote651486652024-12-06 9:46:0927 hrs ago1733478369IN
Aave: Voting Machine
0 POL0.0385607141.17231589
Submit Vote651466182024-12-06 8:33:2429 hrs ago1733474004IN
Aave: Voting Machine
0 POL0.01134930.38539427
Submit Vote651466052024-12-06 8:32:5629 hrs ago1733473976IN
Aave: Voting Machine
0 POL0.0113605330.41626491
Submit Vote651459042024-12-06 8:07:5629 hrs ago1733472476IN
Aave: Voting Machine
0 POL0.0221630732
Submit Vote651458552024-12-06 8:06:1029 hrs ago1733472370IN
Aave: Voting Machine
0 POL0.0107770230.69852545
Submit Vote651458322024-12-06 8:05:2229 hrs ago1733472322IN
Aave: Voting Machine
0 POL0.0108201530.82139413
Submit Vote651458112024-12-06 8:04:3829 hrs ago1733472278IN
Aave: Voting Machine
0 POL0.0108778430.98783621
Submit Vote651457952024-12-06 8:04:0429 hrs ago1733472244IN
Aave: Voting Machine
0 POL0.0234299333.83091522
Submit Vote651446812024-12-06 7:23:5830 hrs ago1733469838IN
Aave: Voting Machine
0 POL0.0113699830.44057569
View all transactions

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
VotingMachine

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 32 : VotingMachine.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {ICrossChainController} from 'aave-crosschain-infra/contracts/interfaces/ICrossChainController.sol';
import {IVotingMachine, IBaseReceiverPortal, IVotingPortal} from './interfaces/IVotingMachine.sol';
import {VotingMachineWithProofs, IDataWarehouse, IVotingStrategy, IVotingMachineWithProofs} from './VotingMachineWithProofs.sol';
import {Errors} from '../libraries/Errors.sol';

/**
 * @title VotingMachine
 * @author BGD Labs
 * @notice this contract contains the logic to communicate with governance chain.
 * @dev This contract implements the abstract contract VotingMachineWithProofs
 * @dev This contract can receive messages of types Proposal and Vote from governance chain, and send voting results
        back.
 */
contract VotingMachine is VotingMachineWithProofs, IVotingMachine {
  /// @inheritdoc IVotingMachine
  address public immutable CROSS_CHAIN_CONTROLLER;

  /// @inheritdoc IVotingMachine
  uint256 public immutable L1_VOTING_PORTAL_CHAIN_ID;

  // address of the L1 VotingPortal contract
  address public immutable L1_VOTING_PORTAL;

  // gas limit used for sending the vote result
  uint256 private _gasLimit;

  /**
   * @param crossChainController address of the CrossChainController contract deployed on current chain. This contract
            is the one responsible to send here the voting configurations once they are bridged.
   * @param gasLimit max number of gas to spend on receiving chain (L1) when sending back the voting results
   * @param l1VotingPortalChainId id of the L1 chain where the voting portal is deployed
   * @param votingStrategy address of the new VotingStrategy contract
   * @param l1VotingPortal address of the L1 Voting Portal contract that communicates with this voting machine
   * @param governance address of the governance contract
   **/
  constructor(
    address crossChainController,
    uint256 gasLimit,
    uint256 l1VotingPortalChainId,
    IVotingStrategy votingStrategy,
    address l1VotingPortal,
    address governance
  ) VotingMachineWithProofs(votingStrategy, governance) {
    require(
      crossChainController != address(0),
      Errors.INVALID_VOTING_MACHINE_CROSS_CHAIN_CONTROLLER
    );
    require(l1VotingPortalChainId > 0, Errors.INVALID_VOTING_PORTAL_CHAIN_ID);
    require(
      l1VotingPortal != address(0),
      Errors.INVALID_VOTING_PORTAL_ADDRESS_IN_VOTING_MACHINE
    );
    CROSS_CHAIN_CONTROLLER = crossChainController;
    L1_VOTING_PORTAL_CHAIN_ID = l1VotingPortalChainId;
    L1_VOTING_PORTAL = l1VotingPortal;

    _updateGasLimit(gasLimit);
  }

  /// @inheritdoc IVotingMachine
  function getGasLimit() external view returns (uint256) {
    return _gasLimit;
  }

  /// @inheritdoc IVotingMachine
  function updateGasLimit(uint256 gasLimit) external onlyOwner {
    _updateGasLimit(gasLimit);
  }

  /// @inheritdoc IBaseReceiverPortal
  function receiveCrossChainMessage(
    address originSender,
    uint256 originChainId,
    bytes memory messageWithType
  ) external {
    require(
      msg.sender == CROSS_CHAIN_CONTROLLER &&
        originSender == L1_VOTING_PORTAL &&
        originChainId == L1_VOTING_PORTAL_CHAIN_ID,
      Errors.WRONG_MESSAGE_ORIGIN
    );

    try this.decodeMessage(messageWithType) returns (
      IVotingPortal.MessageType messageType,
      bytes memory message
    ) {
      bytes memory empty;
      if (messageType == IVotingPortal.MessageType.Proposal) {
        try this.decodeProposalMessage(message) returns (
          uint256 proposalId,
          bytes32 blockHash,
          uint24 votingDuration
        ) {
          _createBridgedProposalVote(proposalId, blockHash, votingDuration);
          emit MessageReceived(
            originSender,
            originChainId,
            true,
            messageType,
            message,
            empty
          );
        } catch (bytes memory decodingError) {
          emit MessageReceived(
            originSender,
            originChainId,
            false,
            messageType,
            message,
            decodingError
          );
        }
      } else {
        emit IncorrectTypeMessageReceived(
          originSender,
          originChainId,
          messageWithType,
          abi.encodePacked('unsupported message type: ', messageType)
        );
      }
    } catch (bytes memory decodingError) {
      emit IncorrectTypeMessageReceived(
        originSender,
        originChainId,
        messageWithType,
        decodingError
      );
    }
  }

  /// @inheritdoc IVotingMachine
  function decodeVoteMessage(
    bytes memory message
  )
    external
    pure
    returns (uint256, address, bool, VotingAssetWithSlot[] memory)
  {
    return abi.decode(message, (uint256, address, bool, VotingAssetWithSlot[]));
  }

  /// @inheritdoc IVotingMachine
  function decodeProposalMessage(
    bytes memory message
  ) external pure returns (uint256, bytes32, uint24) {
    return abi.decode(message, (uint256, bytes32, uint24));
  }

  /// @inheritdoc IVotingMachine
  function decodeMessage(
    bytes memory message
  ) external pure returns (IVotingPortal.MessageType, bytes memory) {
    return abi.decode(message, (IVotingPortal.MessageType, bytes));
  }

  /**
   * @dev method to send the vote result to the voting portal on governance chain
   * @param proposalId id of the proposal voted on
   * @param forVotes votes in favor of the proposal
   * @param againstVotes votes against the proposal
   */
  function _sendVoteResults(
    uint256 proposalId,
    uint256 forVotes,
    uint256 againstVotes
  ) internal override {
    ICrossChainController(CROSS_CHAIN_CONTROLLER).forwardMessage(
      L1_VOTING_PORTAL_CHAIN_ID,
      L1_VOTING_PORTAL,
      _gasLimit,
      abi.encode(proposalId, forVotes, againstVotes)
    );
  }

  /**
   * @notice method to update the gasLimit
   * @param gasLimit the new gas limit
   */
  function _updateGasLimit(uint256 gasLimit) internal {
    _gasLimit = gasLimit;

    emit GasLimitUpdated(gasLimit);
  }
}

File 2 of 32 : ICrossChainController.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import './IBaseCrossChainController.sol';

/**
 * @title ICrossChainController
 * @author BGD Labs
 * @notice interface containing the objects, events and methods definitions of the ICrossChainControllerMainnet contract
 */
interface ICrossChainController is IBaseCrossChainController {
  /**
   * @notice method called to initialize the proxy
   * @param owner address of the owner of the cross chain controller
   * @param guardian address of the guardian of the cross chain controller
   * @param initialRequiredConfirmations number of confirmations the messages need to be accepted as valid
   * @param receiverBridgeAdaptersToAllow array of addresses of the bridge adapters that can receive messages
   * @param forwarderBridgeAdaptersToEnable array specifying for every bridgeAdapter, the destinations it can have
   * @param sendersToApprove array of addresses to allow as forwarders
   */
  function initialize(
    address owner,
    address guardian,
    ConfirmationInput[] memory initialRequiredConfirmations,
    ReceiverBridgeAdapterConfigInput[] memory receiverBridgeAdaptersToAllow,
    ForwarderBridgeAdapterConfigInput[] memory forwarderBridgeAdaptersToEnable,
    address[] memory sendersToApprove
  ) external;
}

File 3 of 32 : IVotingMachine.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IBaseReceiverPortal} from 'aave-crosschain-infra/contracts/interfaces/IBaseReceiverPortal.sol';
import {IVotingPortal} from '../../../interfaces/IVotingPortal.sol';
import {IVotingMachineWithProofs} from './IVotingMachineWithProofs.sol';

/**
 * @title IVotingMachine
 * @author BGD Labs
 * @notice interface containing the methods definitions of the VotingMachine contract
 */
interface IVotingMachine is IBaseReceiverPortal {
  /**
   * @notice emitted when gas limit gets updated
   * @param gasLimit the new gas limit
   */
  event GasLimitUpdated(uint256 indexed gasLimit);

  /**
   * @notice emitted when a cross chain message gets received
   * @param originSender address that sent the message on the origin chain
   * @param originChainId id of the chain where the message originated
   * @param delivered flag indicating if message has been delivered
   * @param messageType type of the received message
   * @param message bytes containing the necessary information of a user vote
   * @param reason bytes with the revert information
   */
  event MessageReceived(
    address indexed originSender,
    uint256 indexed originChainId,
    bool indexed delivered,
    IVotingPortal.MessageType messageType,
    bytes message,
    bytes reason
  );

  /**
   * @notice emitted when a cross chain message does not have the correct type for voting machine
   * @param originSender address that sent the message on the origin chain
   * @param originChainId id of the chain where the message originated
   * @param message bytes containing the necessary information of a proposal vote
   * @param reason bytes with the revert information
   */
  event IncorrectTypeMessageReceived(
    address indexed originSender,
    uint256 indexed originChainId,
    bytes message,
    bytes reason
  );

  /**
   * @notice method to get the chain id of the origin / receiving chain (L1)
   * @return the chainId
   */
  function L1_VOTING_PORTAL_CHAIN_ID() external view returns (uint256);

  /**
   * @notice method to get the VotingPortal of the origin / receiving chain (L1)
   * @return address of the VotingPortal
   */
  function L1_VOTING_PORTAL() external view returns (address);

  /**
   * @notice method to get the address of the CrossChainController contract deployed on current chain
   * @return the CrossChainController contract address
   */
  function CROSS_CHAIN_CONTROLLER() external view returns (address);

  /**
   * @notice method to decode a message from from governance chain
   * @param message encoded message with message type
   * @return messageType and governance underlying message
   */
  function decodeMessage(
    bytes memory message
  ) external view returns (IVotingPortal.MessageType, bytes memory);

  /**
   * @notice method to decode a vote message
   * @param message encoded vote message
   * @return information to vote on a proposal, including proposalId, voter, support, votingTokens
   */
  function decodeVoteMessage(
    bytes memory message
  )
    external
    view
    returns (
      uint256,
      address,
      bool,
      IVotingMachineWithProofs.VotingAssetWithSlot[] memory
    );

  /**
   * @notice method to decode a proposal message from from governance chain
   * @param message encoded proposal message
   * @return information to start a proposal vote, including proposalId, blockHash and votingDuration
   */
  function decodeProposalMessage(
    bytes memory message
  ) external view returns (uint256, bytes32, uint24);

  /**
   * @notice method to update the gasLimit
   * @param gasLimit the new gas limit
   * @dev this method should have a owner gated permission. But responsibility is relegated to inheritance
   */
  function updateGasLimit(uint256 gasLimit) external;

  /**
   * @notice method to get the gasLimit
   * @return gasLimit the new gas limit
   */
  function getGasLimit() external view returns (uint256);
}

File 4 of 32 : VotingMachineWithProofs.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {Ownable} from 'solidity-utils/contracts/oz-common/Ownable.sol';
import {SafeCast} from 'solidity-utils/contracts/oz-common/SafeCast.sol';
import {StateProofVerifier} from './libs/StateProofVerifier.sol';
import {IVotingMachineWithProofs, IDataWarehouse, IVotingStrategy} from './interfaces/IVotingMachineWithProofs.sol';
import {IBaseVotingStrategy} from '../../interfaces/IBaseVotingStrategy.sol';
import {Errors} from '../libraries/Errors.sol';
import {SlotUtils} from '../libraries/SlotUtils.sol';
import {EIP712} from 'openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol';
import {ECDSA} from 'openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol';

/**
 * @title VotingMachineWithProofs
 * @author BGD Labs
 * @notice this contract contains the logic to vote on a bridged proposal. It uses registered proofs to calculate the
           voting power of the users. Once the voting is finished it will send the results back to the governance chain.
 * @dev Abstract contract that is implemented on VotingMachine contract
 */
abstract contract VotingMachineWithProofs is
  IVotingMachineWithProofs,
  EIP712,
  Ownable
{
  using SafeCast for uint256;

  /// @inheritdoc IVotingMachineWithProofs
  uint256 public constant REPRESENTATIVES_SLOT = 9;

  /// @inheritdoc IVotingMachineWithProofs
  string public constant VOTING_ASSET_WITH_SLOT_RAW =
    'VotingAssetWithSlot(address underlyingAsset,uint128 slot)';

  /// @inheritdoc IVotingMachineWithProofs
  bytes32 public constant VOTE_SUBMITTED_TYPEHASH =
    keccak256(
      abi.encodePacked(
        'SubmitVote(uint256 proposalId,address voter,bool support,VotingAssetWithSlot[] votingAssetsWithSlot)',
        VOTING_ASSET_WITH_SLOT_RAW
      )
    );

  /// @inheritdoc IVotingMachineWithProofs
  bytes32 public constant VOTE_SUBMITTED_BY_REPRESENTATIVE_TYPEHASH =
    keccak256(
      abi.encodePacked(
        'SubmitVoteAsRepresentative(uint256 proposalId,address voter,address representative,bool support,VotingAssetWithSlot[] votingAssetsWithSlot)',
        VOTING_ASSET_WITH_SLOT_RAW
      )
    );

  /// @inheritdoc IVotingMachineWithProofs
  bytes32 public constant VOTING_ASSET_WITH_SLOT_TYPEHASH =
    keccak256(abi.encodePacked(VOTING_ASSET_WITH_SLOT_RAW));

  /// @inheritdoc IVotingMachineWithProofs
  string public constant NAME = 'Aave Voting Machine';

  /// @inheritdoc IVotingMachineWithProofs
  IVotingStrategy public immutable VOTING_STRATEGY;

  /// @inheritdoc IVotingMachineWithProofs
  IDataWarehouse public immutable DATA_WAREHOUSE;

  /// @inheritdoc IVotingMachineWithProofs
  address public immutable GOVERNANCE;

  // (proposalId => proposal information) stores the information of the proposals
  mapping(uint256 => Proposal) internal _proposals;

  // (proposalId => proposal vote configuration) stores the configuration for voting on each proposal
  mapping(uint256 => ProposalVoteConfiguration)
    internal _proposalsVoteConfiguration;

  // saves the ids of the proposals that have been bridged for a vote.
  uint256[] internal _proposalsVoteConfigurationIds;

  /**
   * @param votingStrategy address of the new VotingStrategy contract
   * @param governance address of the governance contract on ethereum
   */
  constructor(
    IVotingStrategy votingStrategy,
    address governance
  ) Ownable() EIP712(NAME, 'V1') {
    require(
      address(votingStrategy) != address(0),
      Errors.INVALID_VOTING_STRATEGY
    );
    require(governance != address(0), Errors.VM_INVALID_GOVERNANCE_ADDRESS);
    VOTING_STRATEGY = votingStrategy;
    DATA_WAREHOUSE = votingStrategy.DATA_WAREHOUSE();
    GOVERNANCE = governance;
  }

  /// @inheritdoc IVotingMachineWithProofs
  function DOMAIN_SEPARATOR() public view returns (bytes32) {
    return _domainSeparatorV4();
  }

  /// @inheritdoc IVotingMachineWithProofs
  function getProposalVoteConfiguration(
    uint256 proposalId
  ) external view returns (ProposalVoteConfiguration memory) {
    return _proposalsVoteConfiguration[proposalId];
  }

  /// @inheritdoc IVotingMachineWithProofs
  function startProposalVote(uint256 proposalId) external returns (uint256) {
    ProposalVoteConfiguration memory voteConfig = _proposalsVoteConfiguration[
      proposalId
    ];
    require(
      voteConfig.l1ProposalBlockHash != bytes32(0),
      Errors.MISSING_PROPOSAL_BLOCK_HASH
    );
    Proposal storage newProposal = _proposals[proposalId];

    require(
      _getProposalState(newProposal) == ProposalState.NotCreated,
      Errors.PROPOSAL_VOTE_ALREADY_CREATED
    );

    VOTING_STRATEGY.hasRequiredRoots(voteConfig.l1ProposalBlockHash);

    _checkRepresentationRoots(voteConfig.l1ProposalBlockHash);

    uint40 startTime = _getCurrentTimeRef();
    uint40 endTime = startTime + voteConfig.votingDuration;

    newProposal.id = proposalId;
    newProposal.creationBlockNumber = block.number;
    newProposal.startTime = startTime;
    newProposal.endTime = endTime;

    emit ProposalVoteStarted(
      proposalId,
      voteConfig.l1ProposalBlockHash,
      startTime,
      endTime
    );

    return proposalId;
  }

  /// @inheritdoc IVotingMachineWithProofs
  function submitVoteBySignature(
    uint256 proposalId,
    address voter,
    bool support,
    VotingBalanceProof[] calldata votingBalanceProofs,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external {
    bytes32[] memory underlyingAssetsWithSlotHashes = new bytes32[](
      votingBalanceProofs.length
    );
    for (uint256 i = 0; i < votingBalanceProofs.length; i++) {
      underlyingAssetsWithSlotHashes[i] = keccak256(
        abi.encode(
          VOTING_ASSET_WITH_SLOT_TYPEHASH,
          votingBalanceProofs[i].underlyingAsset,
          votingBalanceProofs[i].slot
        )
      );
    }

    bytes32 digest = _hashTypedDataV4(
      keccak256(
        abi.encode(
          VOTE_SUBMITTED_TYPEHASH,
          proposalId,
          voter,
          support,
          keccak256(abi.encodePacked(underlyingAssetsWithSlotHashes))
        )
      )
    );
    address signer = ECDSA.recover(digest, v, r, s);

    require(signer == voter && signer != address(0), Errors.INVALID_SIGNATURE);
    _submitVote(signer, proposalId, support, votingBalanceProofs);
  }

  /// @inheritdoc IVotingMachineWithProofs
  function submitVote(
    uint256 proposalId,
    bool support,
    VotingBalanceProof[] calldata votingBalanceProofs
  ) external {
    _submitVote(msg.sender, proposalId, support, votingBalanceProofs);
  }

  /// @inheritdoc IVotingMachineWithProofs
  function submitVoteAsRepresentativeBySignature(
    uint256 proposalId,
    address voter,
    address representative,
    bool support,
    bytes memory proofOfRepresentation,
    VotingBalanceProof[] calldata votingBalanceProofs,
    SignatureParams memory signatureParams
  ) external {
    bytes32[] memory underlyingAssetsWithSlotHashes = new bytes32[](
      votingBalanceProofs.length
    );
    for (uint256 i = 0; i < votingBalanceProofs.length; i++) {
      underlyingAssetsWithSlotHashes[i] = keccak256(
        abi.encode(
          VOTING_ASSET_WITH_SLOT_TYPEHASH,
          votingBalanceProofs[i].underlyingAsset,
          votingBalanceProofs[i].slot
        )
      );
    }

    bytes32 digest = _hashTypedDataV4(
      keccak256(
        abi.encode(
          VOTE_SUBMITTED_BY_REPRESENTATIVE_TYPEHASH,
          proposalId,
          voter,
          representative,
          support,
          keccak256(abi.encodePacked(underlyingAssetsWithSlotHashes))
        )
      )
    );
    address signer = ECDSA.recover(
      digest,
      signatureParams.v,
      signatureParams.r,
      signatureParams.s
    );

    require(
      signer == representative && signer != address(0),
      Errors.INVALID_SIGNATURE
    );

    _submitVoteAsRepresentative(
      proposalId,
      support,
      voter,
      representative,
      proofOfRepresentation,
      votingBalanceProofs
    );
  }

  /// @inheritdoc IVotingMachineWithProofs
  function submitVoteAsRepresentative(
    uint256 proposalId,
    bool support,
    address voter,
    bytes memory proofOfRepresentation,
    VotingBalanceProof[] calldata votingBalanceProofs
  ) external {
    _submitVoteAsRepresentative(
      proposalId,
      support,
      voter,
      msg.sender,
      proofOfRepresentation,
      votingBalanceProofs
    );
  }

  /**
   * @notice Function to register the vote of user as its representative
   * @param proposalId id of the proposal
   * @param support boolean, true = vote for, false = vote against
   * @param voter the voter address
   * @param representative address of the voter representative
   * @param proofOfRepresentation proof that can validate that msg.sender is the voter representative
   * @param votingBalanceProofs list of voting assets proofs
   */
  function _submitVoteAsRepresentative(
    uint256 proposalId,
    bool support,
    address voter,
    address representative,
    bytes memory proofOfRepresentation,
    VotingBalanceProof[] calldata votingBalanceProofs
  ) internal {
    require(voter != address(0), Errors.INVALID_VOTER);
    bytes32 l1ProposalBlockHash = _proposalsVoteConfiguration[proposalId]
      .l1ProposalBlockHash;

    bytes32 slot = SlotUtils.getRepresentativeSlotHash(
      voter,
      block.chainid,
      REPRESENTATIVES_SLOT
    );
    StateProofVerifier.SlotValue memory storageData = DATA_WAREHOUSE.getStorage(
      GOVERNANCE,
      l1ProposalBlockHash,
      slot,
      proofOfRepresentation
    );

    address storedRepresentative = address(uint160(storageData.value));

    require(
      representative == storedRepresentative && representative != address(0),
      Errors.CALLER_IS_NOT_VOTER_REPRESENTATIVE
    );

    _submitVote(voter, proposalId, support, votingBalanceProofs);
  }

  /// @inheritdoc IVotingMachineWithProofs
  function getUserProposalVote(
    address user,
    uint256 proposalId
  ) external view returns (Vote memory) {
    return _proposals[proposalId].votes[user];
  }

  /// @inheritdoc IVotingMachineWithProofs
  function closeAndSendVote(uint256 proposalId) external {
    Proposal storage proposal = _proposals[proposalId];
    require(
      _getProposalState(proposal) == ProposalState.Finished,
      Errors.PROPOSAL_VOTE_NOT_FINISHED
    );

    proposal.votingClosedAndSentBlockNumber = block.number;
    proposal.votingClosedAndSentTimestamp = _getCurrentTimeRef();

    uint256 forVotes = proposal.forVotes;
    uint256 againstVotes = proposal.againstVotes;

    proposal.sentToGovernance = true;

    _sendVoteResults(proposalId, forVotes, againstVotes);

    emit ProposalResultsSent(proposalId, forVotes, againstVotes);
  }

  /// @inheritdoc IVotingMachineWithProofs
  function getProposalById(
    uint256 proposalId
  ) external view returns (ProposalWithoutVotes memory) {
    Proposal storage proposal = _proposals[proposalId];
    ProposalWithoutVotes memory proposalWithoutVotes = ProposalWithoutVotes({
      id: proposalId,
      startTime: proposal.startTime,
      endTime: proposal.endTime,
      creationBlockNumber: proposal.creationBlockNumber,
      forVotes: proposal.forVotes,
      againstVotes: proposal.againstVotes,
      votingClosedAndSentBlockNumber: proposal.votingClosedAndSentBlockNumber,
      votingClosedAndSentTimestamp: proposal.votingClosedAndSentTimestamp,
      sentToGovernance: proposal.sentToGovernance
    });

    return proposalWithoutVotes;
  }

  /// @inheritdoc IVotingMachineWithProofs
  function getProposalState(
    uint256 proposalId
  ) external view returns (ProposalState) {
    return _getProposalState(_proposals[proposalId]);
  }

  /// @inheritdoc IVotingMachineWithProofs
  function getProposalsVoteConfigurationIds(
    uint256 skip,
    uint256 size
  ) external view returns (uint256[] memory) {
    uint256 proposalListLength = _proposalsVoteConfigurationIds.length;
    if (proposalListLength == 0 || proposalListLength <= skip) {
      return new uint256[](0);
    } else if (proposalListLength < size + skip) {
      size = proposalListLength - skip;
    }

    uint256[] memory ids = new uint256[](size);
    for (uint256 i = 0; i < size; i++) {
      ids[i] = _proposalsVoteConfigurationIds[
        proposalListLength - skip - i - 1
      ];
    }
    return ids;
  }

  function _checkRepresentationRoots(
    bytes32 l1ProposalBlockHash
  ) internal view {
    require(
      DATA_WAREHOUSE.getStorageRoots(GOVERNANCE, l1ProposalBlockHash) !=
        bytes32(0),
      Errors.MISSING_REPRESENTATION_ROOTS
    );
  }

  /**
    * @notice method to cast a vote on a proposal specified by its id
    * @param voter address with the voting power
    * @param proposalId id of the proposal on which the vote will be cast
    * @param support boolean indicating if the vote is in favor or against the proposal
    * @param votingBalanceProofs list of objects containing the information necessary to vote using the tokens
             allowed on the voting strategy.
    * @dev A vote does not need to use all the tokens allowed, can be a subset
    */
  function _submitVote(
    address voter,
    uint256 proposalId,
    bool support,
    VotingBalanceProof[] calldata votingBalanceProofs
  ) internal {
    Proposal storage proposal = _proposals[proposalId];
    require(
      _getProposalState(proposal) == ProposalState.Active,
      Errors.PROPOSAL_VOTE_NOT_IN_ACTIVE_STATE
    );

    Vote storage vote = proposal.votes[voter];
    require(vote.votingPower == 0, Errors.PROPOSAL_VOTE_ALREADY_EXISTS);

    ProposalVoteConfiguration memory voteConfig = _proposalsVoteConfiguration[
      proposalId
    ];

    uint256 votingPower;
    StateProofVerifier.SlotValue memory balanceVotingPower;
    for (uint256 i = 0; i < votingBalanceProofs.length; i++) {
      for (uint256 j = i + 1; j < votingBalanceProofs.length; j++) {
        require(
          votingBalanceProofs[i].slot != votingBalanceProofs[j].slot ||
            votingBalanceProofs[i].underlyingAsset !=
            votingBalanceProofs[j].underlyingAsset,
          Errors.VOTE_ONCE_FOR_ASSET
        );
      }

      balanceVotingPower = DATA_WAREHOUSE.getStorage(
        votingBalanceProofs[i].underlyingAsset,
        voteConfig.l1ProposalBlockHash,
        SlotUtils.getAccountSlotHash(voter, votingBalanceProofs[i].slot),
        votingBalanceProofs[i].proof
      );

      require(balanceVotingPower.exists, Errors.USER_BALANCE_DOES_NOT_EXISTS);

      if (balanceVotingPower.value != 0) {
        votingPower += IVotingStrategy(address(VOTING_STRATEGY)).getVotingPower(
          votingBalanceProofs[i].underlyingAsset,
          votingBalanceProofs[i].slot,
          balanceVotingPower.value,
          voteConfig.l1ProposalBlockHash
        );
      }
    }
    require(votingPower != 0, Errors.USER_VOTING_BALANCE_IS_ZERO);

    if (support) {
      proposal.forVotes += votingPower.toUint128();
    } else {
      proposal.againstVotes += votingPower.toUint128();
    }

    vote.support = support;
    vote.votingPower = votingPower.toUint248();

    emit VoteEmitted(proposalId, voter, support, votingPower);
  }

  /**
   * @notice method to send the voting results on a proposal back to L1
   * @param proposalId id of the proposal to send the voting result to L1
   * @dev This method should be implemented to trigger the bridging flow
   */
  function _sendVoteResults(
    uint256 proposalId,
    uint256 forVotes,
    uint256 againstVotes
  ) internal virtual;

  /**
   * @notice method to get the state of a proposal specified by its id
   * @param proposal the proposal to retrieve the state of
   * @return the state of the proposal
   */
  function _getProposalState(
    Proposal storage proposal
  ) internal view returns (ProposalState) {
    if (proposal.endTime == 0) {
      return ProposalState.NotCreated;
    } else if (_getCurrentTimeRef() <= proposal.endTime) {
      return ProposalState.Active;
    } else if (proposal.sentToGovernance) {
      return ProposalState.SentToGovernance;
    } else {
      return ProposalState.Finished;
    }
  }

  /**
   * @notice method to get the timestamp of a block casted to uint40
   * @return uint40 block timestamp
   */
  function _getCurrentTimeRef() internal view returns (uint40) {
    return uint40(block.timestamp);
  }

  /**
   * @notice method that registers a proposal configuration and creates the voting if it can. If not it will register the
             the configuration for later creation.
   * @param proposalId id of the proposal bridged to start the vote on
   * @param blockHash hash of the block on L1 when the proposal was activated for voting
   * @param votingDuration duration in seconds of the vote
   */
  function _createBridgedProposalVote(
    uint256 proposalId,
    bytes32 blockHash,
    uint24 votingDuration
  ) internal {
    require(
      blockHash != bytes32(0),
      Errors.INVALID_VOTE_CONFIGURATION_BLOCKHASH
    );
    require(
      votingDuration > 0,
      Errors.INVALID_VOTE_CONFIGURATION_VOTING_DURATION
    );
    require(
      _proposalsVoteConfiguration[proposalId].l1ProposalBlockHash == bytes32(0),
      Errors.PROPOSAL_VOTE_CONFIGURATION_ALREADY_BRIDGED
    );

    _proposalsVoteConfiguration[proposalId] = IVotingMachineWithProofs
      .ProposalVoteConfiguration({
        votingDuration: votingDuration,
        l1ProposalBlockHash: blockHash
      });
    _proposalsVoteConfigurationIds.push(proposalId);

    bool created;
    try this.startProposalVote(proposalId) {
      created = true;
    } catch (bytes memory) {}

    emit ProposalVoteConfigurationBridged(
      proposalId,
      blockHash,
      votingDuration,
      created
    );
  }
}

File 5 of 32 : Errors.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
 * @title Errors library
 * @author BGD Labs
 * @notice Defines the error messages emitted by the different contracts of the Aave Governance V3
 */
library Errors {
  string public constant VOTING_PORTALS_COUNT_NOT_0 = '1'; // to be able to rescue voting portals count must be 0
  string public constant AT_LEAST_ONE_PAYLOAD = '2'; // to create a proposal, it must have at least one payload
  string public constant VOTING_PORTAL_NOT_APPROVED = '3'; // the voting portal used to vote on proposal must be approved
  string public constant PROPOSITION_POWER_IS_TOO_LOW = '4'; // proposition power of proposal creator must be equal or higher than the specified threshold for the access level
  string public constant PROPOSAL_NOT_IN_CREATED_STATE = '5'; // proposal should be in the CREATED state
  string public constant PROPOSAL_NOT_IN_ACTIVE_STATE = '6'; // proposal must be in an ACTIVE state
  string public constant PROPOSAL_NOT_IN_QUEUED_STATE = '7'; // proposal must be in a QUEUED state
  string public constant VOTING_START_COOLDOWN_PERIOD_NOT_PASSED = '8'; // to activate a proposal vote, the cool down delay must pass
  string public constant CALLER_NOT_A_VALID_VOTING_PORTAL = '9'; // only an allowed voting portal can queue a proposal
  string public constant QUEUE_COOLDOWN_PERIOD_NOT_PASSED = '10'; // to execute a proposal a cooldown delay must pass
  string public constant PROPOSAL_NOT_IN_THE_CORRECT_STATE = '11'; // proposal must be created but not executed yet to be able to be canceled
  string public constant CALLER_NOT_GOVERNANCE = '12'; // caller must be governance
  string public constant VOTER_ALREADY_VOTED_ON_PROPOSAL = '13'; // voter can only vote once per proposal using voting portal
  string public constant WRONG_MESSAGE_ORIGIN = '14'; // received message must come from registered source address, chain id, CrossChainController
  string public constant NO_VOTING_ASSETS = '15'; // Strategy must have voting assets
  string public constant PROPOSAL_VOTE_ALREADY_CREATED = '16'; // vote on proposal can only be created once
  string public constant INVALID_SIGNATURE = '17'; // submitted signature is not valid
  string public constant PROPOSAL_VOTE_NOT_FINISHED = '18'; // proposal vote must be finished
  string public constant PROPOSAL_VOTE_NOT_IN_ACTIVE_STATE = '19'; // proposal vote must be in active state
  string public constant PROPOSAL_VOTE_ALREADY_EXISTS = '20'; // proposal vote already exists
  string public constant VOTE_ONCE_FOR_ASSET = '21'; // an asset can only be used once per vote
  string public constant USER_BALANCE_DOES_NOT_EXISTS = '22'; // to vote an user must have balance in the token the user is voting with
  string public constant USER_VOTING_BALANCE_IS_ZERO = '23'; // to vote an user must have some balance between all the tokens selected for voting
  string public constant MISSING_AAVE_ROOTS = '24'; // must have AAVE roots registered to use strategy
  string public constant MISSING_STK_AAVE_ROOTS = '25'; // must have stkAAVE roots registered to use strategy
  string public constant MISSING_STK_AAVE_SLASHING_EXCHANGE_RATE = '26'; // must have stkAAVE slashing exchange rate registered to use strategy
  string public constant UNPROCESSED_STORAGE_ROOT = '27'; // root must be registered beforehand
  string public constant NOT_ENOUGH_MSG_VALUE = '28'; // method was not called with enough value to execute the call
  string public constant FAILED_ACTION_EXECUTION = '29'; // action failed to execute
  string public constant SHOULD_BE_AT_LEAST_ONE_EXECUTOR = '30'; // at least one executor is needed
  string public constant INVALID_EMPTY_TARGETS = '31'; // target of the payload execution must not be empty
  string public constant EXECUTOR_WAS_NOT_SPECIFIED_FOR_REQUESTED_ACCESS_LEVEL =
    '32'; // payload executor must be registered for the specified payload access level
  string public constant PAYLOAD_NOT_IN_QUEUED_STATE = '33'; // payload must be en the queued state
  string public constant TIMELOCK_NOT_FINISHED = '34'; // delay has not passed before execution can be called
  string public constant PAYLOAD_NOT_IN_THE_CORRECT_STATE = '35'; // payload must be created but not executed yet to be able to be canceled
  string public constant PAYLOAD_NOT_IN_CREATED_STATE = '36'; // payload must be in the created state
  string public constant MISSING_A_AAVE_ROOTS = '37'; // must have aAAVE roots registered to use strategy
  string public constant MISSING_PROPOSAL_BLOCK_HASH = '38'; // block hash for this proposal was not bridged before
  string public constant PROPOSAL_VOTE_CONFIGURATION_ALREADY_BRIDGED = '39'; // configuration for this proposal bridged already
  string public constant INVALID_VOTING_PORTAL_ADDRESS = '40'; // voting portal address can't be 0x0
  string public constant INVALID_POWER_STRATEGY = '41'; // 0x0 is not valid as the power strategy
  string public constant INVALID_EXECUTOR_ADDRESS = '42'; // executor address can't be 0x0
  string public constant EXECUTOR_ALREADY_SET_IN_DIFFERENT_LEVEL = '43'; // executor address already being used as executor of a different level
  string public constant INVALID_VOTING_DURATION = '44'; // voting duration can not be bigger than the time it takes to execute a proposal
  string public constant VOTING_DURATION_NOT_PASSED = '45'; // at least votingDuration should have passed since voting started for a proposal to be queued
  string public constant INVALID_PROPOSAL_ACCESS_LEVEL = '46'; // the bridged proposal access level does not correspond with the maximum access level required by the payload
  string public constant PAYLOAD_NOT_CREATED_BEFORE_PROPOSAL = '47'; // payload must be created before proposal
  string public constant INVALID_CROSS_CHAIN_CONTROLLER_ADDRESS = '48';
  string public constant INVALID_MESSAGE_ORIGINATOR_ADDRESS = '49';
  string public constant INVALID_ORIGIN_CHAIN_ID = '50';
  string public constant INVALID_ACTION_TARGET = '51';
  string public constant INVALID_ACTION_ACCESS_LEVEL = '52';
  string public constant INVALID_EXECUTOR_ACCESS_LEVEL = '53';
  string public constant INVALID_VOTING_PORTAL_CROSS_CHAIN_CONTROLLER = '54';
  string public constant INVALID_VOTING_PORTAL_VOTING_MACHINE = '55';
  string public constant INVALID_VOTING_PORTAL_GOVERNANCE = '56';
  string public constant INVALID_VOTING_MACHINE_CHAIN_ID = '57';
  string public constant G_INVALID_CROSS_CHAIN_CONTROLLER_ADDRESS = '58';
  string public constant G_INVALID_IPFS_HASH = '59';
  string public constant G_INVALID_PAYLOAD_ACCESS_LEVEL = '60';
  string public constant G_INVALID_PAYLOADS_CONTROLLER = '61';
  string public constant G_INVALID_PAYLOAD_CHAIN = '62';
  string public constant POWER_STRATEGY_HAS_NO_TOKENS = '63'; // power strategy should at least have
  string public constant INVALID_VOTING_CONFIG_ACCESS_LEVEL = '64';
  string public constant VOTING_DURATION_TOO_SMALL = '65';
  string public constant NO_BRIDGED_VOTING_ASSETS = '66';
  string public constant INVALID_VOTER = '67';
  string public constant INVALID_DATA_WAREHOUSE = '68';
  string public constant INVALID_VOTING_MACHINE_CROSS_CHAIN_CONTROLLER = '69';
  string public constant INVALID_L1_VOTING_PORTAL = '70';
  string public constant INVALID_VOTING_PORTAL_CHAIN_ID = '71';
  string public constant INVALID_VOTING_STRATEGY = '72';
  string public constant INVALID_VOTE_CONFIGURATION_BLOCKHASH = '73';
  string public constant INVALID_VOTE_CONFIGURATION_VOTING_DURATION = '74';
  string public constant INVALID_GAS_LIMIT = '75';
  string public constant INVALID_VOTING_CONFIGS = '76'; // a lvl2 voting configuration must be sent to initializer
  string public constant INVALID_EXECUTOR_DELAY = '77';
  string public constant REPEATED_STRATEGY_ASSET = '78';
  string public constant EMPTY_ASSET_STORAGE_SLOTS = '79';
  string public constant REPEATED_STRATEGY_ASSET_SLOT = '80';
  string public constant INVALID_EXECUTION_TARGET = '81';
  string public constant MISSING_VOTING_CONFIGURATIONS = '82'; // voting configurations for lvl1 and lvl2 must be included on initialization
  string public constant INVALID_PROPOSITION_POWER = '83';
  string public constant INVALID_YES_THRESHOLD = '84';
  string public constant INVALID_YES_NO_DIFFERENTIAL = '85';
  string public constant ETH_TRANSFER_FAILED = '86';
  string public constant INVALID_INITIAL_VOTING_CONFIGS = '87'; // initial voting configurations can not be of the same level
  string public constant INVALID_VOTING_PORTAL_ADDRESS_IN_VOTING_MACHINE = '88';
  string public constant INVALID_VOTING_PORTAL_OWNER = '89';
  string public constant CANCELLATION_FEE_REDEEM_FAILED = '90'; // cancellation fee was not able to be redeemed
  string public constant INVALID_CANCELLATION_FEE_COLLECTOR = '91'; // collector can not be address 0
  string public constant INVALID_CANCELLATION_FEE_SENT = '92'; // cancellation fee sent does not match the needed amount
  string public constant CANCELLATION_FEE_ALREADY_REDEEMED = '93'; // cancellation fee already redeemed
  string public constant INVALID_STATE_TO_REDEEM_CANCELLATION_FEE = '94'; // proposal state is not a valid state to redeem cancellation fee
  string public constant MISSING_REPRESENTATION_ROOTS = '95'; // to represent a voter the representation roots need to be registered
  string public constant CALLER_IS_NOT_VOTER_REPRESENTATIVE = '96'; // to represent a voter, caller must be the stored representative
  string public constant VM_INVALID_GOVERNANCE_ADDRESS = '97'; // governance address can not be 0
  string public constant ALL_DELEGATION_ACTIONS_FAILED = '98'; // all meta delegation actions failed on MetaDelegateHelper
}

File 6 of 32 : IBaseCrossChainController.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import './ICrossChainForwarder.sol';
import './ICrossChainReceiver.sol';
import {IRescuable} from 'solidity-utils/contracts/utils/interfaces/IRescuable.sol';

/**
 * @title IBaseCrossChainController
 * @author BGD Labs
 * @notice interface containing the objects, events and methods definitions of the CrossChainController contract
 */
interface IBaseCrossChainController is IRescuable, ICrossChainForwarder, ICrossChainReceiver {

}

File 7 of 32 : IBaseReceiverPortal.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
 * @title IBaseReceiverPortal
 * @author BGD Labs
 * @notice interface defining the method that needs to be implemented by all receiving portals, as its the one that
           will be called when a received message gets confirmed
 */
interface IBaseReceiverPortal {
  /**
   * @notice method called by CrossChainController when a message has been confirmed
   * @param originSender address of the sender of the bridged message
   * @param originChainId id of the chain where the message originated
   * @param message bytes bridged containing the desired information
   */
  function receiveCrossChainMessage(
    address originSender,
    uint256 originChainId,
    bytes memory message
  ) external;
}

File 8 of 32 : IVotingPortal.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IBaseReceiverPortal} from 'aave-crosschain-infra/contracts/interfaces/IBaseReceiverPortal.sol';
import {IVotingMachineWithProofs} from '../contracts/voting/interfaces/IVotingMachineWithProofs.sol';

/**
 * @title IVotingPortal
 * @author BGD Labs
 * @notice interface containing the objects, events and methods definitions of the VotingPortal contract
 */
interface IVotingPortal is IBaseReceiverPortal {
  /**
   * @notice enum containing the different type of messages that can be bridged
   * @param Null empty state
   * @param Proposal indicates that the message is to bridge a proposal configuration
   */
  enum MessageType {
    Null,
    Proposal
  }

  /**
   * @notice emitted when "Start voting" gas limit gets updated
   * @param gasLimit the new gas limit
   */
  event StartVotingGasLimitUpdated(uint128 gasLimit);

  /**
   * @notice emitted when a vote message is received
   * @param originSender address that sent the message on the origin chain
   * @param originChainId id of the chain where the message originated
   * @param delivered flag indicating if message has been delivered
   * @param message bytes containing the necessary information to queue the bridged proposal id
   * @param reason bytes with the revert information
   */
  event VoteMessageReceived(
    address indexed originSender,
    uint256 indexed originChainId,
    bool indexed delivered,
    bytes message,
    bytes reason
  );

  /**
   * @notice get the chain id where the voting machine which is deployed
   * @return network id
   */
  function VOTING_MACHINE_CHAIN_ID() external view returns (uint256);

  /**
   * @notice gets the address of the voting machine on the destination network
   * @return voting machine address
   */
  function VOTING_MACHINE() external view returns (address);

  /**
   * @notice gets the address of the connected governance
   * @return governance address
   */
  function GOVERNANCE() external view returns (address);

  /**
   * @notice gets the address of the CrossChainController deployed on current network
   * @return CrossChainController address
   */
  function CROSS_CHAIN_CONTROLLER() external view returns (address);

  /**
   * @notice method to set the gas limit for "Start voting" bridging tx
   * @param gasLimit the new gas limit
   */
  function setStartVotingGasLimit(uint128 gasLimit) external;

  /**
   * @notice method to get the gas limit for "Start voting" bridging tx
   * @return the gas limit
   */
  function getStartVotingGasLimit() external view returns (uint128);

  /**
   * @notice method to bridge the vote configuration to voting chain, so a vote can be started.
   * @param proposalId id of the proposal bridged to start the vote on
   * @param blockHash hash of the block on L1 when the proposal was activated for voting
   * @param votingDuration duration in seconds of the vote
   */
  function forwardStartVotingMessage(
    uint256 proposalId,
    bytes32 blockHash,
    uint24 votingDuration
  ) external;

  /**
   * @notice method to decode a message from from voting machine chain
   * @param message encoded message with message type
   * @return proposalId, forVotes, againstVotes from the decoded message
   */
  function decodeMessage(
    bytes memory message
  ) external pure returns (uint256, uint128, uint128);
}

File 9 of 32 : IVotingMachineWithProofs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IDataWarehouse} from './IDataWarehouse.sol';
import {IVotingStrategy} from './IVotingStrategy.sol';

/**
 * @title IVotingMachine
 * @author BGD Labs
 * @notice interface containing the objects, events and method definitions of the VotingMachine contract
 */
interface IVotingMachineWithProofs {
  /**
   * @notice Object containing the signature parameters to be able to vote as a representative
   * @param v v part of the voter signature
   * @param r r part of the voter signature
   * @param s s part of the voter signature
   */
  struct SignatureParams {
    uint8 v;
    bytes32 r;
    bytes32 s;
  }

  /**
   * @notice Object to use over submitVoteBySignature and in case of bridging for protect against wrong roots inclusion
   * @param underlyingAsset address of the token on L1, used for voting
   * @param slot base storage position where the balance on underlyingAsset contract resides on L1. (Normally position 0)
   */
  struct VotingAssetWithSlot {
    address underlyingAsset;
    uint128 slot;
  }

  /**
   * @notice object containing the information of a bridged vote
   * @param support indicates if vote is in favor or against the proposal
   * @param votingAssetsWithSlots list of token addresses with storage slots, that the voter will use for voting
   */
  struct BridgedVote {
    bool support;
    VotingAssetWithSlot[] votingAssetsWithSlot;
  }

  /**
   * @notice enum delimiting the possible states a proposal can have on the voting machine
   * @dev ProposalState enum defines the state machine of a proposal being voted, so the order on which the state is
          defined is important. Check logic correctness if new states are added / removed
   */
  enum ProposalState {
    NotCreated,
    Active,
    Finished,
    SentToGovernance
  }

  /**
   * @notice Object with vote information
   * @param support boolean indicating if the vote is in favor or against a proposal
   * @param votingPower the power used for voting
   */
  struct Vote {
    bool support;
    uint248 votingPower;
  }

  /**
   * @notice Object containing a proposal information
   * @param id numeric identification of the proposal
   * @param sentToGovernance boolean indication if the proposal results have been sent back to L1 governance
   * @param startTime timestamp of the start of voting on the proposal
   * @param endTime timestamp when the voting on the proposal finishes (startTime + votingDuration)
   * @param votingClosedAndSentTimestamp timestamp indicating when the vote has been closed and sent to governance chain
   * @param forVotes votes cast in favor of the proposal
   * @param againstVotes votes cast against the proposal
   * @param creationBlockNumber blockNumber from when the proposal has been created in votingMachine
   * @param votingClosedAndSentBlockNumber block from when the vote has been closed and sent to governance chain
   * @param votes mapping indication for every voter of the proposal the information of that vote
   */
  struct Proposal {
    uint256 id;
    bool sentToGovernance;
    uint40 startTime;
    uint40 endTime;
    uint40 votingClosedAndSentTimestamp;
    uint128 forVotes;
    uint128 againstVotes;
    uint256 creationBlockNumber;
    uint256 votingClosedAndSentBlockNumber;
    mapping(address => Vote) votes;
  }

  /**
   * @notice Object containing a proposal information
   * @param id numeric identification of the proposal
   * @param sentToGovernance boolean indication if the proposal results have been sent back to L1 governance
   * @param startTime timestamp of the start of voting on the proposal
   * @param endTime timestamp when the voting on the proposal finishes (startTime + votingDuration)
   * @param votingClosedAndSentTimestamp timestamp indicating when the vote has been closed and sent to governance chain
   * @param forVotes votes cast in favor of the proposal
   * @param againstVotes votes cast against the proposal
   * @param creationBlockNumber blockNumber from when the proposal has been created in votingMachine
   * @param votingClosedAndSentBlockNumber block from when the vote has been closed and sent back to governance chain
   */
  struct ProposalWithoutVotes {
    uint256 id;
    bool sentToGovernance;
    uint40 startTime;
    uint40 endTime;
    uint40 votingClosedAndSentTimestamp;
    uint128 forVotes;
    uint128 againstVotes;
    uint256 creationBlockNumber;
    uint256 votingClosedAndSentBlockNumber;
  }

  /**
   * @notice vote configuration passed from l1
   * @param votingDuration duration in seconds of the vote for a proposal
   * @param l1BlockHash hash of the block on L1 from the block when the proposal was activated for voting (sent to voting machine)
            this block hash is used to delimit from when the voting power is accounted for voting
   */
  struct ProposalVoteConfiguration {
    uint24 votingDuration;
    bytes32 l1ProposalBlockHash;
  }

  /**
   * @notice Object with the necessary information to process a vote
   * @param underlyingAsset address of the token on L1, used for voting
   * @param slot base storage position where the balance on underlyingAsset contract resides on L1. (Normally position 0)
   * @param proof bytes of the generated proof on L1 with the slot information of underlying asset.
   */
  struct VotingBalanceProof {
    address underlyingAsset;
    uint128 slot;
    bytes proof;
  }

  /**
   * @notice emitted when a proposal is created
   * @param proposalId numeric id of the created proposal
   * @param l1BlockHash block hash from the block on l1 from when the proposal was activated for voting
   * @param startTime timestamp when the proposal was created and ready for voting
   * @param endTime timestamp of when the voting period ends. (startTime + votingDuration)
   */
  event ProposalVoteStarted(
    uint256 indexed proposalId,
    bytes32 indexed l1BlockHash,
    uint256 startTime,
    uint256 endTime
  );

  /**
   * @notice emitted when the results of a vote on a proposal are sent to L1
   * @param proposalId numeric id of the proposal which results are sent to L1
   * @param forVotes votes cast in favor of proposal
   * @param againstVotes votes cast against the proposal
   */
  event ProposalResultsSent(
    uint256 indexed proposalId,
    uint256 forVotes,
    uint256 againstVotes
  );

  /**
   * @notice emitted when a vote is registered
   * @param proposalId Id of the proposal
   * @param voter address of the voter
   * @param support boolean, true = vote for, false = vote against
   * @param votingPower Power of the voter/vote
   */
  event VoteEmitted(
    uint256 indexed proposalId,
    address indexed voter,
    bool indexed support,
    uint256 votingPower
  );

  /**
   * @notice emitted when a voting configuration of a proposal gets received. Meaning that has been bridged successfully
   * @param proposalId id of the proposal bridged to start the vote on
   * @param blockHash hash of the block on L1 when the proposal was activated for voting
   * @param votingDuration duration in seconds of the vote
   * @param voteCreated boolean indicating if the vote has been created or not.
   * @dev the vote will only be created automatically if when the configuration is bridged, all necessary roots
          have been registered already.
   */
  event ProposalVoteConfigurationBridged(
    uint256 indexed proposalId,
    bytes32 indexed blockHash,
    uint24 votingDuration,
    bool indexed voteCreated
  );

  /**
   * @notice method to get the representatives mapping slot in Governance contract
   * @return representatives slot
   */
  function REPRESENTATIVES_SLOT() external view returns (uint256);

  /**
   * @notice method to get the Governance contract address
   * @return Governance address
   */
  function GOVERNANCE() external view returns (address);

  /**
   * @notice method to get the voting asset with slot signature
   * @return signature of the voting asset with slot method
   */
  function VOTING_ASSET_WITH_SLOT_RAW() external view returns (string memory);

  /**
   * @notice method to get the DataWarehouse contract
   * @return DataWarehouse contract
   */
  function DATA_WAREHOUSE() external view returns (IDataWarehouse);

  /**
   * @notice method to get the VotingStrategy contract
   * @return VotingStrategy contract
   */
  function VOTING_STRATEGY() external view returns (IVotingStrategy);

  /**
   * @notice Get the v4 compatible domain separator
   * @dev Return cached value if chainId matches cache, otherwise recomputes separator
   * @return The domain separator of the token at current chain
   */
  function DOMAIN_SEPARATOR() external view returns (bytes32);

  /**
   * @notice method to get the vote submitted type hash for permits digest
   * @return hash of vote submitted string
   */
  function VOTE_SUBMITTED_TYPEHASH() external view returns (bytes32);

  /**
   * @notice method to get the vote submitted by representative type hash for permits digest
   * @return hash of vote submitted by representative string
   */
  function VOTE_SUBMITTED_BY_REPRESENTATIVE_TYPEHASH()
    external
    view
    returns (bytes32);

  /**
   * @notice method to get the voting asset with slot type hash for permits digest
   * @return hash of vote submitted string
   */
  function VOTING_ASSET_WITH_SLOT_TYPEHASH() external view returns (bytes32);

  /**
   * @notice method to get the contract name for permits digest
   * @return contract name string
   */
  function NAME() external view returns (string memory);

  /**
   * @notice method to get a proposal information specified by its id
   * @param proposalId id of the proposal to retrieve
   * @return the proposal information without the users vote
   */
  function getProposalById(
    uint256 proposalId
  ) external view returns (ProposalWithoutVotes memory);

  /**
   * @notice method to get the state of a proposal specified by its id
   * @param proposalId id of the proposal to retrieve the state of
   * @return the state of the proposal
   */
  function getProposalState(
    uint256 proposalId
  ) external view returns (ProposalState);

  /**
   * @notice method to get the voting configuration of a proposal specified by its id
   * @param proposalId id of the proposal to retrieve the voting configuration from
   * @return the proposal vote configuration object
   */
  function getProposalVoteConfiguration(
    uint256 proposalId
  ) external view returns (ProposalVoteConfiguration memory);

  /**
  * @notice method to get a paginated list of proposalIds. The proposals are taken from a list of proposals that have
            received vote configuration from governance chain
  * @param skip number of proposal ids to skip. from latest in the list of proposal ids with voting configuration
  * @param size length of proposal ids to ask for.
  * @return list of proposal ids
  * @dev This is mainly used to get a list of proposals that require automation in some step of the proposal live cycle.
  */
  function getProposalsVoteConfigurationIds(
    uint256 skip,
    uint256 size
  ) external view returns (uint256[] memory);

  /**
   * @notice method to get the vote set by a user on a proposal specified by its id
   * @param user address of the user that voted
   * @param proposalId id of the proposal to retrieve the vote from
   * @return the vote (support and voting power) emitted
   */
  function getUserProposalVote(
    address user,
    uint256 proposalId
  ) external view returns (Vote memory);

  /**
    * @notice method to start a vote on a proposal specified by its id.
    * @param proposalId id of the proposal to start the vote on.
    * @return the id of the proposal that had the vote started on.
    * @dev this method can be called by anyone, requiring that the appropriate conditions are met.
           basically that the proper roots have been registered.
           It can also be called internally when the bridged message is received and the the required roots
           have been registered
    */
  function startProposalVote(uint256 proposalId) external returns (uint256);

  /**
    * @notice method to cast a vote on a proposal specified by its id
    * @param proposalId id of the proposal on which the vote will be cast
    * @param support boolean indicating if the vote is in favor or against the proposal
    * @param votingBalanceProofs list of objects containing the information necessary to vote using the tokens
             allowed on the voting strategy.
    * @dev A vote does not need to use all the tokens allowed, can be a subset
    */
  function submitVote(
    uint256 proposalId,
    bool support,
    VotingBalanceProof[] calldata votingBalanceProofs
  ) external;

  /**
   * @notice Function to register the vote of user that has voted offchain via signature
   * @param proposalId id of the proposal
   * @param voter the voter address
   * @param support boolean, true = vote for, false = vote against
   * @param votingBalanceProofs list of voting assets proofs
   * @param v v part of the voter signature
   * @param r r part of the voter signature
   * @param s s part of the voter signature
   */
  function submitVoteBySignature(
    uint256 proposalId,
    address voter,
    bool support,
    VotingBalanceProof[] calldata votingBalanceProofs,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external;

  /**
   * @notice method to close a vote on a proposal specified by its id and send the results back to governance
   * @param proposalId id of the proposal to close the vote on and send the voting result to governance
   * @dev This method will trigger the bridging flow
   */
  function closeAndSendVote(uint256 proposalId) external;

  /**
   * @notice Function to register the vote of user as its representative
   * @param proposalId id of the proposal
   * @param support boolean, true = vote for, false = vote against
   * @param voter the voter address
   * @param proofOfRepresentation proof that can validate that msg.sender is the voter representative
   * @param votingBalanceProofs list of voting assets proofs
   */
  function submitVoteAsRepresentative(
    uint256 proposalId,
    bool support,
    address voter,
    bytes memory proofOfRepresentation,
    VotingBalanceProof[] calldata votingBalanceProofs
  ) external;

  /**
   * @notice Function to register the vote of user as its representative with a signed message
   * @param proposalId id of the proposal
   * @param voter the voter address
   * @param proofOfRepresentation proof that can validate that msg.sender is the voter representative
   * @param votingBalanceProofs list of voting assets proofs
   * @param signatureParams object containing the necessary signature parameters
   */
  function submitVoteAsRepresentativeBySignature(
    uint256 proposalId,
    address voter,
    address representative,
    bool support,
    bytes memory proofOfRepresentation,
    VotingBalanceProof[] calldata votingBalanceProofs,
    SignatureParams memory signatureParams
  ) external;
}

File 10 of 32 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
// From commit https://github.com/OpenZeppelin/openzeppelin-contracts/commit/8b778fa20d6d76340c5fac1ed66c80273f05b95a

pragma solidity ^0.8.0;

import './Context.sol';

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

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

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

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

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

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

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

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

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

File 11 of 32 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
  /**
   * @dev Returns the downcasted uint248 from uint256, reverting on
   * overflow (when the input is greater than largest uint248).
   *
   * Counterpart to Solidity's `uint248` operator.
   *
   * Requirements:
   *
   * - input must fit into 248 bits
   *
   * _Available since v4.7._
   */
  function toUint248(uint256 value) internal pure returns (uint248) {
    require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
    return uint248(value);
  }

  /**
   * @dev Returns the downcasted uint240 from uint256, reverting on
   * overflow (when the input is greater than largest uint240).
   *
   * Counterpart to Solidity's `uint240` operator.
   *
   * Requirements:
   *
   * - input must fit into 240 bits
   *
   * _Available since v4.7._
   */
  function toUint240(uint256 value) internal pure returns (uint240) {
    require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
    return uint240(value);
  }

  /**
   * @dev Returns the downcasted uint232 from uint256, reverting on
   * overflow (when the input is greater than largest uint232).
   *
   * Counterpart to Solidity's `uint232` operator.
   *
   * Requirements:
   *
   * - input must fit into 232 bits
   *
   * _Available since v4.7._
   */
  function toUint232(uint256 value) internal pure returns (uint232) {
    require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
    return uint232(value);
  }

  /**
   * @dev Returns the downcasted uint224 from uint256, reverting on
   * overflow (when the input is greater than largest uint224).
   *
   * Counterpart to Solidity's `uint224` operator.
   *
   * Requirements:
   *
   * - input must fit into 224 bits
   *
   * _Available since v4.2._
   */
  function toUint224(uint256 value) internal pure returns (uint224) {
    require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
    return uint224(value);
  }

  /**
   * @dev Returns the downcasted uint216 from uint256, reverting on
   * overflow (when the input is greater than largest uint216).
   *
   * Counterpart to Solidity's `uint216` operator.
   *
   * Requirements:
   *
   * - input must fit into 216 bits
   *
   * _Available since v4.7._
   */
  function toUint216(uint256 value) internal pure returns (uint216) {
    require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
    return uint216(value);
  }

  /**
   * @dev Returns the downcasted uint208 from uint256, reverting on
   * overflow (when the input is greater than largest uint208).
   *
   * Counterpart to Solidity's `uint208` operator.
   *
   * Requirements:
   *
   * - input must fit into 208 bits
   *
   * _Available since v4.7._
   */
  function toUint208(uint256 value) internal pure returns (uint208) {
    require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
    return uint208(value);
  }

  /**
   * @dev Returns the downcasted uint200 from uint256, reverting on
   * overflow (when the input is greater than largest uint200).
   *
   * Counterpart to Solidity's `uint200` operator.
   *
   * Requirements:
   *
   * - input must fit into 200 bits
   *
   * _Available since v4.7._
   */
  function toUint200(uint256 value) internal pure returns (uint200) {
    require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
    return uint200(value);
  }

  /**
   * @dev Returns the downcasted uint192 from uint256, reverting on
   * overflow (when the input is greater than largest uint192).
   *
   * Counterpart to Solidity's `uint192` operator.
   *
   * Requirements:
   *
   * - input must fit into 192 bits
   *
   * _Available since v4.7._
   */
  function toUint192(uint256 value) internal pure returns (uint192) {
    require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
    return uint192(value);
  }

  /**
   * @dev Returns the downcasted uint184 from uint256, reverting on
   * overflow (when the input is greater than largest uint184).
   *
   * Counterpart to Solidity's `uint184` operator.
   *
   * Requirements:
   *
   * - input must fit into 184 bits
   *
   * _Available since v4.7._
   */
  function toUint184(uint256 value) internal pure returns (uint184) {
    require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
    return uint184(value);
  }

  /**
   * @dev Returns the downcasted uint176 from uint256, reverting on
   * overflow (when the input is greater than largest uint176).
   *
   * Counterpart to Solidity's `uint176` operator.
   *
   * Requirements:
   *
   * - input must fit into 176 bits
   *
   * _Available since v4.7._
   */
  function toUint176(uint256 value) internal pure returns (uint176) {
    require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
    return uint176(value);
  }

  /**
   * @dev Returns the downcasted uint168 from uint256, reverting on
   * overflow (when the input is greater than largest uint168).
   *
   * Counterpart to Solidity's `uint168` operator.
   *
   * Requirements:
   *
   * - input must fit into 168 bits
   *
   * _Available since v4.7._
   */
  function toUint168(uint256 value) internal pure returns (uint168) {
    require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
    return uint168(value);
  }

  /**
   * @dev Returns the downcasted uint160 from uint256, reverting on
   * overflow (when the input is greater than largest uint160).
   *
   * Counterpart to Solidity's `uint160` operator.
   *
   * Requirements:
   *
   * - input must fit into 160 bits
   *
   * _Available since v4.7._
   */
  function toUint160(uint256 value) internal pure returns (uint160) {
    require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
    return uint160(value);
  }

  /**
   * @dev Returns the downcasted uint152 from uint256, reverting on
   * overflow (when the input is greater than largest uint152).
   *
   * Counterpart to Solidity's `uint152` operator.
   *
   * Requirements:
   *
   * - input must fit into 152 bits
   *
   * _Available since v4.7._
   */
  function toUint152(uint256 value) internal pure returns (uint152) {
    require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
    return uint152(value);
  }

  /**
   * @dev Returns the downcasted uint144 from uint256, reverting on
   * overflow (when the input is greater than largest uint144).
   *
   * Counterpart to Solidity's `uint144` operator.
   *
   * Requirements:
   *
   * - input must fit into 144 bits
   *
   * _Available since v4.7._
   */
  function toUint144(uint256 value) internal pure returns (uint144) {
    require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
    return uint144(value);
  }

  /**
   * @dev Returns the downcasted uint136 from uint256, reverting on
   * overflow (when the input is greater than largest uint136).
   *
   * Counterpart to Solidity's `uint136` operator.
   *
   * Requirements:
   *
   * - input must fit into 136 bits
   *
   * _Available since v4.7._
   */
  function toUint136(uint256 value) internal pure returns (uint136) {
    require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
    return uint136(value);
  }

  /**
   * @dev Returns the downcasted uint128 from uint256, reverting on
   * overflow (when the input is greater than largest uint128).
   *
   * Counterpart to Solidity's `uint128` operator.
   *
   * Requirements:
   *
   * - input must fit into 128 bits
   *
   * _Available since v2.5._
   */
  function toUint128(uint256 value) internal pure returns (uint128) {
    require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
    return uint128(value);
  }

  /**
   * @dev Returns the downcasted uint120 from uint256, reverting on
   * overflow (when the input is greater than largest uint120).
   *
   * Counterpart to Solidity's `uint120` operator.
   *
   * Requirements:
   *
   * - input must fit into 120 bits
   *
   * _Available since v4.7._
   */
  function toUint120(uint256 value) internal pure returns (uint120) {
    require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
    return uint120(value);
  }

  /**
   * @dev Returns the downcasted uint112 from uint256, reverting on
   * overflow (when the input is greater than largest uint112).
   *
   * Counterpart to Solidity's `uint112` operator.
   *
   * Requirements:
   *
   * - input must fit into 112 bits
   *
   * _Available since v4.7._
   */
  function toUint112(uint256 value) internal pure returns (uint112) {
    require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
    return uint112(value);
  }

  /**
   * @dev Returns the downcasted uint104 from uint256, reverting on
   * overflow (when the input is greater than largest uint104).
   *
   * Counterpart to Solidity's `uint104` operator.
   *
   * Requirements:
   *
   * - input must fit into 104 bits
   *
   * _Available since v4.7._
   */
  function toUint104(uint256 value) internal pure returns (uint104) {
    require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
    return uint104(value);
  }

  /**
   * @dev Returns the downcasted uint96 from uint256, reverting on
   * overflow (when the input is greater than largest uint96).
   *
   * Counterpart to Solidity's `uint96` operator.
   *
   * Requirements:
   *
   * - input must fit into 96 bits
   *
   * _Available since v4.2._
   */
  function toUint96(uint256 value) internal pure returns (uint96) {
    require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
    return uint96(value);
  }

  /**
   * @dev Returns the downcasted uint88 from uint256, reverting on
   * overflow (when the input is greater than largest uint88).
   *
   * Counterpart to Solidity's `uint88` operator.
   *
   * Requirements:
   *
   * - input must fit into 88 bits
   *
   * _Available since v4.7._
   */
  function toUint88(uint256 value) internal pure returns (uint88) {
    require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
    return uint88(value);
  }

  /**
   * @dev Returns the downcasted uint80 from uint256, reverting on
   * overflow (when the input is greater than largest uint80).
   *
   * Counterpart to Solidity's `uint80` operator.
   *
   * Requirements:
   *
   * - input must fit into 80 bits
   *
   * _Available since v4.7._
   */
  function toUint80(uint256 value) internal pure returns (uint80) {
    require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
    return uint80(value);
  }

  /**
   * @dev Returns the downcasted uint72 from uint256, reverting on
   * overflow (when the input is greater than largest uint72).
   *
   * Counterpart to Solidity's `uint72` operator.
   *
   * Requirements:
   *
   * - input must fit into 72 bits
   *
   * _Available since v4.7._
   */
  function toUint72(uint256 value) internal pure returns (uint72) {
    require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
    return uint72(value);
  }

  /**
   * @dev Returns the downcasted uint64 from uint256, reverting on
   * overflow (when the input is greater than largest uint64).
   *
   * Counterpart to Solidity's `uint64` operator.
   *
   * Requirements:
   *
   * - input must fit into 64 bits
   *
   * _Available since v2.5._
   */
  function toUint64(uint256 value) internal pure returns (uint64) {
    require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
    return uint64(value);
  }

  /**
   * @dev Returns the downcasted uint56 from uint256, reverting on
   * overflow (when the input is greater than largest uint56).
   *
   * Counterpart to Solidity's `uint56` operator.
   *
   * Requirements:
   *
   * - input must fit into 56 bits
   *
   * _Available since v4.7._
   */
  function toUint56(uint256 value) internal pure returns (uint56) {
    require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
    return uint56(value);
  }

  /**
   * @dev Returns the downcasted uint48 from uint256, reverting on
   * overflow (when the input is greater than largest uint48).
   *
   * Counterpart to Solidity's `uint48` operator.
   *
   * Requirements:
   *
   * - input must fit into 48 bits
   *
   * _Available since v4.7._
   */
  function toUint48(uint256 value) internal pure returns (uint48) {
    require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
    return uint48(value);
  }

  /**
   * @dev Returns the downcasted uint40 from uint256, reverting on
   * overflow (when the input is greater than largest uint40).
   *
   * Counterpart to Solidity's `uint40` operator.
   *
   * Requirements:
   *
   * - input must fit into 40 bits
   *
   * _Available since v4.7._
   */
  function toUint40(uint256 value) internal pure returns (uint40) {
    require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
    return uint40(value);
  }

  /**
   * @dev Returns the downcasted uint32 from uint256, reverting on
   * overflow (when the input is greater than largest uint32).
   *
   * Counterpart to Solidity's `uint32` operator.
   *
   * Requirements:
   *
   * - input must fit into 32 bits
   *
   * _Available since v2.5._
   */
  function toUint32(uint256 value) internal pure returns (uint32) {
    require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
    return uint32(value);
  }

  /**
   * @dev Returns the downcasted uint24 from uint256, reverting on
   * overflow (when the input is greater than largest uint24).
   *
   * Counterpart to Solidity's `uint24` operator.
   *
   * Requirements:
   *
   * - input must fit into 24 bits
   *
   * _Available since v4.7._
   */
  function toUint24(uint256 value) internal pure returns (uint24) {
    require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
    return uint24(value);
  }

  /**
   * @dev Returns the downcasted uint16 from uint256, reverting on
   * overflow (when the input is greater than largest uint16).
   *
   * Counterpart to Solidity's `uint16` operator.
   *
   * Requirements:
   *
   * - input must fit into 16 bits
   *
   * _Available since v2.5._
   */
  function toUint16(uint256 value) internal pure returns (uint16) {
    require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
    return uint16(value);
  }

  /**
   * @dev Returns the downcasted uint8 from uint256, reverting on
   * overflow (when the input is greater than largest uint8).
   *
   * Counterpart to Solidity's `uint8` operator.
   *
   * Requirements:
   *
   * - input must fit into 8 bits
   *
   * _Available since v2.5._
   */
  function toUint8(uint256 value) internal pure returns (uint8) {
    require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
    return uint8(value);
  }

  /**
   * @dev Converts a signed int256 into an unsigned uint256.
   *
   * Requirements:
   *
   * - input must be greater than or equal to 0.
   *
   * _Available since v3.0._
   */
  function toUint256(int256 value) internal pure returns (uint256) {
    require(value >= 0, 'SafeCast: value must be positive');
    return uint256(value);
  }

  /**
   * @dev Returns the downcasted int248 from int256, reverting on
   * overflow (when the input is less than smallest int248 or
   * greater than largest int248).
   *
   * Counterpart to Solidity's `int248` operator.
   *
   * Requirements:
   *
   * - input must fit into 248 bits
   *
   * _Available since v4.7._
   */
  function toInt248(int256 value) internal pure returns (int248 downcasted) {
    downcasted = int248(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
  }

  /**
   * @dev Returns the downcasted int240 from int256, reverting on
   * overflow (when the input is less than smallest int240 or
   * greater than largest int240).
   *
   * Counterpart to Solidity's `int240` operator.
   *
   * Requirements:
   *
   * - input must fit into 240 bits
   *
   * _Available since v4.7._
   */
  function toInt240(int256 value) internal pure returns (int240 downcasted) {
    downcasted = int240(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
  }

  /**
   * @dev Returns the downcasted int232 from int256, reverting on
   * overflow (when the input is less than smallest int232 or
   * greater than largest int232).
   *
   * Counterpart to Solidity's `int232` operator.
   *
   * Requirements:
   *
   * - input must fit into 232 bits
   *
   * _Available since v4.7._
   */
  function toInt232(int256 value) internal pure returns (int232 downcasted) {
    downcasted = int232(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
  }

  /**
   * @dev Returns the downcasted int224 from int256, reverting on
   * overflow (when the input is less than smallest int224 or
   * greater than largest int224).
   *
   * Counterpart to Solidity's `int224` operator.
   *
   * Requirements:
   *
   * - input must fit into 224 bits
   *
   * _Available since v4.7._
   */
  function toInt224(int256 value) internal pure returns (int224 downcasted) {
    downcasted = int224(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
  }

  /**
   * @dev Returns the downcasted int216 from int256, reverting on
   * overflow (when the input is less than smallest int216 or
   * greater than largest int216).
   *
   * Counterpart to Solidity's `int216` operator.
   *
   * Requirements:
   *
   * - input must fit into 216 bits
   *
   * _Available since v4.7._
   */
  function toInt216(int256 value) internal pure returns (int216 downcasted) {
    downcasted = int216(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
  }

  /**
   * @dev Returns the downcasted int208 from int256, reverting on
   * overflow (when the input is less than smallest int208 or
   * greater than largest int208).
   *
   * Counterpart to Solidity's `int208` operator.
   *
   * Requirements:
   *
   * - input must fit into 208 bits
   *
   * _Available since v4.7._
   */
  function toInt208(int256 value) internal pure returns (int208 downcasted) {
    downcasted = int208(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
  }

  /**
   * @dev Returns the downcasted int200 from int256, reverting on
   * overflow (when the input is less than smallest int200 or
   * greater than largest int200).
   *
   * Counterpart to Solidity's `int200` operator.
   *
   * Requirements:
   *
   * - input must fit into 200 bits
   *
   * _Available since v4.7._
   */
  function toInt200(int256 value) internal pure returns (int200 downcasted) {
    downcasted = int200(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
  }

  /**
   * @dev Returns the downcasted int192 from int256, reverting on
   * overflow (when the input is less than smallest int192 or
   * greater than largest int192).
   *
   * Counterpart to Solidity's `int192` operator.
   *
   * Requirements:
   *
   * - input must fit into 192 bits
   *
   * _Available since v4.7._
   */
  function toInt192(int256 value) internal pure returns (int192 downcasted) {
    downcasted = int192(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
  }

  /**
   * @dev Returns the downcasted int184 from int256, reverting on
   * overflow (when the input is less than smallest int184 or
   * greater than largest int184).
   *
   * Counterpart to Solidity's `int184` operator.
   *
   * Requirements:
   *
   * - input must fit into 184 bits
   *
   * _Available since v4.7._
   */
  function toInt184(int256 value) internal pure returns (int184 downcasted) {
    downcasted = int184(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
  }

  /**
   * @dev Returns the downcasted int176 from int256, reverting on
   * overflow (when the input is less than smallest int176 or
   * greater than largest int176).
   *
   * Counterpart to Solidity's `int176` operator.
   *
   * Requirements:
   *
   * - input must fit into 176 bits
   *
   * _Available since v4.7._
   */
  function toInt176(int256 value) internal pure returns (int176 downcasted) {
    downcasted = int176(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
  }

  /**
   * @dev Returns the downcasted int168 from int256, reverting on
   * overflow (when the input is less than smallest int168 or
   * greater than largest int168).
   *
   * Counterpart to Solidity's `int168` operator.
   *
   * Requirements:
   *
   * - input must fit into 168 bits
   *
   * _Available since v4.7._
   */
  function toInt168(int256 value) internal pure returns (int168 downcasted) {
    downcasted = int168(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
  }

  /**
   * @dev Returns the downcasted int160 from int256, reverting on
   * overflow (when the input is less than smallest int160 or
   * greater than largest int160).
   *
   * Counterpart to Solidity's `int160` operator.
   *
   * Requirements:
   *
   * - input must fit into 160 bits
   *
   * _Available since v4.7._
   */
  function toInt160(int256 value) internal pure returns (int160 downcasted) {
    downcasted = int160(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
  }

  /**
   * @dev Returns the downcasted int152 from int256, reverting on
   * overflow (when the input is less than smallest int152 or
   * greater than largest int152).
   *
   * Counterpart to Solidity's `int152` operator.
   *
   * Requirements:
   *
   * - input must fit into 152 bits
   *
   * _Available since v4.7._
   */
  function toInt152(int256 value) internal pure returns (int152 downcasted) {
    downcasted = int152(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
  }

  /**
   * @dev Returns the downcasted int144 from int256, reverting on
   * overflow (when the input is less than smallest int144 or
   * greater than largest int144).
   *
   * Counterpart to Solidity's `int144` operator.
   *
   * Requirements:
   *
   * - input must fit into 144 bits
   *
   * _Available since v4.7._
   */
  function toInt144(int256 value) internal pure returns (int144 downcasted) {
    downcasted = int144(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
  }

  /**
   * @dev Returns the downcasted int136 from int256, reverting on
   * overflow (when the input is less than smallest int136 or
   * greater than largest int136).
   *
   * Counterpart to Solidity's `int136` operator.
   *
   * Requirements:
   *
   * - input must fit into 136 bits
   *
   * _Available since v4.7._
   */
  function toInt136(int256 value) internal pure returns (int136 downcasted) {
    downcasted = int136(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
  }

  /**
   * @dev Returns the downcasted int128 from int256, reverting on
   * overflow (when the input is less than smallest int128 or
   * greater than largest int128).
   *
   * Counterpart to Solidity's `int128` operator.
   *
   * Requirements:
   *
   * - input must fit into 128 bits
   *
   * _Available since v3.1._
   */
  function toInt128(int256 value) internal pure returns (int128 downcasted) {
    downcasted = int128(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
  }

  /**
   * @dev Returns the downcasted int120 from int256, reverting on
   * overflow (when the input is less than smallest int120 or
   * greater than largest int120).
   *
   * Counterpart to Solidity's `int120` operator.
   *
   * Requirements:
   *
   * - input must fit into 120 bits
   *
   * _Available since v4.7._
   */
  function toInt120(int256 value) internal pure returns (int120 downcasted) {
    downcasted = int120(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
  }

  /**
   * @dev Returns the downcasted int112 from int256, reverting on
   * overflow (when the input is less than smallest int112 or
   * greater than largest int112).
   *
   * Counterpart to Solidity's `int112` operator.
   *
   * Requirements:
   *
   * - input must fit into 112 bits
   *
   * _Available since v4.7._
   */
  function toInt112(int256 value) internal pure returns (int112 downcasted) {
    downcasted = int112(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
  }

  /**
   * @dev Returns the downcasted int104 from int256, reverting on
   * overflow (when the input is less than smallest int104 or
   * greater than largest int104).
   *
   * Counterpart to Solidity's `int104` operator.
   *
   * Requirements:
   *
   * - input must fit into 104 bits
   *
   * _Available since v4.7._
   */
  function toInt104(int256 value) internal pure returns (int104 downcasted) {
    downcasted = int104(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
  }

  /**
   * @dev Returns the downcasted int96 from int256, reverting on
   * overflow (when the input is less than smallest int96 or
   * greater than largest int96).
   *
   * Counterpart to Solidity's `int96` operator.
   *
   * Requirements:
   *
   * - input must fit into 96 bits
   *
   * _Available since v4.7._
   */
  function toInt96(int256 value) internal pure returns (int96 downcasted) {
    downcasted = int96(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
  }

  /**
   * @dev Returns the downcasted int88 from int256, reverting on
   * overflow (when the input is less than smallest int88 or
   * greater than largest int88).
   *
   * Counterpart to Solidity's `int88` operator.
   *
   * Requirements:
   *
   * - input must fit into 88 bits
   *
   * _Available since v4.7._
   */
  function toInt88(int256 value) internal pure returns (int88 downcasted) {
    downcasted = int88(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
  }

  /**
   * @dev Returns the downcasted int80 from int256, reverting on
   * overflow (when the input is less than smallest int80 or
   * greater than largest int80).
   *
   * Counterpart to Solidity's `int80` operator.
   *
   * Requirements:
   *
   * - input must fit into 80 bits
   *
   * _Available since v4.7._
   */
  function toInt80(int256 value) internal pure returns (int80 downcasted) {
    downcasted = int80(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
  }

  /**
   * @dev Returns the downcasted int72 from int256, reverting on
   * overflow (when the input is less than smallest int72 or
   * greater than largest int72).
   *
   * Counterpart to Solidity's `int72` operator.
   *
   * Requirements:
   *
   * - input must fit into 72 bits
   *
   * _Available since v4.7._
   */
  function toInt72(int256 value) internal pure returns (int72 downcasted) {
    downcasted = int72(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
  }

  /**
   * @dev Returns the downcasted int64 from int256, reverting on
   * overflow (when the input is less than smallest int64 or
   * greater than largest int64).
   *
   * Counterpart to Solidity's `int64` operator.
   *
   * Requirements:
   *
   * - input must fit into 64 bits
   *
   * _Available since v3.1._
   */
  function toInt64(int256 value) internal pure returns (int64 downcasted) {
    downcasted = int64(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
  }

  /**
   * @dev Returns the downcasted int56 from int256, reverting on
   * overflow (when the input is less than smallest int56 or
   * greater than largest int56).
   *
   * Counterpart to Solidity's `int56` operator.
   *
   * Requirements:
   *
   * - input must fit into 56 bits
   *
   * _Available since v4.7._
   */
  function toInt56(int256 value) internal pure returns (int56 downcasted) {
    downcasted = int56(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
  }

  /**
   * @dev Returns the downcasted int48 from int256, reverting on
   * overflow (when the input is less than smallest int48 or
   * greater than largest int48).
   *
   * Counterpart to Solidity's `int48` operator.
   *
   * Requirements:
   *
   * - input must fit into 48 bits
   *
   * _Available since v4.7._
   */
  function toInt48(int256 value) internal pure returns (int48 downcasted) {
    downcasted = int48(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
  }

  /**
   * @dev Returns the downcasted int40 from int256, reverting on
   * overflow (when the input is less than smallest int40 or
   * greater than largest int40).
   *
   * Counterpart to Solidity's `int40` operator.
   *
   * Requirements:
   *
   * - input must fit into 40 bits
   *
   * _Available since v4.7._
   */
  function toInt40(int256 value) internal pure returns (int40 downcasted) {
    downcasted = int40(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
  }

  /**
   * @dev Returns the downcasted int32 from int256, reverting on
   * overflow (when the input is less than smallest int32 or
   * greater than largest int32).
   *
   * Counterpart to Solidity's `int32` operator.
   *
   * Requirements:
   *
   * - input must fit into 32 bits
   *
   * _Available since v3.1._
   */
  function toInt32(int256 value) internal pure returns (int32 downcasted) {
    downcasted = int32(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
  }

  /**
   * @dev Returns the downcasted int24 from int256, reverting on
   * overflow (when the input is less than smallest int24 or
   * greater than largest int24).
   *
   * Counterpart to Solidity's `int24` operator.
   *
   * Requirements:
   *
   * - input must fit into 24 bits
   *
   * _Available since v4.7._
   */
  function toInt24(int256 value) internal pure returns (int24 downcasted) {
    downcasted = int24(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
  }

  /**
   * @dev Returns the downcasted int16 from int256, reverting on
   * overflow (when the input is less than smallest int16 or
   * greater than largest int16).
   *
   * Counterpart to Solidity's `int16` operator.
   *
   * Requirements:
   *
   * - input must fit into 16 bits
   *
   * _Available since v3.1._
   */
  function toInt16(int256 value) internal pure returns (int16 downcasted) {
    downcasted = int16(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
  }

  /**
   * @dev Returns the downcasted int8 from int256, reverting on
   * overflow (when the input is less than smallest int8 or
   * greater than largest int8).
   *
   * Counterpart to Solidity's `int8` operator.
   *
   * Requirements:
   *
   * - input must fit into 8 bits
   *
   * _Available since v3.1._
   */
  function toInt8(int256 value) internal pure returns (int8 downcasted) {
    downcasted = int8(value);
    require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
  }

  /**
   * @dev Converts an unsigned uint256 into a signed int256.
   *
   * Requirements:
   *
   * - input must be less than or equal to maxInt256.
   *
   * _Available since v3.0._
   */
  function toInt256(uint256 value) internal pure returns (int256) {
    // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
    require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
    return int256(value);
  }
}

File 12 of 32 : StateProofVerifier.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {RLPReader} from './RLPReader.sol';
import {MerklePatriciaProofVerifier} from './MerklePatriciaProofVerifier.sol';

/**
 * @title A helper library for verification of Merkle Patricia account and state proofs.
 */
library StateProofVerifier {
  using RLPReader for RLPReader.RLPItem;
  using RLPReader for bytes;

  uint256 constant HEADER_STATE_ROOT_INDEX = 3;
  uint256 constant HEADER_NUMBER_INDEX = 8;
  uint256 constant HEADER_TIMESTAMP_INDEX = 11;

  struct BlockHeader {
    bytes32 hash;
    bytes32 stateRootHash;
    uint256 number;
    uint256 timestamp;
  }

  struct Account {
    bool exists;
    uint256 nonce;
    uint256 balance;
    bytes32 storageRoot;
    bytes32 codeHash;
  }

  struct SlotValue {
    bool exists;
    uint256 value;
  }

  /**
   * @notice Parses block header and verifies its presence onchain within the latest 256 blocks.
   * @param _headerRlpBytes RLP-encoded block header.
   */
  function verifyBlockHeader(
    bytes memory _headerRlpBytes,
    bytes32 _blockHash
  ) internal pure returns (BlockHeader memory) {
    BlockHeader memory header = parseBlockHeader(_headerRlpBytes);
    require(header.hash == _blockHash, 'blockhash mismatch');
    return header;
  }

  /**
   * @notice Parses RLP-encoded block header.
   * @param _headerRlpBytes RLP-encoded block header.
   */
  function parseBlockHeader(
    bytes memory _headerRlpBytes
  ) internal pure returns (BlockHeader memory) {
    BlockHeader memory result;
    RLPReader.RLPItem[] memory headerFields = _headerRlpBytes
      .toRlpItem()
      .toList();

    require(headerFields.length > HEADER_TIMESTAMP_INDEX);

    result.stateRootHash = bytes32(
      headerFields[HEADER_STATE_ROOT_INDEX].toUint()
    );
    result.number = headerFields[HEADER_NUMBER_INDEX].toUint();
    result.timestamp = headerFields[HEADER_TIMESTAMP_INDEX].toUint();
    result.hash = keccak256(_headerRlpBytes);

    return result;
  }

  /**
   * @notice Verifies Merkle Patricia proof of an account and extracts the account fields.
   *
   * @param _addressHash Keccak256 hash of the address corresponding to the account.
   * @param _stateRootHash MPT root hash of the Ethereum state trie.
   */
  function extractAccountFromProof(
    bytes32 _addressHash, // keccak256(abi.encodePacked(address))
    bytes32 _stateRootHash,
    RLPReader.RLPItem[] memory _proof
  ) internal pure returns (Account memory) {
    bytes memory acctRlpBytes = MerklePatriciaProofVerifier.extractProofValue(
      _stateRootHash,
      abi.encodePacked(_addressHash),
      _proof
    );
    Account memory account;

    if (acctRlpBytes.length == 0) {
      return account;
    }

    RLPReader.RLPItem[] memory acctFields = acctRlpBytes.toRlpItem().toList();
    require(acctFields.length == 4);

    account.exists = true;
    account.nonce = acctFields[0].toUint();
    account.balance = acctFields[1].toUint();
    account.storageRoot = bytes32(acctFields[2].toUint());
    account.codeHash = bytes32(acctFields[3].toUint());

    return account;
  }

  /**
   * @notice Verifies Merkle Patricia proof of a slot and extracts the slot's value.
   *
   * @param _slotHash Keccak256 hash of the slot position.
   * @param _storageRootHash MPT root hash of the account's storage trie.
   */
  function extractSlotValueFromProof(
    bytes32 _slotHash,
    bytes32 _storageRootHash,
    RLPReader.RLPItem[] memory _proof
  ) internal pure returns (SlotValue memory) {
    bytes memory valueRlpBytes = MerklePatriciaProofVerifier.extractProofValue(
      _storageRootHash,
      abi.encodePacked(_slotHash),
      _proof
    );

    SlotValue memory value;

    if (valueRlpBytes.length != 0) {
      value.exists = true;
      value.value = valueRlpBytes.toRlpItem().toUint();
    }

    return value;
  }
}

File 13 of 32 : IBaseVotingStrategy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
 * @title IBaseVotingStrategy
 * @author BGD Labs
 * @notice interface containing the objects, events and method definitions of the BaseVotingStrategy contract
 */
interface IBaseVotingStrategy {
  /**
   * @notice object storing the information of the asset used for the voting strategy
   * @param storageSlots list of slots for the balance of the specified token.
            From that slot, by adding the address of the user, the correct balance can be taken.
   */
  struct VotingAssetConfig {
    uint128[] storageSlots;
  }

  /**
   * @notice emitted when an asset is added for the voting strategy
   * @param asset address of the token to be added
   * @param storageSlots array of storage positions of the balance mapping
   */
  event VotingAssetAdd(address indexed asset, uint128[] storageSlots);

  /**
   * @notice method to get the AAVE token address
   * @return AAVE token contract address
   */
  function AAVE() external view returns (address);

  /**
   * @notice method to get the A_AAVE token address
   * @return A_AAVE token contract address
   */
  function A_AAVE() external view returns (address);

  /**
   * @notice method to get the stkAAVE token address
   * @return stkAAVE token contract address
   */
  function STK_AAVE() external view returns (address);

  /**
   * @notice method to get the slot of the balance of the AAVE and stkAAVE
   * @return AAVE and stkAAVE base balance slot
   */
  function BASE_BALANCE_SLOT() external view returns (uint128);

  /**
   * @notice method to get the slot of the balance of the AAVE aToken
   * @return AAVE aToken base balance slot
   */
  function A_AAVE_BASE_BALANCE_SLOT() external view returns (uint128);

  /**
   * @notice method to get the slot of the AAVE aToken delegation state
   * @return AAVE aToken delegation state slot
   */
  function A_AAVE_DELEGATED_STATE_SLOT() external view returns (uint128);

  /**
   * @notice method to check if a token and slot combination is accepted
   * @param token address of the token to check
   * @param slot number of the token slot
   * @return flag indicating if the token slot is accepted
   */
  function isTokenSlotAccepted(
    address token,
    uint128 slot
  ) external view returns (bool);

  /**
   * @notice method to get the addresses of the assets that can be used for voting
   * @return list of addresses of assets
   */
  function getVotingAssetList() external view returns (address[] memory);

  /**
   * @notice method to get the configuration for voting of an asset
   * @param asset address of the asset to get the configuration from
   * @return object with the asset configuration containing the list of storage slots
   */
  function getVotingAssetConfig(
    address asset
  ) external view returns (VotingAssetConfig memory);
}

File 14 of 32 : SlotUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library SlotUtils {
  /**
   * @notice method to calculate the slot hash of the a mapping indexed by account
   * @param account address of the balance holder
   * @param balanceMappingPosition base position of the storage slot of the balance on a token contract
   * @return the slot hash
   */
  function getAccountSlotHash(
    address account,
    uint256 balanceMappingPosition
  ) internal pure returns (bytes32) {
    return
      keccak256(
        abi.encodePacked(
          bytes32(uint256(uint160(account))),
          balanceMappingPosition
        )
      );
  }

  /**
   * @notice method to calculate the slot hash of the a mapping indexed by voter and chainId
   * @param voter address of the voter
   * @param chainId id of the chain of the votingMachine
   * @param representativesMappingPosition base position of the storage slot of the representatives on governance contract
   * @return the slot hash
   * @dev mapping(address => mapping(uint256 => address))
   */
  function getRepresentativeSlotHash(
    address voter,
    uint256 chainId,
    uint256 representativesMappingPosition
  ) internal pure returns (bytes32) {
    bytes32 voterMappingIndex = keccak256(
      abi.encodePacked(
        bytes32(uint256(uint160(voter))),
        representativesMappingPosition
      )
    );

    return
      keccak256(abi.encodePacked(bytes32(chainId), uint256(voterMappingIndex)));
  }
}

File 15 of 32 : EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.19;

import {ECDSA} from "./ECDSA.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * _Available since v3.4._
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

    bytes32 private constant _TYPE_HASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev See {IERC-5267}.
     *
     * _Available since v4.9._
     */
    function eip712Domain()
        public
        view
        virtual
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _EIP712Name(),
            _EIP712Version(),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }

    /**
     * @dev The name parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _name which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     *
     * _Available since v5.0._
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Name() internal view returns (string memory) {
        return _name.toStringWithFallback(_nameFallback);
    }

    /**
     * @dev The version parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _version which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     *
     * _Available since v5.0._
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Version() internal view returns (string memory) {
        return _version.toStringWithFallback(_versionFallback);
    }
}

File 16 of 32 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.19;

import {Strings} from "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            uint8 v = uint8((uint256(vs) >> 255) + 27);
            return tryRecover(hash, v, r, s);
        }
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS, s);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32")
            mstore(0x1c, hash)
            message := keccak256(0x00, 0x3c)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }
}

File 17 of 32 : ICrossChainForwarder.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import {Transaction, Envelope} from '../libs/EncodingUtils.sol';

/**
 * @title ICrossChainForwarder
 * @author BGD Labs
 * @notice interface containing the objects, events and methods definitions of the CrossChainForwarder contract
 */
interface ICrossChainForwarder {
  /**
   * @notice object storing the connected pair of bridge adapters, on current and destination chain
   * @param destinationBridgeAdapter address of the bridge adapter on the destination chain
   * @param currentChainBridgeAdapter address of the bridge adapter deployed on current network
   */
  struct ChainIdBridgeConfig {
    address destinationBridgeAdapter;
    address currentChainBridgeAdapter;
  }

  /**
   * @notice object with the necessary information to remove bridge adapters
   * @param bridgeAdapter address of the bridge adapter to remove
   * @param chainIds array of chain ids where the bridge adapter connects
   */
  struct BridgeAdapterToDisable {
    address bridgeAdapter;
    uint256[] chainIds;
  }

  /**
   * @notice object storing the pair bridgeAdapter (current deployed chain) destination chain bridge adapter configuration
   * @param currentChainBridgeAdapter address of the bridge adapter deployed on current chain
   * @param destinationBridgeAdapter address of the bridge adapter on the destination chain
   * @param destinationChainId id of the destination chain using our own nomenclature
   */
  struct ForwarderBridgeAdapterConfigInput {
    address currentChainBridgeAdapter;
    address destinationBridgeAdapter;
    uint256 destinationChainId;
  }

  /**
   * @notice emitted when a transaction is successfully forwarded through a bridge adapter
   * @param envelopeId internal id of the envelope
   * @param envelope the Envelope type data
   */
  event EnvelopeRegistered(bytes32 indexed envelopeId, Envelope envelope);

  /**
   * @notice emitted when a transaction forwarding is attempted through a bridge adapter
   * @param transactionId id of the forwarded transaction
   * @param envelopeId internal id of the envelope
   * @param encodedTransaction object intended to be bridged
   * @param destinationChainId id of the destination chain in our notation
   * @param bridgeAdapter address of the bridge adapter that failed (deployed on current network)
   * @param destinationBridgeAdapter address of the connected bridge adapter on destination chain
   * @param adapterSuccessful adapter was able to forward the message
   * @param returnData bytes with error information
   */
  event TransactionForwardingAttempted(
    bytes32 transactionId,
    bytes32 indexed envelopeId,
    bytes encodedTransaction,
    uint256 destinationChainId,
    address indexed bridgeAdapter,
    address destinationBridgeAdapter,
    bool indexed adapterSuccessful,
    bytes returnData
  );

  /**
   * @notice emitted when a bridge adapter has been added to the allowed list
   * @param destinationChainId id of the destination chain in our notation
   * @param bridgeAdapter address of the bridge adapter added (deployed on current network)
   * @param destinationBridgeAdapter address of the connected bridge adapter on destination chain
   * @param allowed boolean indicating if the bridge adapter is allowed or disallowed
   */
  event BridgeAdapterUpdated(
    uint256 indexed destinationChainId,
    address indexed bridgeAdapter,
    address destinationBridgeAdapter,
    bool indexed allowed
  );

  /**
   * @notice emitted when a sender has been updated
   * @param sender address of the updated sender
   * @param isApproved boolean that indicates if the sender has been approved or removed
   */
  event SenderUpdated(address indexed sender, bool indexed isApproved);

  /**
   * @notice method to get the current valid envelope nonce
   * @return the current valid envelope nonce
   */
  function getCurrentEnvelopeNonce() external view returns (uint256);

  /**
   * @notice method to get the current valid transaction nonce
   * @return the current valid transaction nonce
   */
  function getCurrentTransactionNonce() external view returns (uint256);

  /**
   * @notice method to check if a envelope has been previously forwarded.
   * @param envelope the Envelope type data
   * @return boolean indicating if the envelope has been registered
   */
  function isEnvelopeRegistered(Envelope memory envelope) external view returns (bool);

  /**
   * @notice method to check if a envelope has been previously forwarded.
   * @param envelopeId the hashed id of the envelope
   * @return boolean indicating if the envelope has been registered
   */
  function isEnvelopeRegistered(bytes32 envelopeId) external view returns (bool);

  /**
   * @notice method to get if a transaction has been forwarded
   * @param transaction the Transaction type data
   * @return flag indicating if a transaction has been forwarded
   */
  function isTransactionForwarded(Transaction memory transaction) external view returns (bool);

  /**
   * @notice method to get if a transaction has been forwarded
   * @param transactionId hashed id of the transaction
   * @return flag indicating if a transaction has been forwarded
   */
  function isTransactionForwarded(bytes32 transactionId) external view returns (bool);

  /**
   * @notice method called to initiate message forwarding to other networks.
   * @param destinationChainId id of the destination chain where the message needs to be bridged
   * @param destination address where the message is intended for
   * @param gasLimit gas cost on receiving side of the message
   * @param message bytes that need to be bridged
   * @return internal id of the envelope and transaction
   */
  function forwardMessage(
    uint256 destinationChainId,
    address destination,
    uint256 gasLimit,
    bytes memory message
  ) external returns (bytes32, bytes32);

  /**
   * @notice method called to re forward a previously sent envelope.
   * @param envelope the Envelope type data
   * @param gasLimit gas cost on receiving side of the message
   * @return the transaction id that has the retried envelope
   * @dev This method will send an existing Envelope using a new Transaction.
   * @dev This method should be used when the intention is to send the Envelope as if it was a new message. This way on
          the Receiver side it will start from 0 to count for the required confirmations. (usual use case would be for
          when an envelope has been invalidated on Receiver side, and needs to be retried as a new message)
   */
  function retryEnvelope(Envelope memory envelope, uint256 gasLimit) external returns (bytes32);

  /**
   * @notice method to retry forwarding an already forwarded transaction
   * @param encodedTransaction the encoded Transaction data
   * @param gasLimit limit of gas to spend on forwarding per bridge
   * @param bridgeAdaptersToRetry list of bridge adapters to be used for the transaction forwarding retry
   * @dev This method will send an existing Transaction with its Envelope to the specified adapters.
   * @dev Should be used when some of the bridges on the initial forwarding did not work (out of gas),
          and we want the Transaction with Envelope to still account for the required confirmations on the Receiver side
   */
  function retryTransaction(
    bytes memory encodedTransaction,
    uint256 gasLimit,
    address[] memory bridgeAdaptersToRetry
  ) external;

  /**
   * @notice method to enable bridge adapters
   * @param bridgeAdapters array of new bridge adapter configurations
   */
  function enableBridgeAdapters(ForwarderBridgeAdapterConfigInput[] memory bridgeAdapters) external;

  /**
   * @notice method to disable bridge adapters
   * @param bridgeAdapters array of bridge adapter addresses to disable
   */
  function disableBridgeAdapters(BridgeAdapterToDisable[] memory bridgeAdapters) external;

  /**
   * @notice method to remove sender addresses
   * @param senders list of addresses to remove
   */
  function removeSenders(address[] memory senders) external;

  /**
   * @notice method to approve new sender addresses
   * @param senders list of addresses to approve
   */
  function approveSenders(address[] memory senders) external;

  /**
   * @notice method to get all the forwarder bridge adapters of a chain
   * @param chainId id of the chain we want to get the adapters from
   * @return an array of chain configurations where the bridge adapter can communicate
   */
  function getForwarderBridgeAdaptersByChain(
    uint256 chainId
  ) external view returns (ChainIdBridgeConfig[] memory);

  /**
   * @notice method to get if a sender is approved
   * @param sender address that we want to check if approved
   * @return boolean indicating if the address has been approved as sender
   */
  function isSenderApproved(address sender) external view returns (bool);
}

File 18 of 32 : ICrossChainReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import {EnumerableSet} from 'openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol';
import {Transaction, Envelope} from '../libs/EncodingUtils.sol';

/**
 * @title ICrossChainReceiver
 * @author BGD Labs
 * @notice interface containing the objects, events and methods definitions of the CrossChainReceiver contract
 */
interface ICrossChainReceiver {
  /**
   * @notice object with information to set new required confirmations
   * @param chainId id of the origin chain
   * @param requiredConfirmations required confirmations to set a message as confirmed
   */
  struct ConfirmationInput {
    uint256 chainId;
    uint8 requiredConfirmations;
  }

  /**
   * @notice object with information to set new validity timestamp
   * @param chainId id of the origin chain
   * @param validityTimestamp new timestamp in seconds to set as validity point
   */
  struct ValidityTimestampInput {
    uint256 chainId;
    uint120 validityTimestamp;
  }

  /**
   * @notice object with necessary information to configure bridge adapters
   * @param bridgeAdapter address of the bridge adapter to configure
   * @param chainIds array of ids of the chains the adapter receives messages from
   */
  struct ReceiverBridgeAdapterConfigInput {
    address bridgeAdapter;
    uint256[] chainIds;
  }

  /**
   * @notice object containing the receiver configuration
   * @param requiredConfirmation number of bridges that are needed to make a bridged message valid from origin chain
   * @param validityTimestamp all messages originated but not finally confirmed before this timestamp per origin chain, are invalid
   */
  struct ReceiverConfiguration {
    uint8 requiredConfirmation;
    uint120 validityTimestamp;
  }

  /**
   * @notice object with full information of the receiver configuration for a chain
   * @param configuration object containing the specifications of the receiver for a chain
   * @param allowedBridgeAdapters stores if a bridge adapter is allowed for a chain
   */
  struct ReceiverConfigurationFull {
    ReceiverConfiguration configuration;
    EnumerableSet.AddressSet allowedBridgeAdapters;
  }

  /**
   * @notice object that stores the internal information of the transaction
   * @param confirmations number of times that this transaction has been bridged
   * @param firstBridgedAt timestamp in seconds indicating the first time a transaction was received
   */
  struct TransactionStateWithoutAdapters {
    uint8 confirmations;
    uint120 firstBridgedAt;
  }
  /**
   * @notice object that stores the internal information of the transaction with bridge adapters state
   * @param confirmations number of times that this transactions has been bridged
   * @param firstBridgedAt timestamp in seconds indicating the first time a transaction was received
   * @param bridgedByAdapter list of bridge adapters that have bridged the message
   */
  struct TransactionState {
    uint8 confirmations;
    uint120 firstBridgedAt;
    mapping(address => bool) bridgedByAdapter;
  }

  /**
   * @notice object with the current state of an envelope
   * @param confirmed boolean indicating if the bridged message has been confirmed by the infrastructure
   * @param delivered boolean indicating if the bridged message has been delivered to the destination
   */
  enum EnvelopeState {
    None,
    Confirmed,
    Delivered
  }

  /**
   * @notice emitted when a transaction has been received successfully
   * @param transactionId id of the transaction
   * @param envelopeId id of the envelope
   * @param originChainId id of the chain where the envelope originated
   * @param transaction the Transaction type data
   * @param bridgeAdapter address of the bridge adapter who received the message (deployed on current network)
   * @param confirmations number of current confirmations for this message
   */
  event TransactionReceived(
    bytes32 transactionId,
    bytes32 indexed envelopeId,
    uint256 indexed originChainId,
    Transaction transaction,
    address indexed bridgeAdapter,
    uint8 confirmations
  );

  /**
   * @notice emitted when an envelope has been delivery attempted
   * @param envelopeId id of the envelope
   * @param envelope the Envelope type data
   * @param isDelivered flag indicating if the message has been delivered successfully
   */
  event EnvelopeDeliveryAttempted(bytes32 envelopeId, Envelope envelope, bool isDelivered);

  /**
   * @notice emitted when a bridge adapter gets updated (allowed or disallowed)
   * @param bridgeAdapter address of the updated bridge adapter
   * @param allowed boolean indicating if the bridge adapter has been allowed or disallowed
   * @param chainId id of the chain updated
   */
  event ReceiverBridgeAdaptersUpdated(
    address indexed bridgeAdapter,
    bool indexed allowed,
    uint256 indexed chainId
  );

  /**
   * @notice emitted when number of confirmations needed to validate a message changes
   * @param newConfirmations number of new confirmations needed for a message to be valid
   * @param chainId id of the chain updated
   */
  event ConfirmationsUpdated(uint8 newConfirmations, uint256 indexed chainId);

  /**
   * @notice emitted when a new timestamp for invalidations gets set
   * @param invalidTimestamp timestamp to invalidate previous messages
   * @param chainId id of the chain updated
   */
  event NewInvalidation(uint256 invalidTimestamp, uint256 indexed chainId);

  /**
   * @notice method to get the current allowed receiver bridge adapters for a chain
   * @param chainId id of the chain to get the allowed bridge adapter list
   * @return the list of allowed bridge adapters
   */
  function getReceiverBridgeAdaptersByChain(
    uint256 chainId
  ) external view returns (address[] memory);

  /**
   * @notice method to get the current supported chains (at least one allowed bridge adapter)
   * @return list of supported chains
   */
  function getSupportedChains() external view returns (uint256[] memory);

  /**
   * @notice method to get the current configuration of a chain
   * @param chainId id of the chain to get the configuration from
   * @return the specified chain configuration object
   */
  function getConfigurationByChain(
    uint256 chainId
  ) external view returns (ReceiverConfiguration memory);

  /**
   * @notice method to get if a bridge adapter is allowed
   * @param bridgeAdapter address of the bridge adapter to check
   * @param chainId id of the chain to check
   * @return boolean indicating if bridge adapter is allowed
   */
  function isReceiverBridgeAdapterAllowed(
    address bridgeAdapter,
    uint256 chainId
  ) external view returns (bool);

  /**
   * @notice  method to get the current state of a transaction
   * @param transactionId the id of transaction
   * @return number of confirmations of internal message identified by the transactionId and the updated timestamp
   */
  function getTransactionState(
    bytes32 transactionId
  ) external view returns (TransactionStateWithoutAdapters memory);

  /**
   * @notice  method to get the internal transaction information
   * @param transaction Transaction type data
   * @return number of confirmations of internal message identified by internalId and the updated timestamp
   */
  function getTransactionState(
    Transaction memory transaction
  ) external view returns (TransactionStateWithoutAdapters memory);

  /**
   * @notice method to get the internal state of an envelope
   * @param envelope the Envelope type data
   * @return the envelope current state, containing if it has been confirmed and delivered
   */
  function getEnvelopeState(Envelope memory envelope) external view returns (EnvelopeState);

  /**
   * @notice method to get the internal state of an envelope
   * @param envelopeId id of the envelope
   * @return the envelope current state, containing if it has been confirmed and delivered
   */
  function getEnvelopeState(bytes32 envelopeId) external view returns (EnvelopeState);

  /**
   * @notice method to get if transaction has been received by bridge adapter
   * @param transactionId id of the transaction as stored internally
   * @param bridgeAdapter address of the bridge adapter to check if it has bridged the message
   * @return boolean indicating if the message has been received
   */
  function isTransactionReceivedByAdapter(
    bytes32 transactionId,
    address bridgeAdapter
  ) external view returns (bool);

  /**
   * @notice method to set a new timestamp from where the messages will be valid.
   * @param newValidityTimestamp array of objects containing the chain and timestamp where all the previous unconfirmed
            messages must be invalidated.
   */
  function updateMessagesValidityTimestamp(
    ValidityTimestampInput[] memory newValidityTimestamp
  ) external;

  /**
   * @notice method to update the number of confirmations necessary for the messages to be accepted as valid
   * @param newConfirmations array of objects with the chainId and the new number of needed confirmations
   */
  function updateConfirmations(ConfirmationInput[] memory newConfirmations) external;

  /**
   * @notice method that receives a bridged transaction and tries to deliver the contents to destination if possible
   * @param encodedTransaction bytes containing the bridged information
   * @param originChainId id of the chain where the transaction originated
   */
  function receiveCrossChainMessage(
    bytes memory encodedTransaction,
    uint256 originChainId
  ) external;

  /**
   * @notice method to deliver an envelope to its destination
   * @param envelope the Envelope typed data
   * @dev to deliver an envelope, it needs to have been previously confirmed and not delivered
   */
  function deliverEnvelope(Envelope memory envelope) external;

  /**
   * @notice method to add bridge adapters to the allowed list
   * @param bridgeAdaptersInput array of objects with the new bridge adapters and supported chains
   */
  function allowReceiverBridgeAdapters(
    ReceiverBridgeAdapterConfigInput[] memory bridgeAdaptersInput
  ) external;

  /**
   * @notice method to remove bridge adapters from the allowed list
   * @param bridgeAdaptersInput array of objects with the bridge adapters and supported chains to disallow
   */
  function disallowReceiverBridgeAdapters(
    ReceiverBridgeAdapterConfigInput[] memory bridgeAdaptersInput
  ) external;
}

File 19 of 32 : IRescuable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

/**
 * @title IRescuable
 * @author BGD Labs
 * @notice interface containing the objects, events and methods definitions of the Rescuable contract
 */
interface IRescuable {
  /**
   * @notice emitted when erc20 tokens get rescued
   * @param caller address that triggers the rescue
   * @param token address of the rescued token
   * @param to address that will receive the rescued tokens
   * @param amount quantity of tokens rescued
   */
  event ERC20Rescued(
    address indexed caller,
    address indexed token,
    address indexed to,
    uint256 amount
  );

  /**
   * @notice emitted when native tokens get rescued
   * @param caller address that triggers the rescue
   * @param to address that will receive the rescued tokens
   * @param amount quantity of tokens rescued
   */
  event NativeTokensRescued(address indexed caller, address indexed to, uint256 amount);

  /**
   * @notice method called to rescue tokens sent erroneously to the contract. Only callable by owner
   * @param erc20Token address of the token to rescue
   * @param to address to send the tokens
   * @param amount of tokens to rescue
   */
  function emergencyTokenTransfer(address erc20Token, address to, uint256 amount) external;

  /**
   * @notice method called to rescue ether sent erroneously to the contract. Only callable by owner
   * @param to address to send the eth
   * @param amount of eth to rescue
   */
  function emergencyEtherTransfer(address to, uint256 amount) external;

  /**
   * @notice method that defines the address that is allowed to rescue tokens
   * @return the allowed address
   */
  function whoCanRescue() external view returns (address);
}

File 20 of 32 : IDataWarehouse.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {StateProofVerifier} from '../libs/StateProofVerifier.sol';

/**
 * @title IDataWarehouse
 * @author BGD Labs
 * @notice interface containing the methods definitions of the DataWarehouse contract
 */
interface IDataWarehouse {
  /**
   * @notice event emitted when a storage root has been processed successfully
   * @param caller address that called the processStorageRoot method
   * @param account address where the root is generated
   * @param blockHash hash of the block where the root was generated
   */
  event StorageRootProcessed(
    address indexed caller,
    address indexed account,
    bytes32 indexed blockHash
  );

  /**
   * @notice event emitted when a storage root has been processed successfully
   * @param caller address that called the processStorageSlot method
   * @param account address where the slot is processed
   * @param blockHash hash of the block where the storage proof was generated
   * @param slot storage location to search
   * @param value storage information on the specified location
   */
  event StorageSlotProcessed(
    address indexed caller,
    address indexed account,
    bytes32 indexed blockHash,
    bytes32 slot,
    uint256 value
  );

  /**
   * @notice method to get the storage roots of an account (token) in a certain block hash
   * @param account address of the token to get the storage roots from
   * @param blockHash hash of the block from where the roots are generated
   * @return state root hash of the account on the block hash specified
   */
  function getStorageRoots(
    address account,
    bytes32 blockHash
  ) external view returns (bytes32);

  /**
   * @notice method to process the storage root from an account on a block hash.
   * @param account address of the token to get the storage roots from
   * @param blockHash hash of the block from where the roots are generated
   * @param blockHeaderRLP rlp encoded block header. At same block where the block hash was taken
   * @param accountStateProofRLP rlp encoded account state proof, taken in same block as block hash
   * @return the storage root
   */
  function processStorageRoot(
    address account,
    bytes32 blockHash,
    bytes memory blockHeaderRLP,
    bytes memory accountStateProofRLP
  ) external returns (bytes32);

  /**
   * @notice method to get the storage value at a certain slot and block hash for a certain address
   * @param account address of the token to get the storage roots from
   * @param blockHash hash of the block from where the roots are generated
   * @param slot hash of the explicit storage placement where the value to get is found.
   * @param storageProof generated proof containing the storage, at block hash
   * @return an object containing the slot value at the specified storage slot
   */
  function getStorage(
    address account,
    bytes32 blockHash,
    bytes32 slot,
    bytes memory storageProof
  ) external view returns (StateProofVerifier.SlotValue memory);

  /**
   * @notice method to register the storage value at a certain slot and block hash for a certain address
   * @param account address of the token to get the storage roots from
   * @param blockHash hash of the block from where the roots are generated
   * @param slot hash of the explicit storage placement where the value to get is found.
   * @param storageProof generated proof containing the storage, at block hash
   */
  function processStorageSlot(
    address account,
    bytes32 blockHash,
    bytes32 slot,
    bytes calldata storageProof
  ) external;

  /**
   * @notice method to get the value from storage at a certain block hash, previously registered.
   * @param blockHash hash of the block from where the roots are generated
   * @param account address of the token to get the storage roots from
   * @param slot hash of the explicit storage placement where the value to get is found.
   * @return numeric slot value of the slot. The value must be decoded to get the actual stored information
   */
  function getRegisteredSlot(
    bytes32 blockHash,
    address account,
    bytes32 slot
  ) external view returns (uint256);
}

File 21 of 32 : IVotingStrategy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IDataWarehouse} from './IDataWarehouse.sol';

/**
 * @title IVotingStrategy
 * @author BGD Labs
 * @notice interface containing the methods definitions of the VotingStrategy contract
 */
interface IVotingStrategy {
  /**
   * @notice method to get the DataWarehouse contract
   * @return DataWarehouse contract
   */
  function DATA_WAREHOUSE() external view returns (IDataWarehouse);

  /**
   * @notice method to get the exchange rate precision. Taken from stkTokenV3 contract
   * @return exchange rate precission
   */
  function STK_AAVE_SLASHING_EXCHANGE_RATE_PRECISION()
    external
    view
    returns (uint256);

  /**
   * @notice method to get the slot of the stkAave exchange rate in the stkAave contract
   * @return stkAave exchange rate slot
   */
  function STK_AAVE_SLASHING_EXCHANGE_RATE_SLOT()
    external
    view
    returns (uint256);

  /**
   * @notice method to get the power scale factor of the delegated balances
   * @return power scale factor
   */
  function POWER_SCALE_FACTOR() external view returns (uint256);

  /**
   * @notice method to get the power of an asset
   * @param asset address of the token to get the power
   * @param storageSlot storage position of the balance mapping
   * @param power balance of a determined asset to be used for the vote
   * @param blockHash block hash of when we want to get the power. Optional parameter
   * @return voting power of the specified asset
   */
  function getVotingPower(
    address asset,
    uint128 storageSlot,
    uint256 power,
    bytes32 blockHash
  ) external view returns (uint256);

  /**
   * @notice method to check that the roots for all the tokens in the voting strategy have been registered. Including
             the registry of the stkAave exchange rate slot
   * @param blockHash hash of the block from where the roots have been registered.
   */
  function hasRequiredRoots(bytes32 blockHash) external view;
}

File 22 of 32 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
// From commit https://github.com/OpenZeppelin/openzeppelin-contracts/commit/8b778fa20d6d76340c5fac1ed66c80273f05b95a

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
  function _msgSender() internal view virtual returns (address) {
    return msg.sender;
  }

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

File 23 of 32 : RLPReader.sol
// SPDX-License-Identifier: Apache-2.0

/*
 * @author Hamdi Allam [email protected]
 * Please reach out with any questions or concerns
 * Code copied from: https://github.com/hamdiallam/Solidity-RLP/blob/master/contracts/RLPReader.sol
 */
pragma solidity ^0.8.0;

library RLPReader {
  uint8 constant STRING_SHORT_START = 0x80;
  uint8 constant STRING_LONG_START = 0xb8;
  uint8 constant LIST_SHORT_START = 0xc0;
  uint8 constant LIST_LONG_START = 0xf8;
  uint8 constant WORD_SIZE = 32;

  struct RLPItem {
    uint256 len;
    uint256 memPtr;
  }

  struct Iterator {
    RLPItem item; // Item that's being iterated over.
    uint256 nextPtr; // Position of the next item in the list.
  }

  /*
   * @dev Returns the next element in the iteration. Reverts if it has not next element.
   * @param self The iterator.
   * @return The next element in the iteration.
   */
  function next(Iterator memory self) internal pure returns (RLPItem memory) {
    require(hasNext(self));

    uint256 ptr = self.nextPtr;
    uint256 itemLength = _itemLength(ptr);
    self.nextPtr = ptr + itemLength;

    return RLPItem(itemLength, ptr);
  }

  /*
   * @dev Returns true if the iteration has more elements.
   * @param self The iterator.
   * @return true if the iteration has more elements.
   */
  function hasNext(Iterator memory self) internal pure returns (bool) {
    RLPItem memory item = self.item;
    return self.nextPtr < item.memPtr + item.len;
  }

  /*
   * @param item RLP encoded bytes
   */
  function toRlpItem(bytes memory item) internal pure returns (RLPItem memory) {
    uint256 memPtr;
    assembly {
      memPtr := add(item, 0x20)
    }

    return RLPItem(item.length, memPtr);
  }

  /*
   * @dev Create an iterator. Reverts if item is not a list.
   * @param self The RLP item.
   * @return An 'Iterator' over the item.
   */
  function iterator(
    RLPItem memory self
  ) internal pure returns (Iterator memory) {
    require(isList(self));

    uint256 ptr = self.memPtr + _payloadOffset(self.memPtr);
    return Iterator(self, ptr);
  }

  /*
   * @param the RLP item.
   */
  function rlpLen(RLPItem memory item) internal pure returns (uint256) {
    return item.len;
  }

  /*
   * @param the RLP item.
   * @return (memPtr, len) pair: location of the item's payload in memory.
   */
  function payloadLocation(
    RLPItem memory item
  ) internal pure returns (uint256, uint256) {
    uint256 offset = _payloadOffset(item.memPtr);
    uint256 memPtr = item.memPtr + offset;
    uint256 len = item.len - offset; // data length
    return (memPtr, len);
  }

  /*
   * @param the RLP item.
   */
  function payloadLen(RLPItem memory item) internal pure returns (uint256) {
    (, uint256 len) = payloadLocation(item);
    return len;
  }

  /*
   * @param the RLP item containing the encoded list.
   */
  function toList(
    RLPItem memory item
  ) internal pure returns (RLPItem[] memory) {
    require(isList(item));

    uint256 items = numItems(item);
    RLPItem[] memory result = new RLPItem[](items);

    uint256 memPtr = item.memPtr + _payloadOffset(item.memPtr);
    uint256 dataLen;
    for (uint256 i = 0; i < items; i++) {
      dataLen = _itemLength(memPtr);
      result[i] = RLPItem(dataLen, memPtr);
      memPtr = memPtr + dataLen;
    }

    return result;
  }

  // @return indicator whether encoded payload is a list. negate this function call for isData.
  function isList(RLPItem memory item) internal pure returns (bool) {
    if (item.len == 0) return false;

    uint8 byte0;
    uint256 memPtr = item.memPtr;
    assembly {
      byte0 := byte(0, mload(memPtr))
    }

    if (byte0 < LIST_SHORT_START) return false;
    return true;
  }

  /*
   * @dev A cheaper version of keccak256(toRlpBytes(item)) that avoids copying memory.
   * @return keccak256 hash of RLP encoded bytes.
   */
  function rlpBytesKeccak256(
    RLPItem memory item
  ) internal pure returns (bytes32) {
    uint256 ptr = item.memPtr;
    uint256 len = item.len;
    bytes32 result;
    assembly {
      result := keccak256(ptr, len)
    }
    return result;
  }

  /*
   * @dev A cheaper version of keccak256(toBytes(item)) that avoids copying memory.
   * @return keccak256 hash of the item payload.
   */
  function payloadKeccak256(
    RLPItem memory item
  ) internal pure returns (bytes32) {
    (uint256 memPtr, uint256 len) = payloadLocation(item);
    bytes32 result;
    assembly {
      result := keccak256(memPtr, len)
    }
    return result;
  }

  /** RLPItem conversions into data types **/

  // @returns raw rlp encoding in bytes
  function toRlpBytes(
    RLPItem memory item
  ) internal pure returns (bytes memory) {
    bytes memory result = new bytes(item.len);
    if (result.length == 0) return result;

    uint256 ptr;
    assembly {
      ptr := add(0x20, result)
    }

    copy(item.memPtr, ptr, item.len);
    return result;
  }

  // any non-zero byte except "0x80" is considered true
  function toBoolean(RLPItem memory item) internal pure returns (bool) {
    require(item.len == 1);
    uint256 result;
    uint256 memPtr = item.memPtr;
    assembly {
      result := byte(0, mload(memPtr))
    }

    // SEE Github Issue #5.
    // Summary: Most commonly used RLP libraries (i.e Geth) will encode
    // "0" as "0x80" instead of as "0". We handle this edge case explicitly
    // here.
    if (result == 0 || result == STRING_SHORT_START) {
      return false;
    } else {
      return true;
    }
  }

  function toAddress(RLPItem memory item) internal pure returns (address) {
    // 1 byte for the length prefix
    require(item.len == 21);

    return address(uint160(toUint(item)));
  }

  function toUint(RLPItem memory item) internal pure returns (uint256) {
    require(item.len > 0 && item.len <= 33);

    (uint256 memPtr, uint256 len) = payloadLocation(item);

    uint256 result;
    assembly {
      result := mload(memPtr)

      // shift to the correct location if neccesary
      if lt(len, 32) {
        result := div(result, exp(256, sub(32, len)))
      }
    }

    return result;
  }

  // enforces 32 byte length
  function toUintStrict(RLPItem memory item) internal pure returns (uint256) {
    // one byte prefix
    require(item.len == 33);

    uint256 result;
    uint256 memPtr = item.memPtr + 1;
    assembly {
      result := mload(memPtr)
    }

    return result;
  }

  function toBytes(RLPItem memory item) internal pure returns (bytes memory) {
    require(item.len > 0);

    (uint256 memPtr, uint256 len) = payloadLocation(item);
    bytes memory result = new bytes(len);

    uint256 destPtr;
    assembly {
      destPtr := add(0x20, result)
    }

    copy(memPtr, destPtr, len);
    return result;
  }

  /*
   * Private Helpers
   */

  // @return number of payload items inside an encoded list.
  function numItems(RLPItem memory item) private pure returns (uint256) {
    if (item.len == 0) return 0;

    uint256 count = 0;
    uint256 currPtr = item.memPtr + _payloadOffset(item.memPtr);
    uint256 endPtr = item.memPtr + item.len;
    while (currPtr < endPtr) {
      currPtr = currPtr + _itemLength(currPtr); // skip over an item
      count++;
    }

    return count;
  }

  // @return entire rlp item byte length
  function _itemLength(uint256 memPtr) private pure returns (uint256) {
    uint256 itemLen;
    uint256 byte0;
    assembly {
      byte0 := byte(0, mload(memPtr))
    }

    if (byte0 < STRING_SHORT_START) {
      itemLen = 1;
    } else if (byte0 < STRING_LONG_START) {
      itemLen = byte0 - STRING_SHORT_START + 1;
    } else if (byte0 < LIST_SHORT_START) {
      assembly {
        let byteLen := sub(byte0, 0xb7) // # of bytes the actual length is
        memPtr := add(memPtr, 1) // skip over the first byte

        /* 32 byte word size */
        let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to get the len
        itemLen := add(dataLen, add(byteLen, 1))
      }
    } else if (byte0 < LIST_LONG_START) {
      itemLen = byte0 - LIST_SHORT_START + 1;
    } else {
      assembly {
        let byteLen := sub(byte0, 0xf7)
        memPtr := add(memPtr, 1)

        let dataLen := div(mload(memPtr), exp(256, sub(32, byteLen))) // right shifting to the correct length
        itemLen := add(dataLen, add(byteLen, 1))
      }
    }

    return itemLen;
  }

  // @return number of bytes until the data
  function _payloadOffset(uint256 memPtr) private pure returns (uint256) {
    uint256 byte0;
    assembly {
      byte0 := byte(0, mload(memPtr))
    }

    if (byte0 < STRING_SHORT_START) {
      return 0;
    } else if (
      byte0 < STRING_LONG_START ||
      (byte0 >= LIST_SHORT_START && byte0 < LIST_LONG_START)
    ) {
      return 1;
    } else if (byte0 < LIST_SHORT_START) {
      // being explicit
      return byte0 - (STRING_LONG_START - 1) + 1;
    } else {
      return byte0 - (LIST_LONG_START - 1) + 1;
    }
  }

  /*
   * @param src Pointer to source
   * @param dest Pointer to destination
   * @param len Amount of memory to copy from the source
   */
  function copy(uint256 src, uint256 dest, uint256 len) private pure {
    if (len == 0) return;

    // copy as many word sizes as possible
    for (; len >= WORD_SIZE; len -= WORD_SIZE) {
      assembly {
        mstore(dest, mload(src))
      }

      src += WORD_SIZE;
      dest += WORD_SIZE;
    }

    if (len > 0) {
      // left over bytes. Mask is used to remove unwanted bytes from the word
      uint256 mask = 256 ** (WORD_SIZE - len) - 1;
      assembly {
        let srcpart := and(mload(src), not(mask)) // zero out src
        let destpart := and(mload(dest), mask) // retrieve the bytes
        mstore(dest, or(destpart, srcpart))
      }
    }
  }
}

File 24 of 32 : MerklePatriciaProofVerifier.sol
// SPDX-License-Identifier: MIT

/**
 * Copied from https://github.com/lidofinance/curve-merkle-oracle/blob/main/contracts/MerklePatriciaProofVerifier.sol
 */
pragma solidity ^0.8.0;

import {RLPReader} from './RLPReader.sol';

library MerklePatriciaProofVerifier {
  using RLPReader for RLPReader.RLPItem;
  using RLPReader for bytes;

  /// @dev Validates a Merkle-Patricia-Trie proof.
  ///      If the proof proves the inclusion of some key-value pair in the
  ///      trie, the value is returned. Otherwise, i.e. if the proof proves
  ///      the exclusion of a key from the trie, an empty byte array is
  ///      returned.
  /// @param rootHash is the Keccak-256 hash of the root node of the MPT.
  /// @param path is the key of the node whose inclusion/exclusion we are
  ///        proving.
  /// @param stack is the stack of MPT nodes (starting with the root) that
  ///        need to be traversed during verification.
  /// @return value whose inclusion is proved or an empty byte array for
  ///         a proof of exclusion
  function extractProofValue(
    bytes32 rootHash,
    bytes memory path,
    RLPReader.RLPItem[] memory stack
  ) internal pure returns (bytes memory value) {
    bytes memory mptKey = _decodeNibbles(path, 0);
    uint256 mptKeyOffset = 0;

    bytes32 nodeHashHash;
    RLPReader.RLPItem[] memory node;

    RLPReader.RLPItem memory rlpValue;

    if (stack.length == 0) {
      // Root hash of empty Merkle-Patricia-Trie
      require(
        rootHash ==
          0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
      );
      return new bytes(0);
    }

    // Traverse stack of nodes starting at root.
    for (uint256 i = 0; i < stack.length; i++) {
      // We use the fact that an rlp encoded list consists of some
      // encoding of its length plus the concatenation of its
      // *rlp-encoded* items.

      // The root node is hashed with Keccak-256 ...
      if (i == 0 && rootHash != stack[i].rlpBytesKeccak256()) {
        revert();
      }
      // ... whereas all other nodes are hashed with the MPT
      // hash function.
      if (i != 0 && nodeHashHash != _mptHashHash(stack[i])) {
        revert();
      }
      // We verified that stack[i] has the correct hash, so we
      // may safely decode it.
      node = stack[i].toList();

      if (node.length == 2) {
        // Extension or Leaf node

        bool isLeaf;
        bytes memory nodeKey;
        (isLeaf, nodeKey) = _merklePatriciaCompactDecode(node[0].toBytes());

        uint256 prefixLength = _sharedPrefixLength(
          mptKeyOffset,
          mptKey,
          nodeKey
        );
        mptKeyOffset += prefixLength;

        if (prefixLength < nodeKey.length) {
          // Proof claims divergent extension or leaf. (Only
          // relevant for proofs of exclusion.)
          // An Extension/Leaf node is divergent iff it "skips" over
          // the point at which a Branch node should have been had the
          // excluded key been included in the trie.
          // Example: Imagine a proof of exclusion for path [1, 4],
          // where the current node is a Leaf node with
          // path [1, 3, 3, 7]. For [1, 4] to be included, there
          // should have been a Branch node at [1] with a child
          // at 3 and a child at 4.

          // Sanity check
          if (i < stack.length - 1) {
            // divergent node must come last in proof
            revert();
          }

          return new bytes(0);
        }

        if (isLeaf) {
          // Sanity check
          if (i < stack.length - 1) {
            // leaf node must come last in proof
            revert();
          }

          if (mptKeyOffset < mptKey.length) {
            return new bytes(0);
          }

          rlpValue = node[1];
          return rlpValue.toBytes();
        } else {
          // extension
          // Sanity check
          if (i == stack.length - 1) {
            // shouldn't be at last level
            revert();
          }

          if (!node[1].isList()) {
            // rlp(child) was at least 32 bytes. node[1] contains
            // Keccak256(rlp(child)).
            nodeHashHash = node[1].payloadKeccak256();
          } else {
            // rlp(child) was less than 32 bytes. node[1] contains
            // rlp(child).
            nodeHashHash = node[1].rlpBytesKeccak256();
          }
        }
      } else if (node.length == 17) {
        // Branch node

        if (mptKeyOffset != mptKey.length) {
          // we haven't consumed the entire path, so we need to look at a child
          uint8 nibble = uint8(mptKey[mptKeyOffset]);
          mptKeyOffset += 1;
          if (nibble >= 16) {
            // each element of the path has to be a nibble
            revert();
          }

          if (_isEmptyBytesequence(node[nibble])) {
            // Sanity
            if (i != stack.length - 1) {
              // leaf node should be at last level
              revert();
            }

            return new bytes(0);
          } else if (!node[nibble].isList()) {
            nodeHashHash = node[nibble].payloadKeccak256();
          } else {
            nodeHashHash = node[nibble].rlpBytesKeccak256();
          }
        } else {
          // we have consumed the entire mptKey, so we need to look at what's contained in this node.

          // Sanity
          if (i != stack.length - 1) {
            // should be at last level
            revert();
          }

          return node[16].toBytes();
        }
      }
    }
  }

  /// @dev Computes the hash of the Merkle-Patricia-Trie hash of the RLP item.
  ///      Merkle-Patricia-Tries use a weird "hash function" that outputs
  ///      *variable-length* hashes: If the item is shorter than 32 bytes,
  ///      the MPT hash is the item. Otherwise, the MPT hash is the
  ///      Keccak-256 hash of the item.
  ///      The easiest way to compare variable-length byte sequences is
  ///      to compare their Keccak-256 hashes.
  /// @param item The RLP item to be hashed.
  /// @return Keccak-256(MPT-hash(item))
  function _mptHashHash(
    RLPReader.RLPItem memory item
  ) private pure returns (bytes32) {
    if (item.len < 32) {
      return item.rlpBytesKeccak256();
    } else {
      return keccak256(abi.encodePacked(item.rlpBytesKeccak256()));
    }
  }

  function _isEmptyBytesequence(
    RLPReader.RLPItem memory item
  ) private pure returns (bool) {
    if (item.len != 1) {
      return false;
    }
    uint8 b;
    uint256 memPtr = item.memPtr;
    assembly {
      b := byte(0, mload(memPtr))
    }
    return b == 0x80 /* empty byte string */;
  }

  function _merklePatriciaCompactDecode(
    bytes memory compact
  ) private pure returns (bool isLeaf, bytes memory nibbles) {
    require(compact.length > 0);
    uint256 first_nibble = (uint8(compact[0]) >> 4) & 0xF;
    uint256 skipNibbles;
    if (first_nibble == 0) {
      skipNibbles = 2;
      isLeaf = false;
    } else if (first_nibble == 1) {
      skipNibbles = 1;
      isLeaf = false;
    } else if (first_nibble == 2) {
      skipNibbles = 2;
      isLeaf = true;
    } else if (first_nibble == 3) {
      skipNibbles = 1;
      isLeaf = true;
    } else {
      // Not supposed to happen!
      revert();
    }
    return (isLeaf, _decodeNibbles(compact, skipNibbles));
  }

  function _decodeNibbles(
    bytes memory compact,
    uint256 skipNibbles
  ) private pure returns (bytes memory nibbles) {
    require(compact.length > 0);

    uint256 length = compact.length * 2;
    require(skipNibbles <= length);
    length -= skipNibbles;

    nibbles = new bytes(length);
    uint256 nibblesLength = 0;

    for (uint256 i = skipNibbles; i < skipNibbles + length; i += 1) {
      if (i % 2 == 0) {
        nibbles[nibblesLength] = bytes1((uint8(compact[i / 2]) >> 4) & 0xF);
      } else {
        nibbles[nibblesLength] = bytes1((uint8(compact[i / 2]) >> 0) & 0xF);
      }
      nibblesLength += 1;
    }

    assert(nibblesLength == nibbles.length);
  }

  function _sharedPrefixLength(
    uint256 xsOffset,
    bytes memory xs,
    bytes memory ys
  ) private pure returns (uint256) {
    uint256 i;
    for (i = 0; i + xsOffset < xs.length && i < ys.length; i++) {
      if (xs[i + xsOffset] != ys[i]) {
        return i;
      }
    }
    return i;
  }
}

File 25 of 32 : ShortStrings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol)

pragma solidity ^0.8.19;

import {StorageSlot} from "./StorageSlot.sol";

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(_FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

File 26 of 32 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.19;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

File 27 of 32 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.19;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 28 of 32 : EncodingUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

using EnvelopeUtils for Envelope global;
using TransactionUtils for Transaction global;

/**
 * @notice Object with the necessary information to define a unique envelope
 * @param nonce sequential (unique) numeric indicator of the Envelope creation
 * @param origin address that originated the bridging of a message
 * @param destination address where the message needs to be sent
 * @param originChainId id of the chain where the message originated
 * @param destinationChainId id of the chain where the message needs to be bridged
 * @param message bytes that needs to be bridged
 */
struct Envelope {
  uint256 nonce;
  address origin;
  address destination;
  uint256 originChainId;
  uint256 destinationChainId;
  bytes message;
}

/**
 * @notice Object containing the information of an envelope for internal usage
 * @param data bytes of the encoded envelope
 * @param id hash of the encoded envelope
 */
struct EncodedEnvelope {
  bytes data;
  bytes32 id;
}

/**
 * @title EnvelopeUtils library
 * @author BGD Labs
 * @notice Defines utility functions for Envelopes
 */
library EnvelopeUtils {
  /**
   * @notice method that encodes an Envelope and generates its id
   * @param envelope object with the routing information necessary to send a message to a destination chain
   * @return object containing the encoded envelope and the envelope id
   */
  function encode(Envelope memory envelope) internal pure returns (EncodedEnvelope memory) {
    EncodedEnvelope memory encodedEnvelope;
    encodedEnvelope.data = abi.encode(envelope);
    encodedEnvelope.id = getId(encodedEnvelope.data);
    return encodedEnvelope;
  }

  /**
   * @notice method to decode and encoded envelope to its raw parameters
   * @param envelope bytes with the encoded envelope data
   * @return object with the decoded envelope information
   */
  function decode(bytes memory envelope) internal pure returns (Envelope memory) {
    return abi.decode(envelope, (Envelope));
  }

  /**
   * @notice method to get an envelope's id
   * @param envelope object with the routing information necessary to send a message to a destination chain
   * @return hash id of the envelope
   */
  function getId(Envelope memory envelope) internal pure returns (bytes32) {
    EncodedEnvelope memory encodedEnvelope = encode(envelope);
    return encodedEnvelope.id;
  }

  /**
   * @notice method to get an envelope's id
   * @param envelope bytes with the encoded envelope data
   * @return hash id of the envelope
   */
  function getId(bytes memory envelope) internal pure returns (bytes32) {
    return keccak256(envelope);
  }
}

/**
 * @notice Object with the necessary information to send an envelope to a bridge
 * @param nonce sequential (unique) numeric indicator of the Transaction creation
 * @param encodedEnvelope bytes of an encoded envelope object
 */
struct Transaction {
  uint256 nonce;
  bytes encodedEnvelope;
}

/**
 * @notice Object containing the information of a transaction for internal usage
 * @param data bytes of the encoded transaction
 * @param id hash of the encoded transaction
 */
struct EncodedTransaction {
  bytes data;
  bytes32 id;
}

/**
 * @title TransactionUtils library
 * @author BGD Labs
 * @notice Defines utility functions for Transactions
 */
library TransactionUtils {
  /**
   * @notice method that encodes a Transaction and generates its id
   * @param transaction object with the information necessary to send an envelope to a bridge
   * @return object containing the encoded transaction and the transaction id
   */
  function encode(
    Transaction memory transaction
  ) internal pure returns (EncodedTransaction memory) {
    EncodedTransaction memory encodedTransaction;
    encodedTransaction.data = abi.encode(transaction);
    encodedTransaction.id = getId(encodedTransaction.data);
    return encodedTransaction;
  }

  /**
   * @notice method that decodes an encoded transaction (bytes) into a Transaction object
   * @param transaction encoded transaction object
   * @return object containing the decoded Transaction object
   */
  function decode(bytes memory transaction) internal pure returns (Transaction memory) {
    return abi.decode(transaction, (Transaction));
  }

  /**
   * @notice method to get a transaction id
   * @param transaction object with the information necessary to send an envelope to a bridge
   * @return hash id of the transaction
   */
  function getId(Transaction memory transaction) internal pure returns (bytes32) {
    EncodedTransaction memory encodedTransaction = encode(transaction);
    return encodedTransaction.id;
  }

  /**
   * @notice method to get a transaction id
   * @param transaction encoded transaction object
   * @return hash id of the transaction
   */
  function getId(bytes memory transaction) internal pure returns (bytes32) {
    return keccak256(transaction);
  }

  /**
   * @notice method to get the envelope information from the transaction object
   * @param transaction object with the information necessary to send an envelope to a bridge
   * @return object with decoded information of the envelope in the transaction
   */
  function getEnvelope(Transaction memory transaction) internal pure returns (Envelope memory) {
    return EnvelopeUtils.decode(transaction.encodedEnvelope);
  }

  /**
   * @notice method to get the envelope id from the transaction object
   * @param transaction object with the information necessary to send an envelope to a bridge
   * @return hash id of the envelope on a transaction
   */
  function getEnvelopeId(Transaction memory transaction) internal pure returns (bytes32) {
    return EnvelopeUtils.getId(transaction.encodedEnvelope);
  }
}

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

pragma solidity ^0.8.19;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 30 of 32 : StorageSlot.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.19;

/**
 * @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(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlot {
    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
        }
    }
}

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

pragma solidity ^0.8.19;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v5.0._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v5.0._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

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

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

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 32 of 32 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.19;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

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

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

Settings
{
  "remappings": [
    "solidity-utils/=lib/solidity-utils/src/",
    "aave-crosschain-infra/=lib/aave-crosschain-infra/src/",
    "aave-token-v3/=lib/aave-token-v3/src/",
    "@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core/",
    "@aave/periphery-v3/=lib/aave-address-book/lib/aave-v3-periphery/",
    "@openzeppelin/=lib/aave-crosschain-infra/lib/openzeppelin-contracts/",
    "aave-address-book/=lib/aave-address-book/src/",
    "aave-token-v2/=lib/aave-token-v3/lib/aave-token-v2/contracts/",
    "aave-v3-core/=lib/aave-address-book/lib/aave-v3-core/",
    "aave-v3-periphery/=lib/aave-address-book/lib/aave-v3-periphery/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "hyperlane-monorepo/=lib/aave-crosschain-infra/lib/hyperlane-monorepo/",
    "nitro-contracts/=lib/aave-crosschain-infra/lib/nitro-contracts/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "solidity-examples/=lib/aave-crosschain-infra/lib/solidity-examples/contracts/",
    "aave-crosschain-infra-scripts/=lib/aave-crosschain-infra/scripts/",
    "@handlers/=lib/aave-delivery-infrastructure/lib/fx-portal/test/handlers/",
    "@mock/=lib/aave-delivery-infrastructure/lib/fx-portal/test/mock/",
    "@utils/=lib/aave-delivery-infrastructure/lib/fx-portal/test/utils/",
    "aave-delivery-infrastructure/=lib/aave-delivery-infrastructure/",
    "fx-portal/=lib/aave-delivery-infrastructure/lib/fx-portal/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"crossChainController","type":"address"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"uint256","name":"l1VotingPortalChainId","type":"uint256"},{"internalType":"contract IVotingStrategy","name":"votingStrategy","type":"address"},{"internalType":"address","name":"l1VotingPortal","type":"address"},{"internalType":"address","name":"governance","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"gasLimit","type":"uint256"}],"name":"GasLimitUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"originSender","type":"address"},{"indexed":true,"internalType":"uint256","name":"originChainId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"reason","type":"bytes"}],"name":"IncorrectTypeMessageReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"originSender","type":"address"},{"indexed":true,"internalType":"uint256","name":"originChainId","type":"uint256"},{"indexed":true,"internalType":"bool","name":"delivered","type":"bool"},{"indexed":false,"internalType":"enum IVotingPortal.MessageType","name":"messageType","type":"uint8"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"reason","type":"bytes"}],"name":"MessageReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"proposalId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"forVotes","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"againstVotes","type":"uint256"}],"name":"ProposalResultsSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"proposalId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"blockHash","type":"bytes32"},{"indexed":false,"internalType":"uint24","name":"votingDuration","type":"uint24"},{"indexed":true,"internalType":"bool","name":"voteCreated","type":"bool"}],"name":"ProposalVoteConfigurationBridged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"proposalId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"l1BlockHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"ProposalVoteStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"proposalId","type":"uint256"},{"indexed":true,"internalType":"address","name":"voter","type":"address"},{"indexed":true,"internalType":"bool","name":"support","type":"bool"},{"indexed":false,"internalType":"uint256","name":"votingPower","type":"uint256"}],"name":"VoteEmitted","type":"event"},{"inputs":[],"name":"CROSS_CHAIN_CONTROLLER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DATA_WAREHOUSE","outputs":[{"internalType":"contract IDataWarehouse","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GOVERNANCE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"L1_VOTING_PORTAL","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"L1_VOTING_PORTAL_CHAIN_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REPRESENTATIVES_SLOT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VOTE_SUBMITTED_BY_REPRESENTATIVE_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VOTE_SUBMITTED_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VOTING_ASSET_WITH_SLOT_RAW","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VOTING_ASSET_WITH_SLOT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VOTING_STRATEGY","outputs":[{"internalType":"contract IVotingStrategy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"closeAndSendVote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"message","type":"bytes"}],"name":"decodeMessage","outputs":[{"internalType":"enum IVotingPortal.MessageType","name":"","type":"uint8"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"message","type":"bytes"}],"name":"decodeProposalMessage","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"message","type":"bytes"}],"name":"decodeVoteMessage","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"bool","name":"","type":"bool"},{"components":[{"internalType":"address","name":"underlyingAsset","type":"address"},{"internalType":"uint128","name":"slot","type":"uint128"}],"internalType":"struct IVotingMachineWithProofs.VotingAssetWithSlot[]","name":"","type":"tuple[]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGasLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"getProposalById","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"bool","name":"sentToGovernance","type":"bool"},{"internalType":"uint40","name":"startTime","type":"uint40"},{"internalType":"uint40","name":"endTime","type":"uint40"},{"internalType":"uint40","name":"votingClosedAndSentTimestamp","type":"uint40"},{"internalType":"uint128","name":"forVotes","type":"uint128"},{"internalType":"uint128","name":"againstVotes","type":"uint128"},{"internalType":"uint256","name":"creationBlockNumber","type":"uint256"},{"internalType":"uint256","name":"votingClosedAndSentBlockNumber","type":"uint256"}],"internalType":"struct IVotingMachineWithProofs.ProposalWithoutVotes","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"getProposalState","outputs":[{"internalType":"enum IVotingMachineWithProofs.ProposalState","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"getProposalVoteConfiguration","outputs":[{"components":[{"internalType":"uint24","name":"votingDuration","type":"uint24"},{"internalType":"bytes32","name":"l1ProposalBlockHash","type":"bytes32"}],"internalType":"struct IVotingMachineWithProofs.ProposalVoteConfiguration","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"skip","type":"uint256"},{"internalType":"uint256","name":"size","type":"uint256"}],"name":"getProposalsVoteConfigurationIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"getUserProposalVote","outputs":[{"components":[{"internalType":"bool","name":"support","type":"bool"},{"internalType":"uint248","name":"votingPower","type":"uint248"}],"internalType":"struct IVotingMachineWithProofs.Vote","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"originSender","type":"address"},{"internalType":"uint256","name":"originChainId","type":"uint256"},{"internalType":"bytes","name":"messageWithType","type":"bytes"}],"name":"receiveCrossChainMessage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"}],"name":"startProposalVote","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"},{"internalType":"bool","name":"support","type":"bool"},{"components":[{"internalType":"address","name":"underlyingAsset","type":"address"},{"internalType":"uint128","name":"slot","type":"uint128"},{"internalType":"bytes","name":"proof","type":"bytes"}],"internalType":"struct IVotingMachineWithProofs.VotingBalanceProof[]","name":"votingBalanceProofs","type":"tuple[]"}],"name":"submitVote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"},{"internalType":"bool","name":"support","type":"bool"},{"internalType":"address","name":"voter","type":"address"},{"internalType":"bytes","name":"proofOfRepresentation","type":"bytes"},{"components":[{"internalType":"address","name":"underlyingAsset","type":"address"},{"internalType":"uint128","name":"slot","type":"uint128"},{"internalType":"bytes","name":"proof","type":"bytes"}],"internalType":"struct IVotingMachineWithProofs.VotingBalanceProof[]","name":"votingBalanceProofs","type":"tuple[]"}],"name":"submitVoteAsRepresentative","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"},{"internalType":"address","name":"voter","type":"address"},{"internalType":"address","name":"representative","type":"address"},{"internalType":"bool","name":"support","type":"bool"},{"internalType":"bytes","name":"proofOfRepresentation","type":"bytes"},{"components":[{"internalType":"address","name":"underlyingAsset","type":"address"},{"internalType":"uint128","name":"slot","type":"uint128"},{"internalType":"bytes","name":"proof","type":"bytes"}],"internalType":"struct IVotingMachineWithProofs.VotingBalanceProof[]","name":"votingBalanceProofs","type":"tuple[]"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct IVotingMachineWithProofs.SignatureParams","name":"signatureParams","type":"tuple"}],"name":"submitVoteAsRepresentativeBySignature","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"},{"internalType":"address","name":"voter","type":"address"},{"internalType":"bool","name":"support","type":"bool"},{"components":[{"internalType":"address","name":"underlyingAsset","type":"address"},{"internalType":"uint128","name":"slot","type":"uint128"},{"internalType":"bytes","name":"proof","type":"bytes"}],"internalType":"struct IVotingMachineWithProofs.VotingBalanceProof[]","name":"votingBalanceProofs","type":"tuple[]"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"submitVoteBySignature","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"gasLimit","type":"uint256"}],"name":"updateGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"}]

6102206040523480156200001257600080fd5b50604051620040f7380380620040f7833981016040819052620000359162000473565b82816040518060400160405280601381526020017f4161766520566f74696e67204d616368696e650000000000000000000000000081525060405180604001604052806002815260200161563160f01b8152506200009e6000836200035960201b90919060201c565b61012052620000af81600162000359565b61014052815160208084019190912060e052815190820120610100524660a0526200013d60e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60805250503060c052620001513362000392565b6040805180820190915260028152611b9960f11b60208201526001600160a01b0383166200019d5760405162461bcd60e51b8152600401620001949190620004f0565b60405180910390fd5b50604080518082019091526002815261393760f01b60208201526001600160a01b038216620001e15760405162461bcd60e51b8152600401620001949190620004f0565b506001600160a01b03821661016081905260408051636f35e84160e11b8152905163de6bd082916004808201926020929091908290030181865afa1580156200022e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000254919062000540565b6001600160a01b03908116610180529081166101a052604080518082019091526002815261363960f01b602082015291508716620002a75760405162461bcd60e51b8152600401620001949190620004f0565b50604080518082019091526002815261373160f01b602082015284620002e25760405162461bcd60e51b8152600401620001949190620004f0565b50604080518082019091526002815261070760f31b60208201526001600160a01b038316620003265760405162461bcd60e51b8152600401620001949190620004f0565b506001600160a01b038087166101c0526101e08590528216610200526200034d85620003e4565b505050505050620006fd565b60006020835110156200037957620003718362000417565b90506200038c565b816200038684826200060c565b5060ff90505b92915050565b600280546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600681905560405181907f3d1394ba0f6fca9c1e344f10a3efe1bfca63bc591232bb0d76755690f409450c90600090a250565b600080829050601f8151111562000445578260405163305a27a960e01b8152600401620001949190620004f0565b80516200045282620006d8565b179392505050565b6001600160a01b03811681146200047057600080fd5b50565b60008060008060008060c087890312156200048d57600080fd5b86516200049a816200045a565b8096505060208701519450604087015193506060870151620004bc816200045a565b6080880151909350620004cf816200045a565b60a0880151909250620004e2816200045a565b809150509295509295509295565b600060208083528351808285015260005b818110156200051f5785810183015185820160400152820162000501565b506000604082860101526040601f19601f8301168501019250505092915050565b6000602082840312156200055357600080fd5b815162000560816200045a565b9392505050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200059257607f821691505b602082108103620005b357634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200060757600081815260208120601f850160051c81016020861015620005e25750805b601f850160051c820191505b818110156200060357828155600101620005ee565b5050505b505050565b81516001600160401b0381111562000628576200062862000567565b62000640816200063984546200057d565b84620005b9565b602080601f8311600181146200067857600084156200065f5750858301515b600019600386901b1c1916600185901b17855562000603565b600085815260208120601f198616915b82811015620006a95788860151825594840194600190910190840162000688565b5085821015620006c85787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b80516020808301519190811015620005b35760001960209190910360031b1b16919050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e05161020051613902620007f5600039600081816104c2015281816107d1015261230a0152600081816105560152818161080e01526122e80152600081816105b3015281816107a701526122b301526000818161028101528181612394015261255b0152600081816105f501528181611ca9015281816123c6015261252e01526000818161040b015281816110970152611e66015260006121e4015260006121b7015260006119820152600061195a015260006118b5015260006118df0152600061190901526139026000f3fe608060405234801561001057600080fd5b50600436106102065760003560e01c80639a39ada31161011a578063c4956366116100ad578063f2709a5c1161007c578063f2709a5c14610617578063f2fde38b14610688578063f4b7223b1461069b578063f687d12a146106bb578063fd1bd2e9146106ce57600080fd5b8063c4956366146105ae578063d53d9b10146105d5578063dbb8f60a146105dd578063de6bd082146105f057600080fd5b8063aa1da0d2116100e9578063aa1da0d214610549578063b34a5e6b14610551578063b6b0f0e014610578578063bc5ee6a81461058b57600080fd5b80639a39ada3146104bd578063a3f4df7e146104e4578063a69d4b2814610523578063a7f8451c1461053657600080fd5b80633be191df1161019d57806384b0196e1161016c57806384b0196e14610456578063867b96c21461047157806389aa5905146104845780638da5cb5b1461048c5780639080936f1461049d57600080fd5b80633be191df146103f35780634916963e14610406578063634d45b21461042d578063715018a61461044e57600080fd5b806315034cba116101d957806315034cba146102d15780631a93d1c3146102e65780633644e515146102ee5780633656de21146102f657600080fd5b80630def04021461020b578063129c5b9614610249578063146278341461027c578063147c11ea146102bb575b600080fd5b61021e6102193660046129f3565b6106d6565b604080518251151581526020928301516001600160f81b031692810192909252015b60405180910390f35b61025c610257366004612b2c565b610734565b60408051938452602084019290925262ffffff1690820152606001610240565b6102a37f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610240565b6102c361075a565b604051908152602001610240565b6102e46102df366004612b68565b61079c565b005b6006546102c3565b6102c3610b14565b6103e6610304366004612bc0565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915250600081815260036020818152604092839020835161012081018552948552600181015460ff811615159286019290925264ffffffffff610100808404821695870195909552600160301b830481166060870152600160581b83041660808601526001600160801b03600160801b909204821660a0860152600281015490911660c08501529081015460e0840152600401549082015290565b6040516102409190612bd9565b6102e4610401366004612cf1565b610b23565b6102a37f000000000000000000000000000000000000000000000000000000000000000081565b61044061043b366004612b2c565b610ddf565b604051610240929190612e00565b6102e4610e00565b61045e610e14565b6040516102409796959493929190612e5b565b6102e461047f366004612bc0565b610e5a565b6102c3610f72565b6002546001600160a01b03166102a3565b6104b06104ab366004612bc0565b610f9b565b6040516102409190612ecb565b6102a37f000000000000000000000000000000000000000000000000000000000000000081565b610516604051806040016040528060138152602001724161766520566f74696e67204d616368696e6560681b81525081565b6040516102409190612ee5565b6102c3610531366004612bc0565b610fb2565b6102e4610544366004612eff565b6111b8565b6102c36111cb565b6102c37f000000000000000000000000000000000000000000000000000000000000000081565b6102e4610586366004612f5a565b6111f4565b61059e610599366004612b2c565b611203565b6040516102409493929190612ff2565b6102a37f000000000000000000000000000000000000000000000000000000000000000081565b61051661122d565b6102e46105eb366004613070565b611249565b6102a37f000000000000000000000000000000000000000000000000000000000000000081565b610668610625366004612bc0565b6040805180820190915260008082526020820152506000908152600460209081526040918290208251808401909352805462ffffff168352600101549082015290565b60408051825162ffffff1681526020928301519281019290925201610240565b6102e4610696366004613160565b6114f7565b6106ae6106a936600461317d565b611570565b604051610240919061319f565b6102e46106c9366004612bc0565b611683565b6102c3600981565b60408051808201825260008082526020918201819052838152600382528281206001600160a01b0386168252600501825282902082518084019093525460ff81161515835261010090046001600160f81b0316908201525b92915050565b60008060008380602001905181019061074d91906131b2565b9250925092509193909250565b6040518060600160405280603981526020016138946039913960405160200161078391906131f3565b6040516020818303038152906040528051906020012081565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614801561080557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316145b801561083057507f000000000000000000000000000000000000000000000000000000000000000082145b604051806040016040528060028152602001610c4d60f21b815250906108725760405162461bcd60e51b81526004016108699190612ee5565b60405180910390fd5b506040516331a6a2d960e11b8152309063634d45b290610896908490600401612ee5565b600060405180830381865afa9250505080156108d457506040513d6000823e601f3d908101601f191682016040526108d19190810190613291565b60015b610952573d808015610902576040519150601f19603f3d011682016040523d82523d6000602084013e610907565b606091505b5082846001600160a01b03167f8b1e20717f068e39458a6f9c1626ff855155e9b16c044581dc9648e8fbd51e8e8484604051610944929190613321565b60405180910390a350505050565b6060600183600181111561096857610968612d86565b03610aaa5760405163094e2dcb60e11b8152309063129c5b9690610990908590600401612ee5565b606060405180830381865afa9250505080156109c9575060408051601f3d908101601f191682019092526109c6918101906131b2565b60015b610a4d573d8080156109f7576040519150601f19603f3d011682016040523d82523d6000602084013e6109fc565b606091505b506000151586886001600160a01b03167f91ff2d4d8e24ff9dab08471142a75c2f2ad08f79dc01c8b273d6e42700a4e2dd878786604051610a3f9392919061334f565b60405180910390a450610b0c565b610a58838383611694565b60011515888a6001600160a01b03167f91ff2d4d8e24ff9dab08471142a75c2f2ad08f79dc01c8b273d6e42700a4e2dd898989604051610a9a9392919061334f565b60405180910390a4505050610b0c565b84866001600160a01b03167f8b1e20717f068e39458a6f9c1626ff855155e9b16c044581dc9648e8fbd51e8e8686604051602001610ae8919061338b565b60408051601f1981840301815290829052610b039291613321565b60405180910390a35b505050505050565b6000610b1e6118a8565b905090565b6000846001600160401b03811115610b3d57610b3d612a1f565b604051908082528060200260200182016040528015610b66578160200160208202803683370190505b50905060005b85811015610c945760405180606001604052806039815260200161389460399139604051602001610b9d91906133d2565b60405160208183030381529060405280519060200120878783818110610bc557610bc56133ee565b9050602002810190610bd79190613404565b610be5906020810190613160565b888884818110610bf757610bf76133ee565b9050602002810190610c099190613404565b610c1a90604081019060200161342f565b604051602001610c4f939291909283526001600160a01b039190911660208301526001600160801b0316604082015260600190565b60405160208183030381529060405280519060200120828281518110610c7757610c776133ee565b602090810291909101015280610c8c81613462565b915050610b6c565b506000610d5060405180606001604052806039815260200161389460399139604051602001610cc391906131f3565b604051602081830303815290604052805190602001208b8b8b86604051602001610ced919061347b565b60408051601f198184030181528282528051602091820120908301969096528101939093526001600160a01b0390911660608301521515608082015260a081019190915260c0015b604051602081830303815290604052805190602001206119d3565b90506000610d6082878787611a00565b9050896001600160a01b0316816001600160a01b0316148015610d8b57506001600160a01b03811615155b60405180604001604052806002815260200161313760f01b81525090610dc45760405162461bcd60e51b81526004016108699190612ee5565b50610dd2818c8b8b8b611a2e565b5050505050505050505050565b6000606082806020019051810190610df79190613291565b91509150915091565b610e08612104565b610e12600061215e565b565b600060608060008060006060610e286121b0565b610e306121dd565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b60008181526003602052604090206002610e738261220a565b6003811115610e8457610e84612d86565b1460405180604001604052806002815260200161062760f31b81525090610ebe5760405162461bcd60e51b81526004016108699190612ee5565b504360048201554260018083018054600285015460ff1964ffffffffff95909516600160581b029485166fffffffffff00000000000000000000ff198316179093179091556001600160801b03600160801b64ffffffffff60581b19909216939093170482169116610f31848383612278565b604080518381526020810183905285917f57595374ff15e29915354c26ba858db8ad6934a534ba31596cd613581aa3b99c910160405180910390a250505050565b6040518060600160405280603981526020016138946039913960405160200161078391906133d2565b600081815260036020526040812061072e9061220a565b600081815260046020908152604080832081518083018352815462ffffff16815260019091015481840181905282518084019093526002835261066760f31b93830193909352916110165760405162461bcd60e51b81526004016108699190612ee5565b5060008381526003602052604081209061102f8261220a565b600381111561104057611040612d86565b1460405180604001604052806002815260200161189b60f11b8152509061107a5760405162461bcd60e51b81526004016108699190612ee5565b5060208201516040516317c1aadb60e31b815260048101919091527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063be0d56d89060240160006040518083038186803b1580156110e157600080fd5b505afa1580156110f5573d6000803e3d6000fd5b50505050611106826020015161237d565b8151429060009061111c9062ffffff16836134b1565b8684554360038501556001840180546affffffffffffffffffff00191661010064ffffffffff8681169182026affffffffff000000000000191692909217600160301b9285169283021790925560208781015160408051948552918401929092529293509188917f4a35ebd1b3d3106a86d022fa35dfeaefd17695e3c7cd99d39841db619106ade2910160405180910390a35093949350505050565b6111c53385858585611a2e565b50505050565b6040518060600160405280603981526020016138946039913960405160200161078391906134d6565b610b0c86868633878787612472565b600080600060608480602001905181019061121e91906135a1565b93509350935093509193509193565b6040518060600160405280603981526020016138946039913981565b6000826001600160401b0381111561126357611263612a1f565b60405190808252806020026020018201604052801561128c578160200160208202803683370190505b50905060005b838110156113ba57604051806060016040528060398152602001613894603991396040516020016112c391906133d2565b604051602081830303815290604052805190602001208585838181106112eb576112eb6133ee565b90506020028101906112fd9190613404565b61130b906020810190613160565b86868481811061131d5761131d6133ee565b905060200281019061132f9190613404565b61134090604081019060200161342f565b604051602001611375939291909283526001600160a01b039190911660208301526001600160801b0316604082015260600190565b6040516020818303038152906040528051906020012082828151811061139d5761139d6133ee565b6020908102919091010152806113b281613462565b915050611292565b506000611467604051806060016040528060398152602001613894603991396040516020016113e991906134d6565b604051602081830303815290604052805190602001208b8b8b8b87604051602001611414919061347b565b60408051601f198184030181528282528051602091820120908301979097528101949094526001600160a01b03928316606085015291166080830152151560a082015260c081019190915260e001610d35565b9050600061148382856000015186602001518760400151611a00565b9050886001600160a01b0316816001600160a01b03161480156114ae57506001600160a01b03811615155b60405180604001604052806002815260200161313760f01b815250906114e75760405162461bcd60e51b81526004016108699190612ee5565b50610dd28b898c8c8b8b8b612472565b6114ff612104565b6001600160a01b0381166115645760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610869565b61156d8161215e565b50565b6005546060908015806115835750838111155b1561159e57505060408051600081526020810190915261072e565b6115a884846136b0565b8110156115bc576115b984826136c3565b92505b6000836001600160401b038111156115d6576115d6612a1f565b6040519080825280602002602001820160405280156115ff578160200160208202803683370190505b50905060005b8481101561167a57600560018261161c89876136c3565b61162691906136c3565b61163091906136c3565b81548110611640576116406133ee565b906000526020600020015482828151811061165d5761165d6133ee565b60209081029190910101528061167281613462565b915050611605565b50949350505050565b61168b612104565b61156d8161263b565b604080518082019091526002815261373360f01b6020820152826116cb5760405162461bcd60e51b81526004016108699190612ee5565b506040805180820190915260028152610dcd60f21b602082015262ffffff82166117085760405162461bcd60e51b81526004016108699190612ee5565b506000838152600460209081526040918290206001015482518084019093526002835261333960f01b91830191909152156117565760405162461bcd60e51b81526004016108699190612ee5565b5060408051808201825262ffffff8381168252602080830186815260008881526004928390528581209451855462ffffff191694169390931784555160019384015560058054938401815582527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db090920186905591516314d3a96560e31b8152908101859052309063a69d4b28906024016020604051808303816000875af1925050508015611822575060408051601f3d908101601f1916820190925261181f918101906136d6565b60015b61185c573d808015611850576040519150601f19603f3d011682016040523d82523d6000602084013e611855565b606091505b5050611862565b50600190505b60405162ffffff8316815281151590849086907fb97f85602e54244368524a04b5db9a67dbbbfa909eace9334c79b7c0c1d255e59060200160405180910390a450505050565b6000306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614801561190157507f000000000000000000000000000000000000000000000000000000000000000046145b1561192b57507f000000000000000000000000000000000000000000000000000000000000000090565b610b1e604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b600061072e6119e06118a8565b8360405161190160f01b8152600281019290925260228201526042902090565b600080600080611a128888888861266e565b925092509250611a22828261273d565b50909695505050505050565b60008481526003602052604090206001611a478261220a565b6003811115611a5857611a58612d86565b1460405180604001604052806002815260200161313960f01b81525090611a925760405162461bcd60e51b81526004016108699190612ee5565b506001600160a01b0386166000908152600582016020908152604091829020805483518085019094526002845261032360f41b92840192909252919061010090046001600160f81b031615611afa5760405162461bcd60e51b81526004016108699190612ee5565b50600086815260046020908152604080832081518083018352815462ffffff16815260019091015481840152815180830190925283825291810183905290919060005b86811015611fa5576000611b528260016136b0565b90505b87811015611ca657888882818110611b6f57611b6f6133ee565b9050602002810190611b819190613404565b611b9290604081019060200161342f565b6001600160801b0316898984818110611bad57611bad6133ee565b9050602002810190611bbf9190613404565b611bd090604081019060200161342f565b6001600160801b0316141580611c5a5750888882818110611bf357611bf36133ee565b9050602002810190611c059190613404565b611c13906020810190613160565b6001600160a01b0316898984818110611c2e57611c2e6133ee565b9050602002810190611c409190613404565b611c4e906020810190613160565b6001600160a01b031614155b60405180604001604052806002815260200161323160f01b81525090611c935760405162461bcd60e51b81526004016108699190612ee5565b5080611c9e81613462565b915050611b55565b507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e50d420c898984818110611ce857611ce86133ee565b9050602002810190611cfa9190613404565b611d08906020810190613160565b8660200151611d8c8f8d8d88818110611d2357611d236133ee565b9050602002810190611d359190613404565b611d4690604081019060200161342f565b6001600160801b0316604080516001600160a01b038416602082015290810182905260009060600160405160208183030381529060405280519060200120905092915050565b8c8c87818110611d9e57611d9e6133ee565b9050602002810190611db09190613404565b611dbe9060408101906136ef565b6040518663ffffffff1660e01b8152600401611dde959493929190613735565b6040805180830381865afa158015611dfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e1e9190613781565b8051604080518082019091526002815261191960f11b6020820152919350611e595760405162461bcd60e51b81526004016108699190612ee5565b50602082015115611f93577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632a71f953898984818110611ea557611ea56133ee565b9050602002810190611eb79190613404565b611ec5906020810190613160565b8a8a85818110611ed757611ed76133ee565b9050602002810190611ee99190613404565b611efa90604081019060200161342f565b602080870151908901516040516001600160e01b031960e087901b1681526001600160a01b0390941660048501526001600160801b03909216602484015260448301526064820152608401602060405180830381865afa158015611f62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f8691906136d6565b611f9090846136b0565b92505b80611f9d81613462565b915050611b3d565b50604080518082019091526002815261323360f01b602082015282611fdd5760405162461bcd60e51b81526004016108699190612ee5565b50871561203a57611fed826127f6565b600186018054601090612011908490600160801b90046001600160801b03166137bb565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550612085565b612043826127f6565b6002860180546000906120609084906001600160801b03166137bb565b92506101000a8154816001600160801b0302191690836001600160801b031602179055505b835460ff191688151517845561209a82612863565b84546001600160f81b03919091166101000260ff909116178455604051828152881515906001600160a01b038c16908b907f0c611e7b6ae0de26f4772260e1bbdb5f58cbb7c275fe2de14671968d29add8d69060200160405180910390a450505050505050505050565b6002546001600160a01b03163314610e125760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610869565b600280546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6060610b1e7f000000000000000000000000000000000000000000000000000000000000000060006128cc565b6060610b1e7f000000000000000000000000000000000000000000000000000000000000000060016128cc565b6001810154600090600160301b900464ffffffffff16810361222e57506000919050565b6001820154600160301b900464ffffffffff164264ffffffffff161161225657506001919050565b600182015460ff161561226b57506003919050565b506002919050565b919050565b600654604080516020810186905280820185905260608082018590528251808303909101815260808201928390526315713fb560e21b9092527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316926355c4fed492612334927f0000000000000000000000000000000000000000000000000000000000000000927f00000000000000000000000000000000000000000000000000000000000000009290916084016137db565b60408051808303816000875af1158015612352573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123769190613808565b5050505050565b6040516381ac42b560e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152602482018390526000917f0000000000000000000000000000000000000000000000000000000000000000909116906381ac42b590604401602060405180830381865afa15801561240f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243391906136d6565b141560405180604001604052806002815260200161393560f01b8152509061246e5760405162461bcd60e51b81526004016108699190612ee5565b5050565b604080518082019091526002815261363760f01b60208201526001600160a01b0386166124b25760405162461bcd60e51b81526004016108699190612ee5565b5060008781526004602090815260408083206001015481516001600160a01b038a81168286015260098285015283518083038501815260608301855280519086012046608084015260a0808401919091528451808403909101815260c08301948590528051950194909420633943508360e21b909352909391927f0000000000000000000000000000000000000000000000000000000000000000169063e50d420c90612589907f000000000000000000000000000000000000000000000000000000000000000090879087908c9060c40161382c565b6040805180830381865afa1580156125a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125c99190613781565b60208101519091506001600160a01b038881169082161480156125f457506001600160a01b03881615155b604051806040016040528060028152602001611c9b60f11b8152509061262d5760405162461bcd60e51b81526004016108699190612ee5565b50610dd2898c8c8989611a2e565b600681905560405181907f3d1394ba0f6fca9c1e344f10a3efe1bfca63bc591232bb0d76755690f409450c90600090a250565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411156126a95750600091506003905082612733565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa1580156126fd573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661272957506000925060019150829050612733565b9250600091508190505b9450945094915050565b600082600381111561275157612751612d86565b0361275a575050565b600182600381111561276e5761276e612d86565b0361278c5760405163f645eedf60e01b815260040160405180910390fd5b60028260038111156127a0576127a0612d86565b036127c15760405163fce698f760e01b815260048101829052602401610869565b60038260038111156127d5576127d5612d86565b0361246e576040516335e2f38360e21b815260048101829052602401610869565b60006001600160801b0382111561285f5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610869565b5090565b60006001600160f81b0382111561285f5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663438206269747360c81b6064820152608401610869565b606060ff83146128e6576128df83612977565b905061072e565b8180546128f290613859565b80601f016020809104026020016040519081016040528092919081815260200182805461291e90613859565b801561296b5780601f106129405761010080835404028352916020019161296b565b820191906000526020600020905b81548152906001019060200180831161294e57829003601f168201915b5050505050905061072e565b60606000612984836129b6565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b600060ff8216601f81111561072e57604051632cd44ac360e21b815260040160405180910390fd5b6001600160a01b038116811461156d57600080fd5b60008060408385031215612a0657600080fd5b8235612a11816129de565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b0381118282101715612a5757612a57612a1f565b60405290565b604080519081016001600160401b0381118282101715612a5757612a57612a1f565b604051601f8201601f191681016001600160401b0381118282101715612aa757612aa7612a1f565b604052919050565b60006001600160401b03821115612ac857612ac8612a1f565b50601f01601f191660200190565b600082601f830112612ae757600080fd5b8135612afa612af582612aaf565b612a7f565b818152846020838601011115612b0f57600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215612b3e57600080fd5b81356001600160401b03811115612b5457600080fd5b612b6084828501612ad6565b949350505050565b600080600060608486031215612b7d57600080fd5b8335612b88816129de565b92506020840135915060408401356001600160401b03811115612baa57600080fd5b612bb686828701612ad6565b9150509250925092565b600060208284031215612bd257600080fd5b5035919050565b6000610120820190508251825260208301511515602083015264ffffffffff60408401511660408301526060830151612c1b606084018264ffffffffff169052565b506080830151612c34608084018264ffffffffff169052565b5060a0830151612c4f60a08401826001600160801b03169052565b5060c0830151612c6a60c08401826001600160801b03169052565b5060e083015160e083015261010080840151818401525092915050565b801515811461156d57600080fd5b60008083601f840112612ca757600080fd5b5081356001600160401b03811115612cbe57600080fd5b6020830191508360208260051b8501011115612cd957600080fd5b9250929050565b803560ff8116811461227357600080fd5b60008060008060008060008060e0898b031215612d0d57600080fd5b883597506020890135612d1f816129de565b96506040890135612d2f81612c87565b955060608901356001600160401b03811115612d4a57600080fd5b612d568b828c01612c95565b9096509450612d69905060808a01612ce0565b925060a0890135915060c089013590509295985092959890939650565b634e487b7160e01b600052602160045260246000fd5b60028110612dac57612dac612d86565b9052565b60005b83811015612dcb578181015183820152602001612db3565b50506000910152565b60008151808452612dec816020860160208601612db0565b601f01601f19169290920160200192915050565b612e0a8184612d9c565b604060208201526000612b606040830184612dd4565b600081518084526020808501945080840160005b83811015612e5057815187529582019590820190600101612e34565b509495945050505050565b60ff60f81b8816815260e060208201526000612e7a60e0830189612dd4565b8281036040840152612e8c8189612dd4565b606084018890526001600160a01b038716608085015260a0840186905283810360c08501529050612ebd8185612e20565b9a9950505050505050505050565b6020810160048310612edf57612edf612d86565b91905290565b602081526000612ef86020830184612dd4565b9392505050565b60008060008060608587031215612f1557600080fd5b843593506020850135612f2781612c87565b925060408501356001600160401b03811115612f4257600080fd5b612f4e87828801612c95565b95989497509550505050565b60008060008060008060a08789031215612f7357600080fd5b863595506020870135612f8581612c87565b94506040870135612f95816129de565b935060608701356001600160401b0380821115612fb157600080fd5b612fbd8a838b01612ad6565b94506080890135915080821115612fd357600080fd5b50612fe089828a01612c95565b979a9699509497509295939492505050565b600060808201868352602060018060a01b03808816828601526040871515818701526080606087015283875180865260a088019150848901955060005b8181101561305f5786518051861684528601516001600160801b031686840152958501959183019160010161302f565b50909b9a5050505050505050505050565b600080600080600080600080888a0361012081121561308e57600080fd5b8935985060208a01356130a0816129de565b975060408a01356130b0816129de565b965060608a01356130c081612c87565b955060808a01356001600160401b03808211156130dc57600080fd5b6130e88d838e01612ad6565b965060a08c01359150808211156130fe57600080fd5b5061310b8c828d01612c95565b909550935050606060bf198201121561312357600080fd5b5061312c612a35565b61313860c08b01612ce0565b815260e08a013560208201526101008a01356040820152809150509295985092959890939650565b60006020828403121561317257600080fd5b8135612ef8816129de565b6000806040838503121561319057600080fd5b50508035926020909101359150565b602081526000612ef86020830184612e20565b6000806000606084860312156131c757600080fd5b8351925060208401519150604084015162ffffff811681146131e857600080fd5b809150509250925092565b7f5375626d6974566f74652875696e743235362070726f706f73616c49642c616481527f647265737320766f7465722c626f6f6c20737570706f72742c566f74696e674160208201527f7373657457697468536c6f745b5d20766f74696e6741737365747357697468536040820152636c6f742960e01b606082015260008251613284816064850160208701612db0565b9190910160640192915050565b600080604083850312156132a457600080fd5b8251600281106132b357600080fd5b60208401519092506001600160401b038111156132cf57600080fd5b8301601f810185136132e057600080fd5b80516132ee612af582612aaf565b81815286602083850101111561330357600080fd5b613314826020830160208601612db0565b8093505050509250929050565b6040815260006133346040830185612dd4565b82810360208401526133468185612dd4565b95945050505050565b6133598185612d9c565b60606020820152600061336f6060830185612dd4565b82810360408401526133818185612dd4565b9695505050505050565b7f756e737570706f72746564206d65737361676520747970653a2000000000000081526000600283106133c0576133c0612d86565b5060f89190911b601a820152601b0190565b600082516133e4818460208701612db0565b9190910192915050565b634e487b7160e01b600052603260045260246000fd5b60008235605e198336030181126133e457600080fd5b6001600160801b038116811461156d57600080fd5b60006020828403121561344157600080fd5b8135612ef88161341a565b634e487b7160e01b600052601160045260246000fd5b6000600182016134745761347461344c565b5060010190565b815160009082906020808601845b838110156134a557815185529382019390820190600101613489565b50929695505050505050565b64ffffffffff8181168382160190808211156134cf576134cf61344c565b5092915050565b7f5375626d6974566f74654173526570726573656e7461746976652875696e743281527f35362070726f706f73616c49642c6164647265737320766f7465722c6164647260208201527f65737320726570726573656e7461746976652c626f6f6c20737570706f72742c60408201527f566f74696e67417373657457697468536c6f745b5d20766f74696e674173736560608201526a747357697468536c6f742960a81b60808201526000825161359481608b850160208701612db0565b91909101608b0192915050565b600080600080608085870312156135b757600080fd5b845193506020808601516135ca816129de565b809450506040808701516135dd81612c87565b60608801519094506001600160401b03808211156135fa57600080fd5b818901915089601f83011261360e57600080fd5b81518181111561362057613620612a1f565b61362e858260051b01612a7f565b818152858101925060069190911b83018501908b82111561364e57600080fd5b928501925b818410156136a05784848d03121561366b5760008081fd5b613673612a5d565b845161367e816129de565b81528487015161368d8161341a565b8188015283529284019291850191613653565b989b979a50959850505050505050565b8082018082111561072e5761072e61344c565b8181038181111561072e5761072e61344c565b6000602082840312156136e857600080fd5b5051919050565b6000808335601e1984360301811261370657600080fd5b8301803591506001600160401b0382111561372057600080fd5b602001915036819003821315612cd957600080fd5b60018060a01b038616815284602082015283604082015260806060820152816080820152818360a0830137600081830160a090810191909152601f909201601f19160101949350505050565b60006040828403121561379357600080fd5b61379b612a5d565b82516137a681612c87565b81526020928301519281019290925250919050565b6001600160801b038181168382160190808211156134cf576134cf61344c565b84815260018060a01b03841660208201528260408201526080606082015260006133816080830184612dd4565b6000806040838503121561381b57600080fd5b505080516020909101519092909150565b60018060a01b03851681528360208201528260408201526080606082015260006133816080830184612dd4565b600181811c9082168061386d57607f821691505b60208210810361388d57634e487b7160e01b600052602260045260246000fd5b5091905056fe566f74696e67417373657457697468536c6f74286164647265737320756e6465726c79696e6741737365742c75696e7431323820736c6f7429a2646970667358221220a9f31fcf5706f7525d64688572bc75d80377edd7fa1a8fc1f638b39dffa64a4a64736f6c63430008130033000000000000000000000000f6b99959f0b5e79e1cc7062e12af632ceb18ef0d000000000000000000000000000000000000000000000000000000000003d090000000000000000000000000000000000000000000000000000000000000000100000000000000000000000059e6cad5d7e7b9a26a45a1d1e74c7af0081700420000000000000000000000009b24c168d6a76b5459b1d47071a54962a4df36c30000000000000000000000009aee0b04504cef83a65ac3f0e838d0593bcb2bc7

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102065760003560e01c80639a39ada31161011a578063c4956366116100ad578063f2709a5c1161007c578063f2709a5c14610617578063f2fde38b14610688578063f4b7223b1461069b578063f687d12a146106bb578063fd1bd2e9146106ce57600080fd5b8063c4956366146105ae578063d53d9b10146105d5578063dbb8f60a146105dd578063de6bd082146105f057600080fd5b8063aa1da0d2116100e9578063aa1da0d214610549578063b34a5e6b14610551578063b6b0f0e014610578578063bc5ee6a81461058b57600080fd5b80639a39ada3146104bd578063a3f4df7e146104e4578063a69d4b2814610523578063a7f8451c1461053657600080fd5b80633be191df1161019d57806384b0196e1161016c57806384b0196e14610456578063867b96c21461047157806389aa5905146104845780638da5cb5b1461048c5780639080936f1461049d57600080fd5b80633be191df146103f35780634916963e14610406578063634d45b21461042d578063715018a61461044e57600080fd5b806315034cba116101d957806315034cba146102d15780631a93d1c3146102e65780633644e515146102ee5780633656de21146102f657600080fd5b80630def04021461020b578063129c5b9614610249578063146278341461027c578063147c11ea146102bb575b600080fd5b61021e6102193660046129f3565b6106d6565b604080518251151581526020928301516001600160f81b031692810192909252015b60405180910390f35b61025c610257366004612b2c565b610734565b60408051938452602084019290925262ffffff1690820152606001610240565b6102a37f0000000000000000000000009aee0b04504cef83a65ac3f0e838d0593bcb2bc781565b6040516001600160a01b039091168152602001610240565b6102c361075a565b604051908152602001610240565b6102e46102df366004612b68565b61079c565b005b6006546102c3565b6102c3610b14565b6103e6610304366004612bc0565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915250600081815260036020818152604092839020835161012081018552948552600181015460ff811615159286019290925264ffffffffff610100808404821695870195909552600160301b830481166060870152600160581b83041660808601526001600160801b03600160801b909204821660a0860152600281015490911660c08501529081015460e0840152600401549082015290565b6040516102409190612bd9565b6102e4610401366004612cf1565b610b23565b6102a37f00000000000000000000000059e6cad5d7e7b9a26a45a1d1e74c7af00817004281565b61044061043b366004612b2c565b610ddf565b604051610240929190612e00565b6102e4610e00565b61045e610e14565b6040516102409796959493929190612e5b565b6102e461047f366004612bc0565b610e5a565b6102c3610f72565b6002546001600160a01b03166102a3565b6104b06104ab366004612bc0565b610f9b565b6040516102409190612ecb565b6102a37f0000000000000000000000009b24c168d6a76b5459b1d47071a54962a4df36c381565b610516604051806040016040528060138152602001724161766520566f74696e67204d616368696e6560681b81525081565b6040516102409190612ee5565b6102c3610531366004612bc0565b610fb2565b6102e4610544366004612eff565b6111b8565b6102c36111cb565b6102c37f000000000000000000000000000000000000000000000000000000000000000181565b6102e4610586366004612f5a565b6111f4565b61059e610599366004612b2c565b611203565b6040516102409493929190612ff2565b6102a37f000000000000000000000000f6b99959f0b5e79e1cc7062e12af632ceb18ef0d81565b61051661122d565b6102e46105eb366004613070565b611249565b6102a37f000000000000000000000000f41193e25408f652af878c47e4401a01b5e4b68281565b610668610625366004612bc0565b6040805180820190915260008082526020820152506000908152600460209081526040918290208251808401909352805462ffffff168352600101549082015290565b60408051825162ffffff1681526020928301519281019290925201610240565b6102e4610696366004613160565b6114f7565b6106ae6106a936600461317d565b611570565b604051610240919061319f565b6102e46106c9366004612bc0565b611683565b6102c3600981565b60408051808201825260008082526020918201819052838152600382528281206001600160a01b0386168252600501825282902082518084019093525460ff81161515835261010090046001600160f81b0316908201525b92915050565b60008060008380602001905181019061074d91906131b2565b9250925092509193909250565b6040518060600160405280603981526020016138946039913960405160200161078391906131f3565b6040516020818303038152906040528051906020012081565b336001600160a01b037f000000000000000000000000f6b99959f0b5e79e1cc7062e12af632ceb18ef0d1614801561080557507f0000000000000000000000009b24c168d6a76b5459b1d47071a54962a4df36c36001600160a01b0316836001600160a01b0316145b801561083057507f000000000000000000000000000000000000000000000000000000000000000182145b604051806040016040528060028152602001610c4d60f21b815250906108725760405162461bcd60e51b81526004016108699190612ee5565b60405180910390fd5b506040516331a6a2d960e11b8152309063634d45b290610896908490600401612ee5565b600060405180830381865afa9250505080156108d457506040513d6000823e601f3d908101601f191682016040526108d19190810190613291565b60015b610952573d808015610902576040519150601f19603f3d011682016040523d82523d6000602084013e610907565b606091505b5082846001600160a01b03167f8b1e20717f068e39458a6f9c1626ff855155e9b16c044581dc9648e8fbd51e8e8484604051610944929190613321565b60405180910390a350505050565b6060600183600181111561096857610968612d86565b03610aaa5760405163094e2dcb60e11b8152309063129c5b9690610990908590600401612ee5565b606060405180830381865afa9250505080156109c9575060408051601f3d908101601f191682019092526109c6918101906131b2565b60015b610a4d573d8080156109f7576040519150601f19603f3d011682016040523d82523d6000602084013e6109fc565b606091505b506000151586886001600160a01b03167f91ff2d4d8e24ff9dab08471142a75c2f2ad08f79dc01c8b273d6e42700a4e2dd878786604051610a3f9392919061334f565b60405180910390a450610b0c565b610a58838383611694565b60011515888a6001600160a01b03167f91ff2d4d8e24ff9dab08471142a75c2f2ad08f79dc01c8b273d6e42700a4e2dd898989604051610a9a9392919061334f565b60405180910390a4505050610b0c565b84866001600160a01b03167f8b1e20717f068e39458a6f9c1626ff855155e9b16c044581dc9648e8fbd51e8e8686604051602001610ae8919061338b565b60408051601f1981840301815290829052610b039291613321565b60405180910390a35b505050505050565b6000610b1e6118a8565b905090565b6000846001600160401b03811115610b3d57610b3d612a1f565b604051908082528060200260200182016040528015610b66578160200160208202803683370190505b50905060005b85811015610c945760405180606001604052806039815260200161389460399139604051602001610b9d91906133d2565b60405160208183030381529060405280519060200120878783818110610bc557610bc56133ee565b9050602002810190610bd79190613404565b610be5906020810190613160565b888884818110610bf757610bf76133ee565b9050602002810190610c099190613404565b610c1a90604081019060200161342f565b604051602001610c4f939291909283526001600160a01b039190911660208301526001600160801b0316604082015260600190565b60405160208183030381529060405280519060200120828281518110610c7757610c776133ee565b602090810291909101015280610c8c81613462565b915050610b6c565b506000610d5060405180606001604052806039815260200161389460399139604051602001610cc391906131f3565b604051602081830303815290604052805190602001208b8b8b86604051602001610ced919061347b565b60408051601f198184030181528282528051602091820120908301969096528101939093526001600160a01b0390911660608301521515608082015260a081019190915260c0015b604051602081830303815290604052805190602001206119d3565b90506000610d6082878787611a00565b9050896001600160a01b0316816001600160a01b0316148015610d8b57506001600160a01b03811615155b60405180604001604052806002815260200161313760f01b81525090610dc45760405162461bcd60e51b81526004016108699190612ee5565b50610dd2818c8b8b8b611a2e565b5050505050505050505050565b6000606082806020019051810190610df79190613291565b91509150915091565b610e08612104565b610e12600061215e565b565b600060608060008060006060610e286121b0565b610e306121dd565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b60008181526003602052604090206002610e738261220a565b6003811115610e8457610e84612d86565b1460405180604001604052806002815260200161062760f31b81525090610ebe5760405162461bcd60e51b81526004016108699190612ee5565b504360048201554260018083018054600285015460ff1964ffffffffff95909516600160581b029485166fffffffffff00000000000000000000ff198316179093179091556001600160801b03600160801b64ffffffffff60581b19909216939093170482169116610f31848383612278565b604080518381526020810183905285917f57595374ff15e29915354c26ba858db8ad6934a534ba31596cd613581aa3b99c910160405180910390a250505050565b6040518060600160405280603981526020016138946039913960405160200161078391906133d2565b600081815260036020526040812061072e9061220a565b600081815260046020908152604080832081518083018352815462ffffff16815260019091015481840181905282518084019093526002835261066760f31b93830193909352916110165760405162461bcd60e51b81526004016108699190612ee5565b5060008381526003602052604081209061102f8261220a565b600381111561104057611040612d86565b1460405180604001604052806002815260200161189b60f11b8152509061107a5760405162461bcd60e51b81526004016108699190612ee5565b5060208201516040516317c1aadb60e31b815260048101919091527f00000000000000000000000059e6cad5d7e7b9a26a45a1d1e74c7af0081700426001600160a01b03169063be0d56d89060240160006040518083038186803b1580156110e157600080fd5b505afa1580156110f5573d6000803e3d6000fd5b50505050611106826020015161237d565b8151429060009061111c9062ffffff16836134b1565b8684554360038501556001840180546affffffffffffffffffff00191661010064ffffffffff8681169182026affffffffff000000000000191692909217600160301b9285169283021790925560208781015160408051948552918401929092529293509188917f4a35ebd1b3d3106a86d022fa35dfeaefd17695e3c7cd99d39841db619106ade2910160405180910390a35093949350505050565b6111c53385858585611a2e565b50505050565b6040518060600160405280603981526020016138946039913960405160200161078391906134d6565b610b0c86868633878787612472565b600080600060608480602001905181019061121e91906135a1565b93509350935093509193509193565b6040518060600160405280603981526020016138946039913981565b6000826001600160401b0381111561126357611263612a1f565b60405190808252806020026020018201604052801561128c578160200160208202803683370190505b50905060005b838110156113ba57604051806060016040528060398152602001613894603991396040516020016112c391906133d2565b604051602081830303815290604052805190602001208585838181106112eb576112eb6133ee565b90506020028101906112fd9190613404565b61130b906020810190613160565b86868481811061131d5761131d6133ee565b905060200281019061132f9190613404565b61134090604081019060200161342f565b604051602001611375939291909283526001600160a01b039190911660208301526001600160801b0316604082015260600190565b6040516020818303038152906040528051906020012082828151811061139d5761139d6133ee565b6020908102919091010152806113b281613462565b915050611292565b506000611467604051806060016040528060398152602001613894603991396040516020016113e991906134d6565b604051602081830303815290604052805190602001208b8b8b8b87604051602001611414919061347b565b60408051601f198184030181528282528051602091820120908301979097528101949094526001600160a01b03928316606085015291166080830152151560a082015260c081019190915260e001610d35565b9050600061148382856000015186602001518760400151611a00565b9050886001600160a01b0316816001600160a01b03161480156114ae57506001600160a01b03811615155b60405180604001604052806002815260200161313760f01b815250906114e75760405162461bcd60e51b81526004016108699190612ee5565b50610dd28b898c8c8b8b8b612472565b6114ff612104565b6001600160a01b0381166115645760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610869565b61156d8161215e565b50565b6005546060908015806115835750838111155b1561159e57505060408051600081526020810190915261072e565b6115a884846136b0565b8110156115bc576115b984826136c3565b92505b6000836001600160401b038111156115d6576115d6612a1f565b6040519080825280602002602001820160405280156115ff578160200160208202803683370190505b50905060005b8481101561167a57600560018261161c89876136c3565b61162691906136c3565b61163091906136c3565b81548110611640576116406133ee565b906000526020600020015482828151811061165d5761165d6133ee565b60209081029190910101528061167281613462565b915050611605565b50949350505050565b61168b612104565b61156d8161263b565b604080518082019091526002815261373360f01b6020820152826116cb5760405162461bcd60e51b81526004016108699190612ee5565b506040805180820190915260028152610dcd60f21b602082015262ffffff82166117085760405162461bcd60e51b81526004016108699190612ee5565b506000838152600460209081526040918290206001015482518084019093526002835261333960f01b91830191909152156117565760405162461bcd60e51b81526004016108699190612ee5565b5060408051808201825262ffffff8381168252602080830186815260008881526004928390528581209451855462ffffff191694169390931784555160019384015560058054938401815582527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db090920186905591516314d3a96560e31b8152908101859052309063a69d4b28906024016020604051808303816000875af1925050508015611822575060408051601f3d908101601f1916820190925261181f918101906136d6565b60015b61185c573d808015611850576040519150601f19603f3d011682016040523d82523d6000602084013e611855565b606091505b5050611862565b50600190505b60405162ffffff8316815281151590849086907fb97f85602e54244368524a04b5db9a67dbbbfa909eace9334c79b7c0c1d255e59060200160405180910390a450505050565b6000306001600160a01b037f000000000000000000000000c8a2adc4261c6b669cdff69e717e77c9cfeb420d1614801561190157507f000000000000000000000000000000000000000000000000000000000000008946145b1561192b57507fae1a4d19b2c550c11439cbcb934c88b16b8585f876d64fe1a6a6ae8e9e863c4690565b610b1e604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527fa541d5311366fcd9e2a293b74fc7a83275dafef30229b0ede4c76042de7ed570918101919091527f4c23426613a5dc69e08fbd2787e6210aa679d4522e95a89d4dd88c4fd13a228360608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b600061072e6119e06118a8565b8360405161190160f01b8152600281019290925260228201526042902090565b600080600080611a128888888861266e565b925092509250611a22828261273d565b50909695505050505050565b60008481526003602052604090206001611a478261220a565b6003811115611a5857611a58612d86565b1460405180604001604052806002815260200161313960f01b81525090611a925760405162461bcd60e51b81526004016108699190612ee5565b506001600160a01b0386166000908152600582016020908152604091829020805483518085019094526002845261032360f41b92840192909252919061010090046001600160f81b031615611afa5760405162461bcd60e51b81526004016108699190612ee5565b50600086815260046020908152604080832081518083018352815462ffffff16815260019091015481840152815180830190925283825291810183905290919060005b86811015611fa5576000611b528260016136b0565b90505b87811015611ca657888882818110611b6f57611b6f6133ee565b9050602002810190611b819190613404565b611b9290604081019060200161342f565b6001600160801b0316898984818110611bad57611bad6133ee565b9050602002810190611bbf9190613404565b611bd090604081019060200161342f565b6001600160801b0316141580611c5a5750888882818110611bf357611bf36133ee565b9050602002810190611c059190613404565b611c13906020810190613160565b6001600160a01b0316898984818110611c2e57611c2e6133ee565b9050602002810190611c409190613404565b611c4e906020810190613160565b6001600160a01b031614155b60405180604001604052806002815260200161323160f01b81525090611c935760405162461bcd60e51b81526004016108699190612ee5565b5080611c9e81613462565b915050611b55565b507f000000000000000000000000f41193e25408f652af878c47e4401a01b5e4b6826001600160a01b031663e50d420c898984818110611ce857611ce86133ee565b9050602002810190611cfa9190613404565b611d08906020810190613160565b8660200151611d8c8f8d8d88818110611d2357611d236133ee565b9050602002810190611d359190613404565b611d4690604081019060200161342f565b6001600160801b0316604080516001600160a01b038416602082015290810182905260009060600160405160208183030381529060405280519060200120905092915050565b8c8c87818110611d9e57611d9e6133ee565b9050602002810190611db09190613404565b611dbe9060408101906136ef565b6040518663ffffffff1660e01b8152600401611dde959493929190613735565b6040805180830381865afa158015611dfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e1e9190613781565b8051604080518082019091526002815261191960f11b6020820152919350611e595760405162461bcd60e51b81526004016108699190612ee5565b50602082015115611f93577f00000000000000000000000059e6cad5d7e7b9a26a45a1d1e74c7af0081700426001600160a01b0316632a71f953898984818110611ea557611ea56133ee565b9050602002810190611eb79190613404565b611ec5906020810190613160565b8a8a85818110611ed757611ed76133ee565b9050602002810190611ee99190613404565b611efa90604081019060200161342f565b602080870151908901516040516001600160e01b031960e087901b1681526001600160a01b0390941660048501526001600160801b03909216602484015260448301526064820152608401602060405180830381865afa158015611f62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f8691906136d6565b611f9090846136b0565b92505b80611f9d81613462565b915050611b3d565b50604080518082019091526002815261323360f01b602082015282611fdd5760405162461bcd60e51b81526004016108699190612ee5565b50871561203a57611fed826127f6565b600186018054601090612011908490600160801b90046001600160801b03166137bb565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550612085565b612043826127f6565b6002860180546000906120609084906001600160801b03166137bb565b92506101000a8154816001600160801b0302191690836001600160801b031602179055505b835460ff191688151517845561209a82612863565b84546001600160f81b03919091166101000260ff909116178455604051828152881515906001600160a01b038c16908b907f0c611e7b6ae0de26f4772260e1bbdb5f58cbb7c275fe2de14671968d29add8d69060200160405180910390a450505050505050505050565b6002546001600160a01b03163314610e125760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610869565b600280546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6060610b1e7f4161766520566f74696e67204d616368696e650000000000000000000000001360006128cc565b6060610b1e7f563100000000000000000000000000000000000000000000000000000000000260016128cc565b6001810154600090600160301b900464ffffffffff16810361222e57506000919050565b6001820154600160301b900464ffffffffff164264ffffffffff161161225657506001919050565b600182015460ff161561226b57506003919050565b506002919050565b919050565b600654604080516020810186905280820185905260608082018590528251808303909101815260808201928390526315713fb560e21b9092527f000000000000000000000000f6b99959f0b5e79e1cc7062e12af632ceb18ef0d6001600160a01b0316926355c4fed492612334927f0000000000000000000000000000000000000000000000000000000000000001927f0000000000000000000000009b24c168d6a76b5459b1d47071a54962a4df36c39290916084016137db565b60408051808303816000875af1158015612352573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123769190613808565b5050505050565b6040516381ac42b560e01b81526001600160a01b037f0000000000000000000000009aee0b04504cef83a65ac3f0e838d0593bcb2bc781166004830152602482018390526000917f000000000000000000000000f41193e25408f652af878c47e4401a01b5e4b682909116906381ac42b590604401602060405180830381865afa15801561240f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243391906136d6565b141560405180604001604052806002815260200161393560f01b8152509061246e5760405162461bcd60e51b81526004016108699190612ee5565b5050565b604080518082019091526002815261363760f01b60208201526001600160a01b0386166124b25760405162461bcd60e51b81526004016108699190612ee5565b5060008781526004602090815260408083206001015481516001600160a01b038a81168286015260098285015283518083038501815260608301855280519086012046608084015260a0808401919091528451808403909101815260c08301948590528051950194909420633943508360e21b909352909391927f000000000000000000000000f41193e25408f652af878c47e4401a01b5e4b682169063e50d420c90612589907f0000000000000000000000009aee0b04504cef83a65ac3f0e838d0593bcb2bc790879087908c9060c40161382c565b6040805180830381865afa1580156125a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125c99190613781565b60208101519091506001600160a01b038881169082161480156125f457506001600160a01b03881615155b604051806040016040528060028152602001611c9b60f11b8152509061262d5760405162461bcd60e51b81526004016108699190612ee5565b50610dd2898c8c8989611a2e565b600681905560405181907f3d1394ba0f6fca9c1e344f10a3efe1bfca63bc591232bb0d76755690f409450c90600090a250565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411156126a95750600091506003905082612733565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa1580156126fd573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661272957506000925060019150829050612733565b9250600091508190505b9450945094915050565b600082600381111561275157612751612d86565b0361275a575050565b600182600381111561276e5761276e612d86565b0361278c5760405163f645eedf60e01b815260040160405180910390fd5b60028260038111156127a0576127a0612d86565b036127c15760405163fce698f760e01b815260048101829052602401610869565b60038260038111156127d5576127d5612d86565b0361246e576040516335e2f38360e21b815260048101829052602401610869565b60006001600160801b0382111561285f5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610869565b5090565b60006001600160f81b0382111561285f5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663438206269747360c81b6064820152608401610869565b606060ff83146128e6576128df83612977565b905061072e565b8180546128f290613859565b80601f016020809104026020016040519081016040528092919081815260200182805461291e90613859565b801561296b5780601f106129405761010080835404028352916020019161296b565b820191906000526020600020905b81548152906001019060200180831161294e57829003601f168201915b5050505050905061072e565b60606000612984836129b6565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b600060ff8216601f81111561072e57604051632cd44ac360e21b815260040160405180910390fd5b6001600160a01b038116811461156d57600080fd5b60008060408385031215612a0657600080fd5b8235612a11816129de565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b0381118282101715612a5757612a57612a1f565b60405290565b604080519081016001600160401b0381118282101715612a5757612a57612a1f565b604051601f8201601f191681016001600160401b0381118282101715612aa757612aa7612a1f565b604052919050565b60006001600160401b03821115612ac857612ac8612a1f565b50601f01601f191660200190565b600082601f830112612ae757600080fd5b8135612afa612af582612aaf565b612a7f565b818152846020838601011115612b0f57600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215612b3e57600080fd5b81356001600160401b03811115612b5457600080fd5b612b6084828501612ad6565b949350505050565b600080600060608486031215612b7d57600080fd5b8335612b88816129de565b92506020840135915060408401356001600160401b03811115612baa57600080fd5b612bb686828701612ad6565b9150509250925092565b600060208284031215612bd257600080fd5b5035919050565b6000610120820190508251825260208301511515602083015264ffffffffff60408401511660408301526060830151612c1b606084018264ffffffffff169052565b506080830151612c34608084018264ffffffffff169052565b5060a0830151612c4f60a08401826001600160801b03169052565b5060c0830151612c6a60c08401826001600160801b03169052565b5060e083015160e083015261010080840151818401525092915050565b801515811461156d57600080fd5b60008083601f840112612ca757600080fd5b5081356001600160401b03811115612cbe57600080fd5b6020830191508360208260051b8501011115612cd957600080fd5b9250929050565b803560ff8116811461227357600080fd5b60008060008060008060008060e0898b031215612d0d57600080fd5b883597506020890135612d1f816129de565b96506040890135612d2f81612c87565b955060608901356001600160401b03811115612d4a57600080fd5b612d568b828c01612c95565b9096509450612d69905060808a01612ce0565b925060a0890135915060c089013590509295985092959890939650565b634e487b7160e01b600052602160045260246000fd5b60028110612dac57612dac612d86565b9052565b60005b83811015612dcb578181015183820152602001612db3565b50506000910152565b60008151808452612dec816020860160208601612db0565b601f01601f19169290920160200192915050565b612e0a8184612d9c565b604060208201526000612b606040830184612dd4565b600081518084526020808501945080840160005b83811015612e5057815187529582019590820190600101612e34565b509495945050505050565b60ff60f81b8816815260e060208201526000612e7a60e0830189612dd4565b8281036040840152612e8c8189612dd4565b606084018890526001600160a01b038716608085015260a0840186905283810360c08501529050612ebd8185612e20565b9a9950505050505050505050565b6020810160048310612edf57612edf612d86565b91905290565b602081526000612ef86020830184612dd4565b9392505050565b60008060008060608587031215612f1557600080fd5b843593506020850135612f2781612c87565b925060408501356001600160401b03811115612f4257600080fd5b612f4e87828801612c95565b95989497509550505050565b60008060008060008060a08789031215612f7357600080fd5b863595506020870135612f8581612c87565b94506040870135612f95816129de565b935060608701356001600160401b0380821115612fb157600080fd5b612fbd8a838b01612ad6565b94506080890135915080821115612fd357600080fd5b50612fe089828a01612c95565b979a9699509497509295939492505050565b600060808201868352602060018060a01b03808816828601526040871515818701526080606087015283875180865260a088019150848901955060005b8181101561305f5786518051861684528601516001600160801b031686840152958501959183019160010161302f565b50909b9a5050505050505050505050565b600080600080600080600080888a0361012081121561308e57600080fd5b8935985060208a01356130a0816129de565b975060408a01356130b0816129de565b965060608a01356130c081612c87565b955060808a01356001600160401b03808211156130dc57600080fd5b6130e88d838e01612ad6565b965060a08c01359150808211156130fe57600080fd5b5061310b8c828d01612c95565b909550935050606060bf198201121561312357600080fd5b5061312c612a35565b61313860c08b01612ce0565b815260e08a013560208201526101008a01356040820152809150509295985092959890939650565b60006020828403121561317257600080fd5b8135612ef8816129de565b6000806040838503121561319057600080fd5b50508035926020909101359150565b602081526000612ef86020830184612e20565b6000806000606084860312156131c757600080fd5b8351925060208401519150604084015162ffffff811681146131e857600080fd5b809150509250925092565b7f5375626d6974566f74652875696e743235362070726f706f73616c49642c616481527f647265737320766f7465722c626f6f6c20737570706f72742c566f74696e674160208201527f7373657457697468536c6f745b5d20766f74696e6741737365747357697468536040820152636c6f742960e01b606082015260008251613284816064850160208701612db0565b9190910160640192915050565b600080604083850312156132a457600080fd5b8251600281106132b357600080fd5b60208401519092506001600160401b038111156132cf57600080fd5b8301601f810185136132e057600080fd5b80516132ee612af582612aaf565b81815286602083850101111561330357600080fd5b613314826020830160208601612db0565b8093505050509250929050565b6040815260006133346040830185612dd4565b82810360208401526133468185612dd4565b95945050505050565b6133598185612d9c565b60606020820152600061336f6060830185612dd4565b82810360408401526133818185612dd4565b9695505050505050565b7f756e737570706f72746564206d65737361676520747970653a2000000000000081526000600283106133c0576133c0612d86565b5060f89190911b601a820152601b0190565b600082516133e4818460208701612db0565b9190910192915050565b634e487b7160e01b600052603260045260246000fd5b60008235605e198336030181126133e457600080fd5b6001600160801b038116811461156d57600080fd5b60006020828403121561344157600080fd5b8135612ef88161341a565b634e487b7160e01b600052601160045260246000fd5b6000600182016134745761347461344c565b5060010190565b815160009082906020808601845b838110156134a557815185529382019390820190600101613489565b50929695505050505050565b64ffffffffff8181168382160190808211156134cf576134cf61344c565b5092915050565b7f5375626d6974566f74654173526570726573656e7461746976652875696e743281527f35362070726f706f73616c49642c6164647265737320766f7465722c6164647260208201527f65737320726570726573656e7461746976652c626f6f6c20737570706f72742c60408201527f566f74696e67417373657457697468536c6f745b5d20766f74696e674173736560608201526a747357697468536c6f742960a81b60808201526000825161359481608b850160208701612db0565b91909101608b0192915050565b600080600080608085870312156135b757600080fd5b845193506020808601516135ca816129de565b809450506040808701516135dd81612c87565b60608801519094506001600160401b03808211156135fa57600080fd5b818901915089601f83011261360e57600080fd5b81518181111561362057613620612a1f565b61362e858260051b01612a7f565b818152858101925060069190911b83018501908b82111561364e57600080fd5b928501925b818410156136a05784848d03121561366b5760008081fd5b613673612a5d565b845161367e816129de565b81528487015161368d8161341a565b8188015283529284019291850191613653565b989b979a50959850505050505050565b8082018082111561072e5761072e61344c565b8181038181111561072e5761072e61344c565b6000602082840312156136e857600080fd5b5051919050565b6000808335601e1984360301811261370657600080fd5b8301803591506001600160401b0382111561372057600080fd5b602001915036819003821315612cd957600080fd5b60018060a01b038616815284602082015283604082015260806060820152816080820152818360a0830137600081830160a090810191909152601f909201601f19160101949350505050565b60006040828403121561379357600080fd5b61379b612a5d565b82516137a681612c87565b81526020928301519281019290925250919050565b6001600160801b038181168382160190808211156134cf576134cf61344c565b84815260018060a01b03841660208201528260408201526080606082015260006133816080830184612dd4565b6000806040838503121561381b57600080fd5b505080516020909101519092909150565b60018060a01b03851681528360208201528260408201526080606082015260006133816080830184612dd4565b600181811c9082168061386d57607f821691505b60208210810361388d57634e487b7160e01b600052602260045260246000fd5b5091905056fe566f74696e67417373657457697468536c6f74286164647265737320756e6465726c79696e6741737365742c75696e7431323820736c6f7429a2646970667358221220a9f31fcf5706f7525d64688572bc75d80377edd7fa1a8fc1f638b39dffa64a4a64736f6c63430008130033

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

000000000000000000000000f6b99959f0b5e79e1cc7062e12af632ceb18ef0d000000000000000000000000000000000000000000000000000000000003d090000000000000000000000000000000000000000000000000000000000000000100000000000000000000000059e6cad5d7e7b9a26a45a1d1e74c7af0081700420000000000000000000000009b24c168d6a76b5459b1d47071a54962a4df36c30000000000000000000000009aee0b04504cef83a65ac3f0e838d0593bcb2bc7

-----Decoded View---------------
Arg [0] : crossChainController (address): 0xF6B99959F0b5e79E1CC7062E12aF632CEb18eF0d
Arg [1] : gasLimit (uint256): 250000
Arg [2] : l1VotingPortalChainId (uint256): 1
Arg [3] : votingStrategy (address): 0x59e6CAD5d7E7b9A26a45a1d1E74C7aF008170042
Arg [4] : l1VotingPortal (address): 0x9b24C168d6A76b5459B1d47071a54962a4df36c3
Arg [5] : governance (address): 0x9AEE0B04504CeF83A65AC3f0e838D0593BCb2BC7

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 000000000000000000000000f6b99959f0b5e79e1cc7062e12af632ceb18ef0d
Arg [1] : 000000000000000000000000000000000000000000000000000000000003d090
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [3] : 00000000000000000000000059e6cad5d7e7b9a26a45a1d1e74c7af008170042
Arg [4] : 0000000000000000000000009b24c168d6a76b5459b1d47071a54962a4df36c3
Arg [5] : 0000000000000000000000009aee0b04504cef83a65ac3f0e838d0593bcb2bc7


Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

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