ETH Price: $2,416.55 (-0.33%)

Contract

0xaeD181779A8AAbD8Ce996949853FEA442C2CDB47
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Register Converg...155457102022-09-16 10:53:47750 days ago1663325627IN
0xaeD18177...42C2CDB47
0 ETH0.001131475.04588111
Register Converg...149230832022-06-07 21:43:31851 days ago1654638211IN
0xaeD18177...42C2CDB47
0 ETH0.0237721292.1986228
0x61012060149230832022-06-07 21:43:31851 days ago1654638211IN
 Create: ElementBridge
0 ETH0.3338891992.1986228

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ElementBridge

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 17 : ElementBridge.sol
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2020 Spilsbury Holdings Ltd
pragma solidity >=0.6.10 <=0.8.10;
pragma experimental ABIEncoderV2;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IVault, IAsset, PoolSpecialization} from "./interfaces/IVault.sol";
import {IPool} from "./interfaces/IPool.sol";
import {ITranche} from "./interfaces/ITranche.sol";
import {IDeploymentValidator} from "./interfaces/IDeploymentValidator.sol";
import {IERC20Permit, IERC20} from "../../interfaces/IERC20Permit.sol";
import {IWrappedPosition} from "./interfaces/IWrappedPosition.sol";
import {IRollupProcessor} from "../../interfaces/IRollupProcessor.sol";
import {MinHeap} from "./MinHeap.sol";
import {FullMath} from "../uniswapv3/libraries/FullMath.sol";

import {IDefiBridge} from "../../interfaces/IDefiBridge.sol";

import {AztecTypes} from "../../aztec/AztecTypes.sol";

/**
 * @title Element Bridge
 * @dev Smart contract responsible for depositing, managing and redeeming Defi interactions with the Element protocol
 */

contract ElementBridge is IDefiBridge {
    using MinHeap for MinHeap.MinHeapData;

    /*----------------------------------------
      ERROR TAGS
      ----------------------------------------*/
    error INVALID_TRANCHE();
    error INVALID_WRAPPED_POSITION();
    error INVALID_POOL();
    error INVALID_CALLER();
    error ASSET_IDS_NOT_EQUAL();
    error ASSET_NOT_ERC20();
    error INPUT_ASSETB_NOT_UNUSED();
    error OUTPUT_ASSETB_NOT_UNUSED();
    error INTERACTION_ALREADY_EXISTS();
    error POOL_NOT_FOUND();
    error UNKNOWN_NONCE();
    error BRIDGE_NOT_READY();
    error ALREADY_FINALISED();
    error TRANCHE_POSITION_MISMATCH();
    error TRANCHE_UNDERLYING_MISMATCH();
    error POOL_UNDERLYING_MISMATCH();
    error POOL_EXPIRY_MISMATCH();
    error TRANCHE_EXPIRY_MISMATCH();
    error VAULT_ADDRESS_VERIFICATION_FAILED();
    error VAULT_ADDRESS_MISMATCH();
    error TRANCHE_ALREADY_EXPIRED();
    error UNREGISTERED_POOL();
    error UNREGISTERED_POSITION();
    error UNREGISTERED_PAIR();
    error INVALID_TOKEN_BALANCE_RECEIVED();
    error INVALID_CHANGE_IN_BALANCE();
    error RECEIVED_LESS_THAN_LIMIT();

    /*----------------------------------------
      STRUCTS
      ----------------------------------------*/
    /**
     * @dev Contains information that describes a specific interaction
     *
     * @param quantityPT the quantity of element principal tokens that were purchased by this interaction
     * @param trancheAddress the address of the element tranche for which principal tokens were purchased
     * @param expiry the time of expiry of this interaction's tranche
     * @param finalised flag specifying whether this interaction has been finalised
     * @param failed flag specifying whether this interaction failed to be finalised at any point
     */
    struct Interaction {
        uint256 quantityPT;
        address trancheAddress;
        uint64 expiry;
        bool finalised;
        bool failed;
    }

    /**
     * @dev Contains information that describes a specific element pool
     *
     * @param poolId the unique Id associated with the element pool
     * @param trancheAddress the address of the element tranche for which principal tokens are traded in the pool
     * @param poolAddress the address of the pool contract
     * @param wrappedPositionAddress the address of the underlying wrapped position token associated with the pool/tranche
     */
    struct Pool {
        bytes32 poolId;
        address trancheAddress;
        address poolAddress;
        address wrappedPositionAddress;
    }

    enum TrancheRedemptionStatus {
        NOT_REDEEMED,
        REDEMPTION_FAILED,
        REDEMPTION_SUCCEEDED
    }

    /**
     * @dev Contains information for managing all funds deposited/redeemed with a specific element tranche
     *
     * @param quantityTokensHeld total quantity of principal tokens purchased for the tranche
     * @param quantityAssetRedeemed total quantity of underlying tokens received from the element tranche on expiry
     * @param quantityAssetRemaining the current remainning quantity of underlying tokens held by the contract
     * @param numDeposits the total number of deposits (interactions) against the give tranche
     * @param numFinalised the current number of interactions against this tranche that have been finalised
     * @param redemptionStatus value describing the redemption status of the tranche
     */
    struct TrancheAccount {
        uint256 quantityTokensHeld;
        uint256 quantityAssetRedeemed;
        uint256 quantityAssetRemaining;
        uint32 numDeposits;
        uint32 numFinalised;
        TrancheRedemptionStatus redemptionStatus;
    }

    // Tranche factory address for Tranche contract address derivation
    address private immutable trancheFactory;
    // Tranche bytecode hash for Tranche contract address derivation.
    // This is constant as long as Tranche does not implement non-constant constructor arguments.
    bytes32 private immutable trancheBytecodeHash; // = 0xf481a073666136ab1f5e93b296e84df58092065256d0db23b2d22b62c68e978d;

    // cache of all of our Defi interactions. keyed on nonce
    mapping(uint256 => Interaction) public interactions;

    // cahce of all expiry values against the underlying asset address
    mapping(address => uint64[]) public assetToExpirys;

    // cache of all pools we have been configured to interact with
    mapping(uint256 => Pool) public pools;

    // cahce of all of our tranche accounts
    mapping(address => TrancheAccount) private trancheAccounts;

    // mapping containing the block number in which a tranche was configured
    mapping(address => uint256) private trancheDeploymentBlockNumbers;

    // the aztec rollup processor contract
    address public immutable rollupProcessor;

    // the balancer contract
    address private immutable balancerAddress;

    // the address of the element deployment validator contract
    address private immutable elementDeploymentValidatorAddress;

    // data structures used to manage the ongoing interaction deposit/redemption cycle
    MinHeap.MinHeapData private heap;
    mapping(uint64 => uint256[]) private expiryToNonce;

    // 48 hours in seconds, usd for calculating speeedbump expiries
    uint256 internal constant FORTY_EIGHT_HOURS = 172800;

    uint256 internal constant MAX_UINT = type(uint256).max;

    uint256 internal constant MIN_GAS_FOR_CHECK_AND_FINALISE = 40000;
    uint256 internal constant MIN_GAS_FOR_FUNCTION_COMPLETION = 2000;
    uint256 internal constant MIN_GAS_FOR_FAILED_INTERACTION = 20000;
    uint256 internal constant MIN_GAS_FOR_EXPIRY_REMOVAL = 25000;

    // event emitted on every successful convert call
    event LogConvert(uint256 indexed nonce, uint256 totalInputValue, int64 gasUsed);

    // event emitted on every attempt to finalise, successful or otherwise
    event LogFinalise(uint256 indexed nonce, bool success, string message, int64 gasUsed);

    // event emitted on wvery newly configured pool
    event LogPoolAdded(address poolAddress, address wrappedPositionAddress, uint64 expiry);

    /**
     * @dev Constructor
     * @param _rollupProcessor the address of the rollup contract
     * @param _trancheFactory the address of the element tranche factor contract
     * @param _trancheBytecodeHash the hash of the bytecode of the tranche contract, used for tranche contract address derivation
     * @param _balancerVaultAddress the address of the balancer router contract
     * @param _elementDeploymentValidatorAddress the address of the element deployment validator contract
     */
    constructor(
        address _rollupProcessor,
        address _trancheFactory,
        bytes32 _trancheBytecodeHash,
        address _balancerVaultAddress,
        address _elementDeploymentValidatorAddress
    ) {
        rollupProcessor = _rollupProcessor;
        trancheFactory = _trancheFactory;
        trancheBytecodeHash = _trancheBytecodeHash;
        balancerAddress = _balancerVaultAddress;
        elementDeploymentValidatorAddress = _elementDeploymentValidatorAddress;
        heap.initialise(100);
    }

    /**
     * @dev Function for retrieving the available expiries for the given asset
     * @param asset the asset address being queried
     * @return assetExpiries the list of available expiries for the provided asset address
     */
    function getAssetExpiries(address asset) public view returns (uint64[] memory assetExpiries) {
        assetExpiries = assetToExpirys[asset];
    }

    /// @dev Registers a convergent pool with the contract, setting up a new asset/expiry element tranche
    /// @param _convergentPool The pool's address
    /// @param _wrappedPosition The element wrapped position contract's address
    /// @param _expiry The expiry of the tranche being configured
    function registerConvergentPoolAddress(
        address _convergentPool,
        address _wrappedPosition,
        uint64 _expiry
    ) external {
        checkAndStorePoolSpecification(_convergentPool, _wrappedPosition, _expiry);
    }

    /// @dev This internal function produces the deterministic create2
    ///      address of the Tranche contract from a wrapped position contract and expiry
    /// @param position The wrapped position contract address
    /// @param expiry The expiration time of the tranche as a uint256
    /// @return trancheContract derived Tranche contract address
    function deriveTranche(address position, uint256 expiry) internal view virtual returns (address trancheContract) {
        bytes32 salt = keccak256(abi.encodePacked(position, expiry));
        bytes32 addressBytes = keccak256(abi.encodePacked(bytes1(0xff), trancheFactory, salt, trancheBytecodeHash));
        trancheContract = address(uint160(uint256(addressBytes)));
    }

    struct PoolSpec {
        uint256 poolExpiry;
        bytes32 poolId;
        address underlyingAsset;
        address trancheAddress;
        address tranchePosition;
        address trancheUnderlying;
        address poolUnderlying;
        address poolVaultAddress;
    }

    /// @dev Validates and stores a convergent pool specification
    /// @param poolAddress The pool's address
    /// @param wrappedPositionAddress The element wrapped position contract's address
    /// @param expiry The expiry of the tranche being configured
    function checkAndStorePoolSpecification(
        address poolAddress,
        address wrappedPositionAddress,
        uint64 expiry
    ) internal {
        PoolSpec memory poolSpec;
        IWrappedPosition wrappedPosition = IWrappedPosition(wrappedPositionAddress);
        // this underlying asset should be the real asset i.e. DAI stablecoin etc
        try wrappedPosition.token() returns (IERC20 wrappedPositionToken) {
            poolSpec.underlyingAsset = address(wrappedPositionToken);
        } catch {
            revert INVALID_WRAPPED_POSITION();
        }
        // this should be the address of the Element tranche for the asset/expiry pair
        poolSpec.trancheAddress = deriveTranche(wrappedPositionAddress, expiry);
        // get the wrapped position held in the tranche to cross check against that provided
        ITranche tranche = ITranche(poolSpec.trancheAddress);
        try tranche.position() returns (IERC20 tranchePositionToken) {
            poolSpec.tranchePosition = address(tranchePositionToken);
        } catch {
            revert INVALID_TRANCHE();
        }
        // get the underlying held in the tranche to cross check against that provided
        try tranche.underlying() returns (IERC20 trancheUnderlying) {
            poolSpec.trancheUnderlying = address(trancheUnderlying);
        } catch {
            revert INVALID_TRANCHE();
        }
        // get the tranche expiry to cross check against that provided
        uint64 trancheExpiry = 0;
        try tranche.unlockTimestamp() returns (uint256 trancheUnlock) {
            trancheExpiry = uint64(trancheUnlock);
        } catch {
            revert INVALID_TRANCHE();
        }
        if (trancheExpiry != expiry) {
            revert TRANCHE_EXPIRY_MISMATCH();
        }

        if (poolSpec.tranchePosition != wrappedPositionAddress) {
            revert TRANCHE_POSITION_MISMATCH();
        }
        if (poolSpec.trancheUnderlying != poolSpec.underlyingAsset) {
            revert TRANCHE_UNDERLYING_MISMATCH();
        }
        // get the pool underlying to cross check against that provided
        IPool pool = IPool(poolAddress);
        try pool.underlying() returns (IERC20 poolUnderlying) {
            poolSpec.poolUnderlying = address(poolUnderlying);
        } catch {
            revert INVALID_POOL();
        }
        // get the pool expiry to cross check against that provided
        try pool.expiration() returns (uint256 poolExpiry) {
            poolSpec.poolExpiry = poolExpiry;
        } catch {
            revert INVALID_POOL();
        }
        // get the vault associated with the pool
        try pool.getVault() returns (IVault poolVault) {
            poolSpec.poolVaultAddress = address(poolVault);
        } catch {
            revert INVALID_POOL();
        }
        // get the pool id associated with the pool
        try pool.getPoolId() returns (bytes32 poolId) {
            poolSpec.poolId = poolId;
        } catch {
            revert INVALID_POOL();
        }
        if (poolSpec.poolUnderlying != poolSpec.underlyingAsset) {
            revert POOL_UNDERLYING_MISMATCH();
        }
        if (poolSpec.poolExpiry != expiry) {
            revert POOL_EXPIRY_MISMATCH();
        }
        //verify that the vault address is equal to our balancer address
        if (poolSpec.poolVaultAddress != balancerAddress) {
            revert VAULT_ADDRESS_VERIFICATION_FAILED();
        }

        // retrieve the pool address for the given pool id from balancer
        // then test it against that given to us
        IVault balancerVault = IVault(balancerAddress);
        (address balancersPoolAddress, ) = balancerVault.getPool(poolSpec.poolId);
        if (poolAddress != balancersPoolAddress) {
            revert VAULT_ADDRESS_MISMATCH();
        }

        // verify with Element that the provided contracts are registered
        validatePositionAndPoolAddressesWithElementRegistry(wrappedPositionAddress, poolAddress);

        // we store the pool information against a hash of the asset and expiry
        uint256 assetExpiryHash = hashAssetAndExpiry(poolSpec.underlyingAsset, trancheExpiry);
        pools[assetExpiryHash] = Pool(poolSpec.poolId, poolSpec.trancheAddress, poolAddress, wrappedPositionAddress);
        uint64[] storage expiriesForAsset = assetToExpirys[poolSpec.underlyingAsset];
        uint256 expiryIndex = 0;
        while (expiryIndex < expiriesForAsset.length && expiriesForAsset[expiryIndex] != trancheExpiry) {
            unchecked {
                ++expiryIndex;
            }
        }
        if (expiryIndex == expiriesForAsset.length) {
            expiriesForAsset.push(trancheExpiry);
        }
        setTrancheDeploymentBlockNumber(poolSpec.trancheAddress);

        // initialising the expiry -> nonce mapping here like this reduces a chunk of gas later when we start to add interactions for this expiry
        uint256[] storage nonces = expiryToNonce[trancheExpiry];
        if (nonces.length == 0) {
            expiryToNonce[trancheExpiry].push(MAX_UINT);
        }
        emit LogPoolAdded(poolAddress, wrappedPositionAddress, trancheExpiry);
    }

    /**
     * @dev Sets the current block number as the block in which the given tranche was first configured
     * Only stores the block number if this is the first time this tranche has been configured
     * @param trancheAddress the address of the tranche against which to store the current block number
     */
    function setTrancheDeploymentBlockNumber(address trancheAddress) internal {
        uint256 trancheDeploymentBlock = trancheDeploymentBlockNumbers[trancheAddress];
        if (trancheDeploymentBlock == 0) {
            // only set the deployment block on the first time this tranche is configured
            trancheDeploymentBlockNumbers[trancheAddress] = block.number;
        }
    }

    /**
     * @dev Returns the block number in which a tranche was first configured on the bridge based on the nonce of an interaction in that tranche
     * @param interactionNonce the nonce of the interaction to query
     * @return blockNumber the number of the block in which the tranche was first configured
     */
    function getTrancheDeploymentBlockNumber(uint256 interactionNonce) public view returns (uint256 blockNumber) {
        Interaction storage interaction = interactions[interactionNonce];
        if (interaction.expiry == 0) {
            revert UNKNOWN_NONCE();
        }
        blockNumber = trancheDeploymentBlockNumbers[interaction.trancheAddress];
    }

    /**
     * @dev Verifies that the given pool and wrapped position addresses are registered in the Element deployment validator
     * Reverts if addresses don't validate successfully
     * @param wrappedPosition address of a wrapped position contract
     * @param pool address of a balancer pool contract
     */
    function validatePositionAndPoolAddressesWithElementRegistry(address wrappedPosition, address pool) internal {
        IDeploymentValidator validator = IDeploymentValidator(elementDeploymentValidatorAddress);
        if (!validator.checkPoolValidation(pool)) {
            revert UNREGISTERED_POOL();
        }
        if (!validator.checkWPValidation(wrappedPosition)) {
            revert UNREGISTERED_POSITION();
        }
        if (!validator.checkPairValidation(wrappedPosition, pool)) {
            revert UNREGISTERED_PAIR();
        }
    }

    /// @dev Produces a hash of the given asset and expiry value
    /// @param asset The asset address
    /// @param expiry The expiry value
    /// @return hashValue The resulting hash value
    function hashAssetAndExpiry(address asset, uint64 expiry) public pure returns (uint256 hashValue) {
        hashValue = uint256(keccak256(abi.encodePacked(asset, uint256(expiry))));
    }

    struct ConvertArgs {
        address inputAssetAddress;
        uint256 totalInputValue;
        uint256 interactionNonce;
        uint64 auxData;
    }

    /**
     * @dev Function to add a new interaction to the bridge
     * Converts the amount of input asset given to the market determined amount of tranche asset
     * @param inputAssetA The type of input asset for the new interaction
     * @param outputAssetA The type of output asset for the new interaction
     * @param totalInputValue The amount the the input asset provided in this interaction
     * @param interactionNonce The nonce value for this interaction
     * @param auxData The expiry value for this interaction
     * @return outputValueA The interaction's first ouptut value after this call - will be 0
     * @return outputValueB The interaction's second ouptut value after this call - will be 0
     * @return isAsync Flag specifying if this interaction is asynchronous - will be true
     */
    function convert(
        AztecTypes.AztecAsset calldata inputAssetA,
        AztecTypes.AztecAsset calldata inputAssetB,
        AztecTypes.AztecAsset calldata outputAssetA,
        AztecTypes.AztecAsset calldata outputAssetB,
        uint256 totalInputValue,
        uint256 interactionNonce,
        uint64 auxData,
        address
    )
        external
        payable
        override
        returns (
            uint256 outputValueA,
            uint256 outputValueB,
            bool isAsync
        )
    {
        int64 gasAtStart = int64(int256(gasleft()));
        int64 gasUsed = 0;
        // ### INITIALIZATION AND SANITY CHECKS
        if (msg.sender != rollupProcessor) {
            revert INVALID_CALLER();
        }
        if (inputAssetA.id != outputAssetA.id) {
            revert ASSET_IDS_NOT_EQUAL();
        }
        if (inputAssetA.assetType != AztecTypes.AztecAssetType.ERC20) {
            revert ASSET_NOT_ERC20();
        }
        if (inputAssetB.assetType != AztecTypes.AztecAssetType.NOT_USED) {
            revert INPUT_ASSETB_NOT_UNUSED();
        }
        if (outputAssetB.assetType != AztecTypes.AztecAssetType.NOT_USED) {
            revert OUTPUT_ASSETB_NOT_UNUSED();
        }
        if (interactions[interactionNonce].expiry != 0) {
            revert INTERACTION_ALREADY_EXISTS();
        }

        // operation is asynchronous
        isAsync = true;
        outputValueA = 0;
        outputValueB = 0;

        // capture the provided arguments in a struct to prevent 'stack too deep' errors
        ConvertArgs memory convertArgs = ConvertArgs({
            inputAssetAddress: inputAssetA.erc20Address,
            totalInputValue: totalInputValue,
            interactionNonce: interactionNonce,
            auxData: auxData
        });

        // retrieve the appropriate pool for this interaction and verify that it exists
        Pool storage pool = pools[hashAssetAndExpiry(convertArgs.inputAssetAddress, convertArgs.auxData)];
        address trancheAddress = pool.trancheAddress;
        if (trancheAddress == address(0)) {
            revert POOL_NOT_FOUND();
        }
        ITranche tranche = ITranche(trancheAddress);
        uint64 trancheExpiry = uint64(tranche.unlockTimestamp());
        if (block.timestamp >= trancheExpiry) {
            revert TRANCHE_ALREADY_EXPIRED();
        }

        // execute the swap on balancer
        uint256 principalTokensAmount = exchangeAssetForTrancheTokens(
            convertArgs.inputAssetAddress,
            pool,
            convertArgs.totalInputValue
        );
        // store the tranche that underpins our interaction, the expiry and the number of received tokens against the nonce
        Interaction storage newInteraction = interactions[convertArgs.interactionNonce];
        newInteraction.quantityPT = principalTokensAmount;
        newInteraction.trancheAddress = trancheAddress;
        newInteraction.expiry = trancheExpiry;

        // add the nonce and expiry to our expiry heap
        addNonceAndExpiryToNonceMapping(convertArgs.interactionNonce, trancheExpiry);
        // increase our tranche account deposits and holdings
        // other members are left as their initial values (all zeros)
        TrancheAccount storage trancheAccount = trancheAccounts[trancheAddress];
        trancheAccount.quantityTokensHeld += principalTokensAmount;
        unchecked {
            trancheAccount.numDeposits++;
            gasUsed = gasAtStart - int64(int256(gasleft()));
        }
        emit LogConvert(convertArgs.interactionNonce, convertArgs.totalInputValue, gasUsed);
        finaliseExpiredInteractions(MIN_GAS_FOR_FUNCTION_COMPLETION);
        // we need to get here with MIN_GAS_FOR_FUNCTION_COMPLETION gas to exit.
    }

    /**
     * @dev Function to exchange the input asset for tranche tokens on Balancer
     * @param inputAsset the address of the asset we want to swap
     * @param pool storage struct containing details of the pool we wish to use for the swap
     * @param inputQuantity the quantity of the input asset we wish to swap
     * @return quantityReceived amount of tokens recieved
     */
    function exchangeAssetForTrancheTokens(
        address inputAsset,
        Pool storage pool,
        uint256 inputQuantity
    ) internal returns (uint256 quantityReceived) {
        IVault.SingleSwap memory singleSwap = IVault.SingleSwap({
            poolId: pool.poolId, // the id of the pool we want to use
            kind: IVault.SwapKind.GIVEN_IN, // We are exchanging a given number of input tokens
            assetIn: IAsset(inputAsset), // the input asset for the swap
            assetOut: IAsset(pool.trancheAddress), // the tranche token address as the output asset
            amount: inputQuantity, // the total amount of input asset we wish to swap
            userData: "0x00" // set to 0 as per the docs, this is unused in current balancer pools
        });
        IVault.FundManagement memory fundManagement = IVault.FundManagement({
            sender: address(this), // the bridge has already received the tokens from the rollup so it owns totalInputValue of inputAssetA
            fromInternalBalance: false,
            recipient: payable(address(this)), // we want the output tokens transferred back to us
            toInternalBalance: false
        });

        // approve the transfer of tokens to the balancer address
        ERC20(inputAsset).approve(balancerAddress, inputQuantity);

        uint256 trancheTokenQuantityBefore = ERC20(pool.trancheAddress).balanceOf(address(this));
        quantityReceived = IVault(balancerAddress).swap(
            singleSwap,
            fundManagement,
            inputQuantity, // we won't accept less than 1 output token per input token
            block.timestamp
        );

        uint256 trancheTokenQuantityAfter = ERC20(pool.trancheAddress).balanceOf(address(this));
        // ensure we haven't lost tokens!
        if (trancheTokenQuantityAfter < trancheTokenQuantityBefore) {
            revert INVALID_CHANGE_IN_BALANCE();
        }
        // change in balance must be >= 0 here
        uint256 changeInBalance = trancheTokenQuantityAfter - trancheTokenQuantityBefore;
        // ensure the change in balance matches that reported to us
        if (changeInBalance != quantityReceived) {
            revert INVALID_TOKEN_BALANCE_RECEIVED();
        }
        // ensure we received at least the limit we placed
        if (quantityReceived < inputQuantity) {
            revert RECEIVED_LESS_THAN_LIMIT();
        }
    }

    /**
     * @dev Function to attempt finalising of as many interactions as possible within the specified gas limit
     * Continue checking for and finalising interactions until we expend the available gas
     * @param gasFloor The amount of gas that needs to remain after this call has completed
     */
    function finaliseExpiredInteractions(uint256 gasFloor) internal {
        // check and finalise interactions until we don't have enough gas left to reliably update our state without risk of reverting the entire transaction
        // gas left must be enough for check for next expiry, finalise and leave this function without breaching gasFloor
        uint256 gasLoopCondition = MIN_GAS_FOR_CHECK_AND_FINALISE + MIN_GAS_FOR_FUNCTION_COMPLETION + gasFloor;
        uint256 ourGasFloor = MIN_GAS_FOR_FUNCTION_COMPLETION + gasFloor;
        while (gasleft() > gasLoopCondition) {
            // check the heap to see if we can finalise an expired transaction
            // we provide a gas floor to the function which will enable us to leave this function without breaching our gasFloor
            (bool expiryAvailable, uint256 nonce) = checkForNextInteractionToFinalise(ourGasFloor);
            if (!expiryAvailable) {
                break;
            }
            // make sure we will have at least ourGasFloor gas after the finalise in order to exit this function
            uint256 gasRemaining = gasleft();
            if (gasRemaining <= ourGasFloor) {
                break;
            }
            uint256 gasForFinalise = gasRemaining - ourGasFloor;
            // make the call to finalise the interaction with the gas limit
            try IRollupProcessor(rollupProcessor).processAsyncDefiInteraction{gas: gasForFinalise}(nonce) returns (
                bool interactionCompleted
            ) {
                // no need to do anything here, we just need to know that the call didn't throw
            } catch {
                break;
            }
        }
    }

    /**
     * @dev Function to finalise an interaction
     * Converts the held amount of tranche asset for the given interaction into the output asset
     * @param interactionNonce The nonce value for the interaction that should be finalised
     */
    function finalise(
        AztecTypes.AztecAsset calldata,
        AztecTypes.AztecAsset calldata,
        AztecTypes.AztecAsset calldata outputAssetA,
        AztecTypes.AztecAsset calldata,
        uint256 interactionNonce,
        uint64
    )
        external
        payable
        override
        returns (
            uint256 outputValueA,
            uint256 outputValueB,
            bool interactionCompleted
        )
    {
        int64 gasAtStart = int64(int256(gasleft()));
        int64 gasUsed = 0;
        if (msg.sender != rollupProcessor) {
            revert INVALID_CALLER();
        }
        // retrieve the interaction and verify it's ready for finalising
        Interaction storage interaction = interactions[interactionNonce];
        if (interaction.expiry == 0) {
            revert UNKNOWN_NONCE();
        }
        if (interaction.expiry >= block.timestamp) {
            revert BRIDGE_NOT_READY();
        }
        if (interaction.finalised) {
            revert ALREADY_FINALISED();
        }

        TrancheAccount storage trancheAccount = trancheAccounts[interaction.trancheAddress];
        // cache a couple of frequently used values from the tranche account here
        uint32 numDepositsIntoTranche = trancheAccount.numDeposits;
        uint256 trancheTokensHeld = trancheAccount.quantityTokensHeld;
        if (numDepositsIntoTranche == 0) {
            // shouldn't be possible, this means we have had no deposits against this tranche
            setInteractionAsFailure(interaction, interactionNonce, "NO_DEPOSITS_2", 0);
            popInteractionFromNonceMapping(interaction, interactionNonce);
            return (0, 0, false);
        }

        // we only want to redeem the tranche if it hasn't previously successfully been redeemed
        if (trancheAccount.redemptionStatus != TrancheRedemptionStatus.REDEMPTION_SUCCEEDED) {
            // tranche not redeemed, we need to withdraw the principal
            // convert the tokens back to underlying using the tranche
            ITranche tranche = ITranche(interaction.trancheAddress);
            try tranche.withdrawPrincipal(trancheTokensHeld, address(this)) returns (uint256 valueRedeemed) {
                trancheAccount.quantityAssetRedeemed = valueRedeemed;
                trancheAccount.quantityAssetRemaining = valueRedeemed;
                trancheAccount.redemptionStatus = TrancheRedemptionStatus.REDEMPTION_SUCCEEDED;
            } catch Error(string memory errorMessage) {
                unchecked {
                    gasUsed = gasAtStart - int64(int256(gasleft()));
                }
                setInteractionAsFailure(interaction, interactionNonce, errorMessage, gasUsed);
                trancheAccount.redemptionStatus = TrancheRedemptionStatus.REDEMPTION_FAILED;
                popInteractionFromNonceMapping(interaction, interactionNonce);
                return (0, 0, false);
            } catch {
                unchecked {
                    gasUsed = gasAtStart - int64(int256(gasleft()));
                }
                setInteractionAsFailure(interaction, interactionNonce, "WITHDRAW_ERR", gasUsed);
                trancheAccount.redemptionStatus = TrancheRedemptionStatus.REDEMPTION_FAILED;
                popInteractionFromNonceMapping(interaction, interactionNonce);
                return (0, 0, false);
            }
        }

        // at this point, the tranche must have been redeemed and we can allocate proportionately to this interaction
        uint256 amountToAllocate = 0;
        if (trancheTokensHeld == 0) {
            // what can we do here?
            // we seem to have 0 total principle tokens so we can't apportion the output asset as it must be the case that each interaction purchased 0
            // we know that the number of deposits against this tranche is > 0 as we check further up this function
            // so we will have to divide the output asset, if there is any, equally
            amountToAllocate = trancheAccount.quantityAssetRedeemed / numDepositsIntoTranche;
        } else {
            // apportion the output asset based on the interaction's holding of the principle token
            // protects against phantom overflow in the operation of
            // amountToAllocate = (trancheAccount.quantityAssetRedeemed * interaction.quantityPT) / trancheTokensHeld;
            amountToAllocate = FullMath.mulDiv(
                trancheAccount.quantityAssetRedeemed,
                interaction.quantityPT,
                trancheTokensHeld
            );
        }
        // numDeposits and numFinalised are uint32 types, so easily within range for an int256
        int256 numRemainingInteractionsForTranche = int256(uint256(numDepositsIntoTranche)) -
            int256(uint256(trancheAccount.numFinalised));
        // the number of remaining interactions should never be less than 1 here, but test for <= 1 to ensure we catch all possibilities
        if (numRemainingInteractionsForTranche <= 1 || amountToAllocate > trancheAccount.quantityAssetRemaining) {
            // if there are no more interactions to finalise after this then allocate all the remaining
            // likewise if we have managed to allocate more than the remaining
            amountToAllocate = trancheAccount.quantityAssetRemaining;
        }
        trancheAccount.quantityAssetRemaining -= amountToAllocate;
        unchecked {
            trancheAccount.numFinalised++;
        }

        // approve the transfer of funds back to the rollup contract
        ERC20(outputAssetA.erc20Address).approve(rollupProcessor, amountToAllocate);
        interaction.finalised = true;
        popInteractionFromNonceMapping(interaction, interactionNonce);
        outputValueA = amountToAllocate;
        outputValueB = 0;
        interactionCompleted = true;
        unchecked {
            gasUsed = gasAtStart - int64(int256(gasleft()));
        }
        emit LogFinalise(interactionNonce, interactionCompleted, "", gasUsed);
    }

    /**
     * @dev Function to mark an interaction as having failed and publish a finalise event
     * @param interaction The interaction that failed
     * @param interactionNonce The nonce of the failed interaction
     * @param message The reason for failure
     */
    function setInteractionAsFailure(
        Interaction storage interaction,
        uint256 interactionNonce,
        string memory message,
        int64 gasUsed
    ) internal {
        interaction.failed = true;
        emit LogFinalise(interactionNonce, false, message, gasUsed);
    }

    /**
     * @dev Function to add an interaction nonce and expiry to the heap data structures
     * @param nonce The nonce of the interaction to be added
     * @param expiry The expiry of the interaction to be added
     * @return expiryAdded Flag specifying whether the interactions expiry was added to the heap
     */
    function addNonceAndExpiryToNonceMapping(uint256 nonce, uint64 expiry) internal returns (bool expiryAdded) {
        // get the set of nonces already against this expiry
        // check for the MAX_UINT placeholder nonce that exists to reduce gas costs at this point in the code
        uint256[] storage nonces = expiryToNonce[expiry];
        uint256 noncesLength = nonces.length;
        if (noncesLength == 1 && nonces[0] == MAX_UINT) {
            nonces[0] = nonce;
        } else {
            nonces.push(nonce);
            unchecked {
                noncesLength++;
            }
        }
        // is this the first time this expiry has been requested?
        // if so then add it to our expiry heap
        if (noncesLength == 1) {
            heap.add(expiry);
            expiryAdded = true;
        }
    }

    /**
     * @dev Function to remove an interaction from the heap data structures
     * @param interaction The interaction should be removed
     * @param interactionNonce The nonce of the interaction to be removed
     * @return expiryRemoved Flag specifying whether the interactions expiry was removed from the heap
     */
    function popInteractionFromNonceMapping(Interaction storage interaction, uint256 interactionNonce)
        internal
        returns (bool expiryRemoved)
    {
        uint64 expiry = interaction.expiry;
        uint256[] storage nonces = expiryToNonce[expiry];
        uint256 noncesLength = nonces.length;
        if (noncesLength == 0) {
            return false;
        }
        uint256 index = noncesLength - 1;
        while (index > 0 && nonces[index] != interactionNonce) {
            unchecked {
                --index;
            }
        }
        if (nonces[index] != interactionNonce) {
            return false;
        }
        if (index != noncesLength - 1) {
            nonces[index] = nonces[noncesLength - 1];
        }
        nonces.pop();

        // if there are no more nonces left for this expiry then remove it from the heap
        // checking if length == 1 to account for the pop.
        if (noncesLength == 1) {
            heap.remove(expiry);
            delete expiryToNonce[expiry];
            return true;
        }
        return false;
    }

    /**
     * @dev Function to determine if we are able to finalise an interaction
     * @param gasFloor The amount of gas that needs to remain after this call has completed
     * @return expiryAvailable Flag specifying whether an expiry is available to be finalised
     * @return nonce The next interaction nonce to be finalised
     */
    function checkForNextInteractionToFinalise(uint256 gasFloor)
        internal
        returns (bool expiryAvailable, uint256 nonce)
    {
        // do we have any expiries and if so is the earliest expiry now expired
        if (heap.size() == 0) {
            return (false, 0);
        }
        // retrieve the minimum (oldest) expiry and determine if it is in the past
        uint64 nextExpiry = heap.min();
        if (nextExpiry >= block.timestamp) {
            // oldest expiry is still not expired
            return (false, 0);
        }
        // we have some expired interactions
        uint256[] storage nonces = expiryToNonce[nextExpiry];
        uint256 noncesLength = nonces.length;
        uint256 minGasForLoop = (gasFloor + MIN_GAS_FOR_FAILED_INTERACTION);
        while (noncesLength > 0 && gasleft() >= minGasForLoop) {
            uint256 nextNonce = nonces[noncesLength - 1];
            if (nextNonce == MAX_UINT) {
                // this shouldn't happen, this value is the placeholder for reducing gas costs on convert
                // we just need to pop and continue
                nonces.pop();
                unchecked {
                    noncesLength--;
                }
                continue;
            }
            Interaction storage interaction = interactions[nextNonce];
            if (interaction.expiry == 0 || interaction.finalised || interaction.failed) {
                // this shouldn't happen, suggests the interaction has been finalised already but not removed from the sets of nonces for this expiry
                // remove the nonce and continue searching
                nonces.pop();
                unchecked {
                    noncesLength--;
                }
                continue;
            }
            // we have valid interaction for the next expiry, check if it can be finalised
            (bool canBeFinalised, string memory message) = interactionCanBeFinalised(interaction);
            if (!canBeFinalised) {
                // can't be finalised, add to failures and pop from nonces
                setInteractionAsFailure(interaction, nextNonce, message, 0);
                nonces.pop();
                unchecked {
                    noncesLength--;
                }
                continue;
            }
            return (true, nextNonce);
        }

        // if we don't have enough gas to remove the expiry, it will be removed next time
        if (noncesLength == 0 && gasleft() >= (gasFloor + MIN_GAS_FOR_EXPIRY_REMOVAL)) {
            // if we are here then we have run out of nonces for this expiry so pop from the heap
            heap.remove(nextExpiry);
        }
        return (false, 0);
    }

    /**
     * @dev Determine if an interaction can be finalised
     * Performs a variety of check on the tranche and tranche account to determine
     * a. if the tranche has already been redeemed
     * b. if the tranche is currently under a speedbump
     * c. if the yearn vault has sufficient balance to support tranche redemption
     * @param interaction The interaction to be finalised
     * @return canBeFinalised Flag specifying whether the interaction can be finalised
     * @return message Message value giving the reason why an interaction can't be finalised
     */
    function interactionCanBeFinalised(Interaction storage interaction)
        internal
        returns (bool canBeFinalised, string memory message)
    {
        TrancheAccount storage trancheAccount = trancheAccounts[interaction.trancheAddress];
        if (trancheAccount.numDeposits == 0) {
            // shouldn't happen, suggests we don't have an account for this tranche!
            return (false, "NO_DEPOSITS_1");
        }
        if (trancheAccount.redemptionStatus == TrancheRedemptionStatus.REDEMPTION_FAILED) {
            return (false, "REDEMPTION_FAILED");
        }
        // determine if the tranche has already been redeemed
        if (trancheAccount.redemptionStatus == TrancheRedemptionStatus.REDEMPTION_SUCCEEDED) {
            // tranche was previously redeemed
            if (trancheAccount.quantityAssetRemaining == 0) {
                // this is a problem. we have already allocated out all of the redeemed assets!
                return (false, "FULLY_ALLOCATED");
            }
            // this interaction can be finalised. we don't need to redeem the tranche, we just need to allocate the redeemed asset
            return (true, "");
        }
        // tranche hasn't been redeemed, now check to see if we can redeem it
        ITranche tranche = ITranche(interaction.trancheAddress);
        uint256 speedbump = tranche.speedbump();
        if (speedbump != 0) {
            uint256 newExpiry = speedbump + FORTY_EIGHT_HOURS;
            if (newExpiry > block.timestamp) {
                // a speedbump is in force for this tranche and it is beyond the current time
                trancheAccount.redemptionStatus = TrancheRedemptionStatus.REDEMPTION_FAILED;
                return (false, "SPEEDBUMP");
            }
        }
        address wpAddress = address(tranche.position());
        IWrappedPosition wrappedPosition = IWrappedPosition(wpAddress);
        address underlyingAddress = address(wrappedPosition.token());
        address yearnVaultAddress = address(wrappedPosition.vault());
        uint256 vaultQuantity = ERC20(underlyingAddress).balanceOf(yearnVaultAddress);
        if (trancheAccount.quantityTokensHeld > vaultQuantity) {
            trancheAccount.redemptionStatus = TrancheRedemptionStatus.REDEMPTION_FAILED;
            return (false, "VAULT_BALANCE");
        }
        // at this point, we will need to redeem the tranche which should be possible
        return (true, "");
    }
}

File 2 of 17 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

File 3 of 17 : IVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity <=0.8.10;
pragma abicoder v2;

import {IERC20} from "./IERC20Permit.sol";

interface IAsset {
    // solhint-disable-previous-line no-empty-blocks
}

enum PoolSpecialization {
    GENERAL,
    MINIMAL_SWAP_INFO,
    TWO_TOKEN
}

interface IVault {
    enum SwapKind {
        GIVEN_IN,
        GIVEN_OUT
    }

    /**
     * @dev Performs a swap with a single Pool.
     *
     * If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens
     * taken from the Pool, which must be greater than or equal to `limit`.
     *
     * If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens
     * sent to the Pool, which must be less than or equal to `limit`.
     *
     * Internal Balance usage and the recipient are determined by the `funds` struct.
     *
     * Emits a `Swap` event.
     */
    function swap(
        SingleSwap memory singleSwap,
        FundManagement memory funds,
        uint256 limit,
        uint256 deadline
    ) external payable returns (uint256);

    /**
     * @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on
     * the `kind` value.
     *
     * `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address).
     * Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault.
     *
     * The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
     * used to extend swap behavior.
     */
    struct SingleSwap {
        bytes32 poolId;
        SwapKind kind;
        IAsset assetIn;
        IAsset assetOut;
        uint256 amount;
        bytes userData;
    }

    /**
     * @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the
     * `recipient` account.
     *
     * If the caller is not `sender`, it must be an authorized relayer for them.
     *
     * If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20
     * transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender`
     * must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of
     * `joinPool`.
     *
     * If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of
     * transferred. This matches the behavior of `exitPool`.
     *
     * Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a
     * revert.
     */
    struct FundManagement {
        address sender;
        bool fromInternalBalance;
        address payable recipient;
        bool toInternalBalance;
    }

    // will revert if poolId is not a registered pool
    function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);

    /**
     * @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be
     * simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result.
     *
     * Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH)
     * the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it
     * receives are the same that an equivalent `batchSwap` call would receive.
     *
     * Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct.
     * This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens,
     * approve them for the Vault, or even know a user's address.
     *
     * Note that this function is not 'view' (due to implementation details): the client code must explicitly execute
     * eth_call instead of eth_sendTransaction.
     */

    struct BatchSwapStep {
        bytes32 poolId;
        uint256 assetInIndex;
        uint256 assetOutIndex;
        uint256 amount;
        bytes userData;
    }

    function queryBatchSwap(
        SwapKind kind,
        BatchSwapStep[] memory swaps,
        IAsset[] memory assets,
        FundManagement memory funds
    ) external view returns (int256[] memory assetDeltas);

    /**
     * @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of
     * the tokens' `balances` changed.
     *
     * The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all
     * Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order.
     *
     * If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same
     * order as passed to `registerTokens`.
     *
     * Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are
     * the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo`
     * instead.
     */
    function getPoolTokens(bytes32 poolId)
        external
        view
        returns (
            IERC20[] memory tokens,
            uint256[] memory balances,
            uint256 lastChangeBlock
        );
}

File 4 of 17 : IPool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import {IERC20Permit, IERC20} from "./IERC20Permit.sol";
import {IVault} from "./IVault.sol";

interface IPool is IERC20Permit {
    /// @dev Returns the poolId for this pool
    /// @return The poolId for this pool
    function getPoolId() external view returns (bytes32);

    function underlying() external view returns (IERC20);

    function expiration() external view returns (uint256);

    function getVault() external view returns (IVault);
}

File 5 of 17 : ITranche.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.6.10 <=0.8.10;

import "./IERC20Permit.sol";

interface ITranche is IERC20Permit {
    function deposit(uint256 _shares, address destination) external returns (uint256, uint256);

    function prefundedDeposit(address _destination) external returns (uint256, uint256);

    function withdrawPrincipal(uint256 _amount, address _destination) external returns (uint256);

    function withdrawInterest(uint256 _amount, address _destination) external returns (uint256);

    function interestSupply() external view returns (uint128);

    function position() external view returns (IERC20);

    function underlying() external view returns (IERC20);

    function speedbump() external view returns (uint256);

    function unlockTimestamp() external view returns (uint256);

    function hitSpeedbump() external;
}

File 6 of 17 : IDeploymentValidator.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

interface IDeploymentValidator {
    function validateWPAddress(address wrappedPosition) external;

    function validatePoolAddress(address pool) external;

    function validateAddresses(address wrappedPosition, address pool) external;

    function checkWPValidation(address wrappedPosition) external view returns (bool);

    function checkPoolValidation(address pool) external view returns (bool);

    function checkPairValidation(address wrappedPosition, address pool) external view returns (bool);
}

File 7 of 17 : IERC20Permit.sol
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2022 Spilsbury Holdings Ltd
pragma solidity >=0.8.4;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IERC20Permit is IERC20 {
    function nonces(address user) external view returns (uint256);

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
}

File 8 of 17 : IWrappedPosition.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "./IERC20Permit.sol";

interface IWrappedPosition is IERC20Permit {
    function token() external view returns (IERC20);

    function vault() external view returns (address);

    function balanceOfUnderlying(address who) external view returns (uint256);

    function getSharesToUnderlying(uint256 shares) external view returns (uint256);

    function deposit(address sender, uint256 amount) external returns (uint256);

    function withdraw(
        address sender,
        uint256 _shares,
        uint256 _minUnderlying
    ) external returns (uint256);

    function withdrawUnderlying(
        address _destination,
        uint256 _amount,
        uint256 _minUnderlying
    ) external returns (uint256, uint256);

    function prefundedDeposit(address _destination)
        external
        returns (
            uint256,
            uint256,
            uint256
        );
}

File 9 of 17 : IRollupProcessor.sol
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2022 Spilsbury Holdings Ltd
pragma solidity >=0.8.4;

interface IRollupProcessor {
    function defiBridgeProxy() external view returns (address);

    function processRollup(
        bytes calldata proofData,
        bytes calldata signatures,
        bytes calldata offchainTxData
    ) external;

    function depositPendingFunds(
        uint256 assetId,
        uint256 amount,
        address owner,
        bytes32 proofHash
    ) external payable;

    function depositPendingFundsPermit(
        uint256 assetId,
        uint256 amount,
        address owner,
        bytes32 proofHash,
        address spender,
        uint256 permitApprovalAmount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    function receiveEthFromBridge(uint256 interactionNonce) external payable;

    function setRollupProvider(address provderAddress, bool valid) external;

    function approveProof(bytes32 _proofHash) external;

    function pause() external;

    function setDefiBridgeProxy(address feeDistributorAddress) external;

    function setVerifier(address verifierAddress) external;

    function setSupportedAsset(
        address linkedToken,
        bool supportsPermit,
        uint256 gasLimit
    ) external;

    function setAssetPermitSupport(uint256 assetId, bool supportsPermit) external;

    function setSupportedBridge(address linkedBridge, uint256 gasLimit) external;

    function getSupportedAsset(uint256 assetId) external view returns (address);

    function getSupportedAssets() external view returns (address[] memory);

    function getSupportedBridge(uint256 bridgeAddressId) external view returns (address);

    function getBridgeGasLimit(uint256 bridgeAddressId) external view returns (uint256);

    function getSupportedBridges() external view returns (address[] memory);

    function getAssetPermitSupport(uint256 assetId) external view returns (bool);

    function getEscapeHatchStatus() external view returns (bool, uint256);

    function getUserPendingDeposit(uint256 assetId, address userAddress) external view returns (uint256);

    function processAsyncDefiInteraction(uint256 interactionNonce) external returns (bool);

    function getDefiInteractionBlockNumber(uint256 interactionNonce) external view returns (uint256);

    event DefiBridgeProcessed(
        uint256 indexed bridgeId,
        uint256 indexed nonce,
        uint256 totalInputValue,
        uint256 totalOutputValueA,
        uint256 totalOutputValueB,
        bool result
    );
    event AsyncDefiBridgeProcessed(
        uint256 indexed bridgeId,
        uint256 indexed nonce,
        uint256 totalInputValue,
        uint256 totalOutputValueA,
        uint256 totalOutputValueB,
        bool result
    );
}

File 10 of 17 : MinHeap.sol
pragma solidity 0.8.10;

/**
 * @title Min Heap
 * @dev Library for managing an array of uint64 values as a minimum heap
 */
library MinHeap {
    using MinHeap for MinHeapData;

    error HEAP_EMPTY();

    /**
     * @dev Encapsulates the underlying data structure used to manage the heap
     *
     * @param heap the array of values contained within the heap
     * @param heapSize the current size of the heap, usually different to the size of underlying array so tracked seperately
     */
    struct MinHeapData {
        uint32 heapSize;
        uint64[] heap;
    }

    /**
     * @dev used to pre-allocate the underlying array with dummy values
     * Useful for gas optimisation later when tru value start to be added
     * @param self reference to the underlying data structure of the heap
     * @param initialSize the amount of slots to pre-allocate
     */
    function initialise(MinHeapData storage self, uint32 initialSize) internal {
        uint256 i = 0;
        unchecked {
            while (i < initialSize) {
                self.heap.push(type(uint64).max);
                i++;
            }
            self.heapSize = 0;
        }
    }

    /**
     * @dev used to add a new value to the heap
     * @param self reference to the underlying data structure of the heap
     * @param value the value to add
     */
    function add(MinHeapData storage self, uint64 value) internal {
        uint32 hSize = self.heapSize;
        if (hSize == self.heap.length) {
            self.heap.push(value);
        } else {
            self.heap[hSize] = value;
        }
        unchecked {
            self.heapSize = hSize + 1;
        }
        siftUp(self, hSize);
    }

    /**
     * @dev retrieve the current minimum value in the heap
     * @param self reference to the underlying data structure of the heap
     * @return minimum the heap's current minimum value
     */
    function min(MinHeapData storage self) internal view returns (uint64 minimum) {
        if (self.heapSize == 0) {
            revert HEAP_EMPTY();
        }
        minimum = self.heap[0];
    }

    /**
     * @dev used to remove a value from the heap
     * will remove the first found occurence of the value from the heap, optimised for removal of the minimum value
     * @param self reference to the underlying data structure of the heap
     * @param value the value to be removed
     */
    function remove(MinHeapData storage self, uint64 value) internal {
        uint256 index = 0;
        uint32 hSize = self.heapSize;
        while (index < hSize && self.heap[index] != value) {
            unchecked {
                ++index;
            }
        }
        if (index == hSize) {
            return;
        }
        if (index != 0) {
            // the value was found but it is not the minimum value
            // to remove this we set it's value to 0 and sift it up to it's new position
            self.heap[index] = 0;
            siftUp(self, index);
        }
        // now we just need to pop the minimum value
        pop(self);
    }

    /**
     * @dev used to remove the minimum value from the heap
     * @param self reference to the underlying data structure of the heap
     */
    function pop(MinHeapData storage self) internal {
        // if the heap is empty then nothing to do
        uint32 hSize = self.heapSize;
        if (hSize == 0) {
            return;
        }
        // read the value in the last position and shrink the array by 1
        uint64 last = self.heap[--hSize];
        // now sift down
        // write the smallest child value into the parent each time
        // then once we no longer have any smaller children, we write the 'last' value into place
        // requires a total of O(logN) updates
        uint256 index = 0;
        uint256 leftChildIndex;
        uint256 rightChildIndex;
        while (index < hSize) {
            // get the indices of the child values
            unchecked {
                leftChildIndex = (index << 1) + 1; // as long as hSize is not gigantic, we are fine.
                rightChildIndex = leftChildIndex + 1;
            }
            uint256 swapIndex = index;
            uint64 smallestValue = last;
            uint64 leftChild; // Used only for cache

            // identify the smallest child, first check the left
            if (leftChildIndex < hSize && (leftChild = self.heap[leftChildIndex]) < smallestValue) {
                swapIndex = leftChildIndex;
                smallestValue = leftChild;
            }
            // then check the right
            if (rightChildIndex < hSize && self.heap[rightChildIndex] < smallestValue) {
                swapIndex = rightChildIndex;
            }
            // if neither child was smaller then nothing more to do
            if (swapIndex == index) {
                self.heap[index] = smallestValue;
                break;
            }
            // take the value from the smallest child and write in into our slot
            self.heap[index] = self.heap[swapIndex];
            index = swapIndex;
        }
        self.heapSize = hSize;
    }

    /**
     * @dev retrieve the current size of the heap
     * @param self reference to the underlying data structure of the heap
     * @return currentSize the heap's current size
     */
    function size(MinHeapData storage self) internal view returns (uint256 currentSize) {
        currentSize = self.heapSize;
    }

    /**
     * @dev move the value at the given index up to the correct position in the heap
     * @param self reference to the underlying data structure of the heap
     * @param index the index of the element that is to be correctly positioned
     */
    function siftUp(MinHeapData storage self, uint256 index) private {
        uint64 value = self.heap[index];
        uint256 parentIndex;
        while (index > 0) {
            uint64 parent;
            unchecked {
                parentIndex = (index - 1) >> 1;
            }
            if ((parent = self.heap[parentIndex]) <= value) {
                break;
            }
            self.heap[index] = parent; // update
            index = parentIndex;
        }
        self.heap[index] = value;
    }
}

File 11 of 17 : FullMath.sol
// SPDX-License-Identifier: MIT
//pragma solidity >=0.4.0 <0.8.0;

pragma solidity >=0.6.10 <=0.8.10;

///note: @dev of Aztec Connect Uniswap V3 Bridge for LP. This library has been modified to conform to version 0.8.x of solidity.
///the first change is on line 74, which was originally a unary negation of an unsigned integer like thus:
///uint256 twos = -denominator & denominator;
/// unary negation on unsigned integers has been disallowed in solidity versions 0.8.x
///the fix for this is to change line 74 from uint256 twos = -denominator & denominator; to uint256 twos = (type(uint256).max - denominator + 1 ) & denominator;
///see https://docs.soliditylang.org/en/v0.8.11/080-breaking-changes.html
///the second change is the introduction of an unchecked block starting on line 70
///the code within this block relies on integer wraparound
/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        // 512-bit multiply [prod1 prod0] = a * b
        // Compute the product mod 2**256 and mod 2**256 - 1
        // then 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(a, b, not(0))
            prod0 := mul(a, b)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        // Handle non-overflow cases, 256 by 256 division
        if (prod1 == 0) {
            require(denominator > 0);
            assembly {
                result := div(prod0, denominator)
            }
            return result;
        }

        // Make sure the result is less than 2**256.
        // Also prevents denominator == 0
        require(denominator > prod1);

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

        // Make division exact by subtracting the remainder from [prod1 prod0]
        // Compute remainder using mulmod
        uint256 remainder;
        assembly {
            remainder := mulmod(a, b, denominator)
        }
        // Subtract 256 bit number from 512 bit number
        assembly {
            prod1 := sub(prod1, gt(remainder, prod0))
            prod0 := sub(prod0, remainder)
        }

        unchecked {
            // Factor powers of two out of denominator
            // Compute largest power of two divisor of denominator.
            // Always >= 1.
            uint256 twos = (type(uint256).max - denominator + 1) & denominator; //this line has been modified from the original Uniswap V3 library
            // Divide denominator by power of two
            assembly {
                denominator := div(denominator, twos)
            }

            // Divide [prod1 prod0] by the factors of two
            assembly {
                prod0 := div(prod0, twos)
            }
            // Shift in bits from prod1 into prod0. For this we need
            // to flip `twos` such that it is 2**256 / twos.
            // If twos is zero, then it becomes one
            assembly {
                twos := add(div(sub(0, twos), twos), 1)
            }
            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
            // correct for four bits. That is, denominator * inv = 1 mod 2**4
            uint256 inv = (3 * denominator) ^ 2;
            // Now use 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.
            inv *= 2 - denominator * inv; // inverse mod 2**8
            inv *= 2 - denominator * inv; // inverse mod 2**16
            inv *= 2 - denominator * inv; // inverse mod 2**32
            inv *= 2 - denominator * inv; // inverse mod 2**64
            inv *= 2 - denominator * inv; // inverse mod 2**128
            inv *= 2 - denominator * inv; // 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 precoditions 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 * inv;
        }

        return result;
    }

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        result = mulDiv(a, b, denominator);
        if (mulmod(a, b, denominator) > 0) {
            require(result < type(uint256).max);
            result++;
        }
    }
}

File 12 of 17 : IDefiBridge.sol
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2022 Spilsbury Holdings Ltd
pragma solidity >=0.8.4;

import {AztecTypes} from "../aztec/AztecTypes.sol";

interface IDefiBridge {
    /**
     * Input cases:
     * Case1: 1 real input.
     * Case2: 1 virtual asset input.
     * Case3: 1 real 1 virtual input.
     *
     * Output cases:
     * Case1: 1 real
     * Case2: 2 real
     * Case3: 1 real 1 virtual
     * Case4: 1 virtual
     *
     * Example use cases with asset mappings
     * 1 1: Swapping.
     * 1 2: Swapping with incentives (2nd output reward token).
     * 1 3: Borrowing. Lock up collateral, get back loan asset and virtual position asset.
     * 1 4: Opening lending position OR Purchasing NFT. Input real asset, get back virtual asset representing NFT or position.
     * 2 1: Selling NFT. Input the virtual asset, get back a real asset.
     * 2 2: Closing a lending position. Get back original asset and reward asset.
     * 2 3: Claiming fees from an open position.
     * 2 4: Voting on a 1 4 case.
     * 3 1: Repaying a borrow. Return loan plus interest. Get collateral back.
     * 3 2: Repaying a borrow. Return loan plus interest. Get collateral plus reward token. (AAVE)
     * 3 3: Partial loan repayment.
     * 3 4: DAO voting stuff.
     */

    // @dev This function is called from the RollupProcessor.sol contract via the DefiBridgeProxy. It receives the aggregate sum of all users funds for the input assets.
    // @param AztecAsset inputAssetA a struct detailing the first input asset, this will always be set
    // @param AztecAsset inputAssetB an optional struct detailing the second input asset, this is used for repaying borrows and should be virtual
    // @param AztecAsset outputAssetA a struct detailing the first output asset, this will always be set
    // @param AztecAsset outputAssetB a struct detailing an optional second output asset
    // @param uint256 inputValue, the total amount input, if there are two input assets, equal amounts of both assets will have been input
    // @param uint256 interactionNonce a globally unique identifier for this DeFi interaction. This is used as the assetId if one of the output assets is virtual
    // @param uint64 auxData other data to be passed into the bridge contract (slippage / nftID etc)
    // @return uint256 outputValueA the amount of outputAssetA returned from this interaction, should be 0 if async
    // @return uint256 outputValueB the amount of outputAssetB returned from this interaction, should be 0 if async or bridge only returns 1 asset.
    // @return bool isAsync a flag to toggle if this bridge interaction will return assets at a later date after some third party contract has interacted with it via finalise()
    function convert(
        AztecTypes.AztecAsset calldata inputAssetA,
        AztecTypes.AztecAsset calldata inputAssetB,
        AztecTypes.AztecAsset calldata outputAssetA,
        AztecTypes.AztecAsset calldata outputAssetB,
        uint256 inputValue,
        uint256 interactionNonce,
        uint64 auxData,
        address rollupBeneficiary
    )
        external
        payable
        virtual
        returns (
            uint256 outputValueA,
            uint256 outputValueB,
            bool isAsync
        );

    // @dev This function is called from the RollupProcessor.sol contract via the DefiBridgeProxy. It receives the aggregate sum of all users funds for the input assets.
    // @param AztecAsset inputAssetA a struct detailing the first input asset, this will always be set
    // @param AztecAsset inputAssetB an optional struct detailing the second input asset, this is used for repaying borrows and should be virtual
    // @param AztecAsset outputAssetA a struct detailing the first output asset, this will always be set
    // @param AztecAsset outputAssetB a struct detailing an optional second output asset
    // @param uint256 interactionNonce
    // @param uint64 auxData other data to be passed into the bridge contract (slippage / nftID etc)
    // @return uint256 outputValueA the return value of output asset A
    // @return uint256 outputValueB optional return value of output asset B
    // @dev this function should have a modifier on it to ensure it can only be called by the Rollup Contract
    function finalise(
        AztecTypes.AztecAsset calldata inputAssetA,
        AztecTypes.AztecAsset calldata inputAssetB,
        AztecTypes.AztecAsset calldata outputAssetA,
        AztecTypes.AztecAsset calldata outputAssetB,
        uint256 interactionNonce,
        uint64 auxData
    )
        external
        payable
        virtual
        returns (
            uint256 outputValueA,
            uint256 outputValueB,
            bool interactionComplete
        );
}

File 13 of 17 : AztecTypes.sol
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2020 Spilsbury Holdings Ltd

pragma solidity >=0.6.10 <=0.8.10;
pragma experimental ABIEncoderV2;

library AztecTypes {
    enum AztecAssetType {
        NOT_USED,
        ETH,
        ERC20,
        VIRTUAL
    }

    struct AztecAsset {
        uint256 id;
        address erc20Address;
        AztecAssetType assetType;
    }
}

File 14 of 17 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 15 of 17 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

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

pragma solidity ^0.8.0;

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

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

File 17 of 17 : IERC20Permit.sol
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2020 Spilsbury Holdings Ltd
pragma solidity >=0.6.10 <=0.8.10;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IERC20Permit is IERC20 {
    function nonces(address user) external view returns (uint256);

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_rollupProcessor","type":"address"},{"internalType":"address","name":"_trancheFactory","type":"address"},{"internalType":"bytes32","name":"_trancheBytecodeHash","type":"bytes32"},{"internalType":"address","name":"_balancerVaultAddress","type":"address"},{"internalType":"address","name":"_elementDeploymentValidatorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ALREADY_FINALISED","type":"error"},{"inputs":[],"name":"ASSET_IDS_NOT_EQUAL","type":"error"},{"inputs":[],"name":"ASSET_NOT_ERC20","type":"error"},{"inputs":[],"name":"BRIDGE_NOT_READY","type":"error"},{"inputs":[],"name":"HEAP_EMPTY","type":"error"},{"inputs":[],"name":"INPUT_ASSETB_NOT_UNUSED","type":"error"},{"inputs":[],"name":"INTERACTION_ALREADY_EXISTS","type":"error"},{"inputs":[],"name":"INVALID_CALLER","type":"error"},{"inputs":[],"name":"INVALID_CHANGE_IN_BALANCE","type":"error"},{"inputs":[],"name":"INVALID_POOL","type":"error"},{"inputs":[],"name":"INVALID_TOKEN_BALANCE_RECEIVED","type":"error"},{"inputs":[],"name":"INVALID_TRANCHE","type":"error"},{"inputs":[],"name":"INVALID_WRAPPED_POSITION","type":"error"},{"inputs":[],"name":"OUTPUT_ASSETB_NOT_UNUSED","type":"error"},{"inputs":[],"name":"POOL_EXPIRY_MISMATCH","type":"error"},{"inputs":[],"name":"POOL_NOT_FOUND","type":"error"},{"inputs":[],"name":"POOL_UNDERLYING_MISMATCH","type":"error"},{"inputs":[],"name":"RECEIVED_LESS_THAN_LIMIT","type":"error"},{"inputs":[],"name":"TRANCHE_ALREADY_EXPIRED","type":"error"},{"inputs":[],"name":"TRANCHE_EXPIRY_MISMATCH","type":"error"},{"inputs":[],"name":"TRANCHE_POSITION_MISMATCH","type":"error"},{"inputs":[],"name":"TRANCHE_UNDERLYING_MISMATCH","type":"error"},{"inputs":[],"name":"UNKNOWN_NONCE","type":"error"},{"inputs":[],"name":"UNREGISTERED_PAIR","type":"error"},{"inputs":[],"name":"UNREGISTERED_POOL","type":"error"},{"inputs":[],"name":"UNREGISTERED_POSITION","type":"error"},{"inputs":[],"name":"VAULT_ADDRESS_MISMATCH","type":"error"},{"inputs":[],"name":"VAULT_ADDRESS_VERIFICATION_FAILED","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalInputValue","type":"uint256"},{"indexed":false,"internalType":"int64","name":"gasUsed","type":"int64"}],"name":"LogConvert","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"},{"indexed":false,"internalType":"int64","name":"gasUsed","type":"int64"}],"name":"LogFinalise","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"poolAddress","type":"address"},{"indexed":false,"internalType":"address","name":"wrappedPositionAddress","type":"address"},{"indexed":false,"internalType":"uint64","name":"expiry","type":"uint64"}],"name":"LogPoolAdded","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"assetToExpirys","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"inputAssetA","type":"tuple"},{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"inputAssetB","type":"tuple"},{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"outputAssetA","type":"tuple"},{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"outputAssetB","type":"tuple"},{"internalType":"uint256","name":"totalInputValue","type":"uint256"},{"internalType":"uint256","name":"interactionNonce","type":"uint256"},{"internalType":"uint64","name":"auxData","type":"uint64"},{"internalType":"address","name":"","type":"address"}],"name":"convert","outputs":[{"internalType":"uint256","name":"outputValueA","type":"uint256"},{"internalType":"uint256","name":"outputValueB","type":"uint256"},{"internalType":"bool","name":"isAsync","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"","type":"tuple"},{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"","type":"tuple"},{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"outputAssetA","type":"tuple"},{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"erc20Address","type":"address"},{"internalType":"enum AztecTypes.AztecAssetType","name":"assetType","type":"uint8"}],"internalType":"struct AztecTypes.AztecAsset","name":"","type":"tuple"},{"internalType":"uint256","name":"interactionNonce","type":"uint256"},{"internalType":"uint64","name":"","type":"uint64"}],"name":"finalise","outputs":[{"internalType":"uint256","name":"outputValueA","type":"uint256"},{"internalType":"uint256","name":"outputValueB","type":"uint256"},{"internalType":"bool","name":"interactionCompleted","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"getAssetExpiries","outputs":[{"internalType":"uint64[]","name":"assetExpiries","type":"uint64[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"interactionNonce","type":"uint256"}],"name":"getTrancheDeploymentBlockNumber","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint64","name":"expiry","type":"uint64"}],"name":"hashAssetAndExpiry","outputs":[{"internalType":"uint256","name":"hashValue","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"interactions","outputs":[{"internalType":"uint256","name":"quantityPT","type":"uint256"},{"internalType":"address","name":"trancheAddress","type":"address"},{"internalType":"uint64","name":"expiry","type":"uint64"},{"internalType":"bool","name":"finalised","type":"bool"},{"internalType":"bool","name":"failed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"pools","outputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"address","name":"trancheAddress","type":"address"},{"internalType":"address","name":"poolAddress","type":"address"},{"internalType":"address","name":"wrappedPositionAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_convergentPool","type":"address"},{"internalType":"address","name":"_wrappedPosition","type":"address"},{"internalType":"uint64","name":"_expiry","type":"uint64"}],"name":"registerConvergentPoolAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rollupProcessor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

6101206040523480156200001257600080fd5b50604051620036c8380380620036c8833981016040819052620000359162000103565b6001600160a01b0385811660c05284811660805260a084905282811660e05281166101005262000074600560646200007f602090811b62000dfb17901c565b50505050506200016a565b60005b8163ffffffff16811015620000d757600180840180548083018255600091825260209091206004820401805460086003909316929092026101000a6001600160401b0302801990921690911790550162000082565b5050805463ffffffff19169055565b80516001600160a01b0381168114620000fe57600080fd5b919050565b600080600080600060a086880312156200011c57600080fd5b6200012786620000e6565b94506200013760208701620000e6565b9350604086015192506200014e60608701620000e6565b91506200015e60808701620000e6565b90509295509295909350565b60805160a05160c05160e051610100516134e8620001e06000396000611fcd01526000818161149501528181611505015281816118e601526119ef0152600081816101a30152818161034a0152818161079b01528181610ba60152611c9f01526000610fb901526000610f8801526134e86000f3fe6080604052600436106100915760003560e01c80639b07d342116100595780639b07d3421461020b578063a46b17231461021e578063ac4afa381461023e578063beb5ca32146102bf578063e03da821146102f757600080fd5b806305ff03ba146100965780630ba460ff146100b857806326c3b515146101615780632a113d6e14610191578063748c72d4146101dd575b600080fd5b3480156100a257600080fd5b506100b66100b1366004612e6d565b610324565b005b3480156100c457600080fd5b5061011c6100d3366004612eb4565b600060208190529081526040902080546001909101546001600160a01b038116906001600160401b03600160a01b8204169060ff600160e01b8204811691600160e81b90041685565b604080519586526001600160a01b0390941660208601526001600160401b039092169284019290925290151560608301521515608082015260a0015b60405180910390f35b61017461016f366004612ee5565b610334565b604080519384526020840192909252151590820152606001610158565b34801561019d57600080fd5b506101c57f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610158565b3480156101e957600080fd5b506101fd6101f8366004612eb4565b610723565b604051908152602001610158565b610174610219366004612f7b565b610785565b34801561022a57600080fd5b506101fd610239366004612ff0565b610cc1565b34801561024a57600080fd5b50610290610259366004612eb4565b6002602081905260009182526040909120805460018201549282015460039092015490926001600160a01b03908116928116911684565b604080519485526001600160a01b03938416602086015291831691840191909152166060820152608001610158565b3480156102cb57600080fd5b506102df6102da366004613025565b610d11565b6040516001600160401b039091168152602001610158565b34801561030357600080fd5b50610317610312366004613051565b610d5d565b604051610158919061306e565b61032f838383610e60565b505050565b6000806000805a90506000336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610388576040516306a8611160e11b815260040160405180910390fd5b8c358b35146103aa57604051633a8b0fa560e01b815260040160405180910390fd5b60028d60400160208101906103bf91906130d1565b60038111156103d0576103d06130bb565b146103ee57604051633841b42760e21b815260040160405180910390fd5b600061040060608e0160408f016130d1565b6003811115610411576104116130bb565b1461042f5760405163057d2bf960e51b815260040160405180910390fd5b600061044160608c0160408d016130d1565b6003811115610452576104526130bb565b14610470576040516338e2878f60e01b815260040160405180910390fd5b600088815260208190526040902060010154600160a01b90046001600160401b0316156104b05760405163691f18df60e01b815260040160405180910390fd5b600192506000945060009350600060405180608001604052808f60200160208101906104dc9190613051565b6001600160a01b031681526020018b81526020018a8152602001896001600160401b0316815250905060006002600061051d84600001518560600151610cc1565b8152602081019190915260400160002060018101549091506001600160a01b03168061055c576040516301de8c6d60e01b815260040160405180910390fd5b60008190506000816001600160a01b031663aa082a9d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105c591906130f2565b9050806001600160401b031642106105f057604051635a1032c960e11b815260040160405180910390fd5b60006106058660000151868860200151611859565b6040808801805160009081526020819052919091208281556001810180546001600160401b038716600160a01b026001600160e01b03199091166001600160a01b038a161717905590519192509061065d9084611b5f565b506001600160a01b038516600090815260036020526040812080549091849183919061068a908490613121565b909155505060038101805463ffffffff8082166001011663ffffffff199091161790555a8a03985087604001517fc621d102de25d9fb4a882d97639da3cb4a20f336efcf731704d7ba6e2d36f4ea89602001518b6040516106f892919091825260070b602082015260400190565b60405180910390a261070b6107d0611c0c565b50505050505050505050985098509895505050505050565b60008181526020819052604081206001810154600160a01b90046001600160401b03166107635760405163c2c1a8e760e01b815260040160405180910390fd5b600101546001600160a01b031660009081526004602052604090205492915050565b6000806000805a90506000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146107d9576040516306a8611160e11b815260040160405180910390fd5b60008781526020819052604090206001810154600160a01b90046001600160401b03166108195760405163c2c1a8e760e01b815260040160405180910390fd5b600181015442600160a01b9091046001600160401b03161061084e57604051634010786d60e11b815260040160405180910390fd5b6001810154600160e01b900460ff161561087b5760405163db4c3b1160e01b815260040160405180910390fd5b60018101546001600160a01b0316600090815260036020819052604090912090810154815463ffffffff9091169081610901576108e0848c6040518060400160405280600d81526020016c2727afa222a827a9a4aa29af9960991b8152506000611d1e565b6108ea848c611d78565b506000806000985098509850505050505050610cb5565b60026003840154600160401b900460ff166002811115610923576109236130bb565b14610aa457600184015460405163884e17f360e01b8152600481018390523060248201526001600160a01b0390911690819063884e17f3906044016020604051808303816000875af1925050508015610999575060408051601f3d908101601f19168201909252610996918101906130f2565b60015b610a7c576109a5613139565b806308c379a01415610a0e57506109ba61318f565b806109c55750610a10565b5a880396506109d6868e838a611d1e565b60038501805460ff60401b1916600160401b1790556109f5868e611d78565b5060008060009a509a509a505050505050505050610cb5565b505b5a87039550610a45858d6040518060400160405280600c81526020016b2ba4aa24222920abafa2a92960a11b81525089611d1e565b60038401805460ff60401b1916600160401b179055610a64858d611d78565b50600080600099509950995050505050505050610cb5565b6001850181905560028501555060038301805460ff60401b1916680200000000000000001790555b600081610ac8578263ffffffff168460010154610ac19190613218565b9050610ade565b610adb8460010154866000015484611ef9565b90505b6003840154600090610b029063ffffffff640100000000909104811690861661323a565b9050600181131580610b175750846002015482115b15610b2457846002015491505b81856002016000828254610b389190613279565b9250508190555084600301600481819054906101000a900463ffffffff168092919060010191906101000a81548163ffffffff021916908363ffffffff160217905550508e6020016020810190610b8f9190613051565b60405163095ea7b360e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260248201859052919091169063095ea7b3906044016020604051808303816000875af1158015610c00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c249190613290565b5060018601805460ff60e01b1916600160e01b179055610c44868e611d78565b50819a5060009950600198505a880396508c7fcdb222b9bdf555fd0196a74228f1d9a5eb9b4dd230de179690409b2fa1e7ee0e8a89604051610ca4929190911515825260606020830181905260009083015260070b604082015260800190565b60405180910390a250505050505050505b96509650969350505050565b6040516bffffffffffffffffffffffff19606084901b1660208201526001600160401b038216603482015260009060540160408051601f1981840301815291905280516020909101209392505050565b60016020528160005260406000208181548110610d2d57600080fd5b9060005260206000209060049182820401919006600802915091509054906101000a90046001600160401b031681565b6001600160a01b038116600090815260016020908152604091829020805483518184028101840190945280845260609392830182828015610def57602002820191906000526020600020906000905b82829054906101000a90046001600160401b03166001600160401b031681526020019060080190602082600701049283019260010382029150808411610dac5790505b50505050509050919050565b60005b8163ffffffff16811015610e5157600180840180548083018255600091825260209091206004820401805460086003909316929092026101000a6001600160401b03028019909216909117905501610dfe565b5050805463ffffffff19169055565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091526000839050806001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610f00575060408051601f3d908101601f19168201909252610efd918101906132b2565b60015b610f1d5760405163eda1d2cf60e01b815260040160405180910390fd5b6001600160a01b031660408381019190915280516bffffffffffffffffffffffff19606087811b82166020808501919091526001600160401b038816603480860191909152855180860390910181526054850186528051908201206001600160f81b031960748601527f000000000000000000000000000000000000000000000000000000000000000090921b909216607584015260898301527f000000000000000000000000000000000000000000000000000000000000000060a9808401919091528351808403909101815260c990920190925280519101206001600160a01b031660608301819052604080516309218e9160e01b8152905182916309218e919160048083019260209291908290030181865afa925050508015611060575060408051601f3d908101601f1916820190925261105d918101906132b2565b60015b61107d57604051633299481b60e01b815260040160405180910390fd5b6001600160a01b03166080840152806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156110e5575060408051601f3d908101601f191682019092526110e2918101906132b2565b60015b61110257604051633299481b60e01b815260040160405180910390fd5b6001600160a01b031660a08401526000816001600160a01b031663aa082a9d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561116c575060408051601f3d908101601f19168201909252611169918101906130f2565b60015b61118957604051633299481b60e01b815260040160405180910390fd5b9050846001600160401b0316816001600160401b0316146111bc576040516249491b60e41b815260040160405180910390fd5b856001600160a01b031684608001516001600160a01b0316146111f1576040516259150160e81b815260040160405180910390fd5b83604001516001600160a01b03168460a001516001600160a01b03161461122b57604051635ffd9a8d60e11b815260040160405180910390fd5b6000879050806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561128a575060408051601f3d908101601f19168201909252611287918101906132b2565b60015b6112a75760405163015216d560e21b815260040160405180910390fd5b6001600160a01b031660c0860152806001600160a01b0316634665096d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561130f575060408051601f3d908101601f1916820190925261130c918101906130f2565b60015b61132c5760405163015216d560e21b815260040160405180910390fd5b8552806001600160a01b0316638d928af86040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611388575060408051601f3d908101601f19168201909252611385918101906132b2565b60015b6113a55760405163015216d560e21b815260040160405180910390fd5b6001600160a01b031660e0860152806001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561140d575060408051601f3d908101601f1916820190925261140a918101906130f2565b60015b61142a5760405163015216d560e21b815260040160405180910390fd5b602086015284604001516001600160a01b03168560c001516001600160a01b03161461146957604051631c368bd160e11b815260040160405180910390fd5b84516001600160401b0387161461149357604051630cb15d9960e31b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168560e001516001600160a01b0316146114e957604051630adf24e160e31b815260040160405180910390fd5b602085015160405163f6c0092760e01b815260048101919091527f0000000000000000000000000000000000000000000000000000000000000000906000906001600160a01b0383169063f6c00927906024016040805180830381865afa158015611558573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061157c91906132cf565b509050806001600160a01b03168a6001600160a01b0316146115b157604051630e7c481d60e31b815260040160405180910390fd5b6115bb898b611fae565b60006115cb886040015186610cc1565b905060405180608001604052808960200151815260200189606001516001600160a01b031681526020018c6001600160a01b031681526020018b6001600160a01b0316815250600260008381526020019081526020016000206000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b031602179055509050506000600160008a604001516001600160a01b03166001600160a01b03168152602001908152602001600020905060005b8154811080156117395750866001600160401b031682828154811061170f5761170f61330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b031614155b15611746576001016116e8565b815481141561178d5781546001810183556000838152602090206004820401805460039092166008026101000a6001600160401b0381810219909316928a16029190911790555b61179a8a6060015161216e565b6001600160401b038716600090815260076020526040902080546117e6576001600160401b03881660009081526007602090815260408220805460018101825590835291206000199101555b7f5ee59c475c00a3d1aadd3f845a455b20c79ba7f236b2c185f3f9bd8ca995c9438e8e8a604051611841939291906001600160a01b0393841681529190921660208201526001600160401b0391909116604082015260600190565b60405180910390a15050505050505050505050505050565b6040805160c08101825283548152600060208083018290526001600160a01b03878116848601819052600188015482166060808701919091526080808701899052875180890189526004808252630307830360e41b8288015260a0890191909152885191820189523080835295820187905281890195909552908101859052955163095ea7b360e01b81527f0000000000000000000000000000000000000000000000000000000000000000909216928201929092526024810186905291939163095ea7b3906044016020604051808303816000875af1158015611941573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119659190613290565b5060018501546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156119b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119d591906130f2565b6040516352bbbe2960e01b81529091506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906352bbbe2990611a2a90869086908a904290600401613370565b6020604051808303816000875af1158015611a49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a6d91906130f2565b60018701546040516370a0823160e01b81523060048201529195506000916001600160a01b03909116906370a0823190602401602060405180830381865afa158015611abd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae191906130f2565b905081811015611b045760405163037d1b3160e41b815260040160405180910390fd5b6000611b108383613279565b9050858114611b32576040516304e41c7d60e31b815260040160405180910390fd5b86861015611b535760405163c2ef4e0560e01b815260040160405180910390fd5b50505050509392505050565b6001600160401b03811660009081526007602052604081208054600181148015611ba7575060001982600081548110611b9a57611b9a61330d565b9060005260206000200154145b15611bd1578482600081548110611bc057611bc061330d565b600091825260209091200155611beb565b815460018181018455600084815260209020909101869055015b8060011415611c0457611bff6005856121ac565b600192505b505092915050565b600081611c1d6107d0619c40613121565b611c279190613121565b90506000611c37836107d0613121565b90505b815a111561032f57600080611c4e83612287565b9150915081611c5e575050505050565b60005a9050838111611c7257505050505050565b6000611c7e8583613279565b6040516310311e8d60e31b8152600481018590529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690638188f46890839060240160206040518083038160008887f193505050508015611d07575060408051601f3d908101601f19168201909252611d0491810190613290565b60015b611d145750505050505050565b5050505050611c3a565b60018401805460ff60e81b1916600160e81b17905560405183907fcdb222b9bdf555fd0196a74228f1d9a5eb9b4dd230de179690409b2fa1e7ee0e90611d6a906000908690869061344e565b60405180910390a250505050565b6001820154600160a01b90046001600160401b03166000818152600760205260408120805491929180611db15760009350505050611ef3565b6000611dbe600183613279565b90505b600081118015611ded575085838281548110611ddf57611ddf61330d565b906000526020600020015414155b15611dfb5760001901611dc1565b85838281548110611e0e57611e0e61330d565b906000526020600020015414611e2b576000945050505050611ef3565b611e36600183613279565b8114611e825782611e48600184613279565b81548110611e5857611e5861330d565b9060005260206000200154838281548110611e7557611e7561330d565b6000918252602090912001555b82805480611e9257611e9261347c565b600190038181906000526020600020016000905590558160011415611eea57611ebc6005856124ac565b6001600160401b0384166000908152600760205260408120611edd91612e02565b6001945050505050611ef3565b60009450505050505b92915050565b600080806000198587098587029250828110838203039150508060001415611f335760008411611f2857600080fd5b508290049050611fa7565b808411611f3f57600080fd5b600084868809851960019081018716968790049682860381900495909211909303600082900391909104909201919091029190911760038402600290811880860282030280860282030280860282030280860282030280860282030280860290910302029150505b9392505050565b6040516318d2af8560e31b81526001600160a01b0382811660048301527f0000000000000000000000000000000000000000000000000000000000000000919082169063c6957c2890602401602060405180830381865afa158015612017573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061203b9190613290565b6120585760405163bdc96a2960e01b815260040160405180910390fd5b604051639221015760e01b81526001600160a01b038481166004830152821690639221015790602401602060405180830381865afa15801561209e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c29190613290565b6120df5760405163764c28c560e11b815260040160405180910390fd5b60405163c1c6917560e01b81526001600160a01b038481166004830152838116602483015282169063c1c6917590604401602060405180830381865afa15801561212d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121519190613290565b61032f5760405163064a479b60e01b815260040160405180910390fd5b6001600160a01b038116600090815260046020526040902054806121a8576001600160a01b03821660009081526004602052604090204390555b5050565b8154600183015463ffffffff90911690811415612209576001838101805491820181556000908152602090206004820401805460039092166008026101000a6001600160401b03818102199093169285160291909117905561225f565b81836001018263ffffffff16815481106122255761222561330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b031602179055505b825463ffffffff19166001820163ffffffff90811691909117845561032f90849083166125a4565b60008061229960055463ffffffff1690565b6122a857506000928392509050565b60006122b460056126f6565b905042816001600160401b0316106122d25750600093849350915050565b6001600160401b0381166000908152600760205260408120805490916122fa614e2088613121565b90505b60008211801561230d5750805a10155b1561247457600083612320600185613279565b815481106123305761233061330d565b9060005260206000200154905060001981141561237c57838054806123575761235761347c565b60019003818190600052602060002001600090559055828060019003935050506122fd565b60008181526020819052604090206001810154600160a01b90046001600160401b031615806123b657506001810154600160e01b900460ff165b806123cc57506001810154600160e81b900460ff165b1561240757848054806123e1576123e161347c565b6001900381819060005260206000200160009055905583806001900394505050506122fd565b60008061241383612764565b9150915081612461576124298385836000611d1e565b868054806124395761243961347c565b60019003818190600052602060002001600090559055858060019003965050505050506122fd565b5060019a92995091975050505050505050565b8115801561248d57506124896161a888613121565b5a10155b1561249d5761249d6005856124ac565b50600096879650945050505050565b815460009063ffffffff165b8063ffffffff16821080156125115750826001600160401b03168460010183815481106124e7576124e761330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b031614155b15612521578160010191506124b8565b8063ffffffff168214156125355750505050565b81156125955760008460010183815481106125525761255261330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b0316021790555061259584836125a4565b61259e84612ba1565b50505050565b60008260010182815481106125bb576125bb61330d565b60009182526020822060048204015460039091166008026101000a90046001600160401b031691505b82156126a15760006001808503901c9150826001600160401b03168560010183815481106126145761261461330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b03169150811161264957506126a1565b8085600101858154811061265f5761265f61330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b03160217905550819350506125e4565b818460010184815481106126b7576126b761330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b0316021790555050505050565b805460009063ffffffff1661271e57604051639622ab6160e01b815260040160405180910390fd5b816001016000815481106127345761273461330d565b90600052602060002090600491828204019190066008029054906101000a90046001600160401b03169050919050565b60018101546001600160a01b031660009081526003602081905260408220908101546060919063ffffffff166127c65760006040518060400160405280600d81526020016c4e4f5f4445504f534954535f3160981b8152509250925050915091565b60016003820154600160401b900460ff1660028111156127e8576127e86130bb565b141561282457600060405180604001604052806011815260200170149151115354151253d397d19052531151607a1b8152509250925050915091565b60026003820154600160401b900460ff166002811115612846576128466130bb565b14156128a55760028101546128895760006040518060400160405280600f81526020016e119553131657d0531313d0d0551151608a1b8152509250925050915091565b6001604051806020016040528060008152509250925050915091565b60018401546040805163421b15c160e01b815290516001600160a01b0390921691600091839163421b15c1916004808201926020929091908290030181865afa1580156128f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061291a91906130f2565b9050801561297e5760006129316202a30083613121565b90504281111561297c57505050600301805460ff60401b1916600160401b17905550506040805180820190915260098152680535045454442554d560bc1b6020820152600092909150565b505b6000826001600160a01b03166309218e916040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129e291906132b2565b905060008190506000816001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a4d91906132b2565b90506000826001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ab391906132b2565b6040516370a0823160e01b81526001600160a01b0380831660048301529192506000918416906370a0823190602401602060405180830381865afa158015612aff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b2391906130f2565b90508088600001541115612b7e5750505050600393909301805460ff60401b1916600160401b179055505060408051808201909152600d81526c5641554c545f42414c414e434560981b602082015260009590945092505050565b600160405180602001604052806000815250995099505050505050505050915091565b805463ffffffff1680612bb2575050565b600060018301612bc183613492565b92508263ffffffff1681548110612bda57612bda61330d565b60009182526020822060048204015460039091166008026101000a90046001600160401b0316915080805b8463ffffffff16831015612de3575050600181811b908101906002018284600063ffffffff881685108015612c805750816001600160401b0316896001018681548110612c5457612c5461330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b0316915081105b15612c8c578492508091505b8763ffffffff1684108015612ce45750816001600160401b0316896001018581548110612cbb57612cbb61330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b0316105b15612ced578392505b85831415612d4c5781896001018781548110612d0b57612d0b61330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b03160217905550505050612de3565b886001018381548110612d6157612d6161330d565b90600052602060002090600491828204019190066008029054906101000a90046001600160401b0316896001018781548110612d9f57612d9f61330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b03160217905550829550505050612c05565b5050835463ffffffff191663ffffffff93909316929092179092555050565b5080546000825590600052602060002090810190612e209190612e23565b50565b5b80821115612e385760008155600101612e24565b5090565b6001600160a01b0381168114612e2057600080fd5b80356001600160401b0381168114612e6857600080fd5b919050565b600080600060608486031215612e8257600080fd5b8335612e8d81612e3c565b92506020840135612e9d81612e3c565b9150612eab60408501612e51565b90509250925092565b600060208284031215612ec657600080fd5b5035919050565b600060608284031215612edf57600080fd5b50919050565b600080600080600080600080610200898b031215612f0257600080fd5b612f0c8a8a612ecd565b9750612f1b8a60608b01612ecd565b9650612f2a8a60c08b01612ecd565b9550612f3a8a6101208b01612ecd565b945061018089013593506101a08901359250612f596101c08a01612e51565b91506101e0890135612f6a81612e3c565b809150509295985092959890939650565b6000806000806000806101c08789031215612f9557600080fd5b612f9f8888612ecd565b9550612fae8860608901612ecd565b9450612fbd8860c08901612ecd565b9350612fcd886101208901612ecd565b92506101808701359150612fe46101a08801612e51565b90509295509295509295565b6000806040838503121561300357600080fd5b823561300e81612e3c565b915061301c60208401612e51565b90509250929050565b6000806040838503121561303857600080fd5b823561304381612e3c565b946020939093013593505050565b60006020828403121561306357600080fd5b8135611fa781612e3c565b6020808252825182820181905260009190848201906040850190845b818110156130af5783516001600160401b03168352928401929184019160010161308a565b50909695505050505050565b634e487b7160e01b600052602160045260246000fd5b6000602082840312156130e357600080fd5b813560048110611fa757600080fd5b60006020828403121561310457600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156131345761313461310b565b500190565b600060033d11156131525760046000803e5060005160e01c5b90565b601f8201601f191681016001600160401b038111828210171561318857634e487b7160e01b600052604160045260246000fd5b6040525050565b600060443d101561319d5790565b6040516003193d81016004833e81513d6001600160401b0381602484011181841117156131cc57505050505090565b82850191508151818111156131e45750505050505090565b843d87010160208285010111156131fe5750505050505090565b61320d60208286010187613155565b509095945050505050565b60008261323557634e487b7160e01b600052601260045260246000fd5b500490565b60008083128015600160ff1b8501841216156132585761325861310b565b6001600160ff1b03840183138116156132735761327361310b565b50500390565b60008282101561328b5761328b61310b565b500390565b6000602082840312156132a257600080fd5b81518015158114611fa757600080fd5b6000602082840312156132c457600080fd5b8151611fa781612e3c565b600080604083850312156132e257600080fd5b82516132ed81612e3c565b60208401519092506003811061330257600080fd5b809150509250929050565b634e487b7160e01b600052603260045260246000fd5b6000815180845260005b818110156133495760208185018101518683018201520161332d565b8181111561335b576000602083870101525b50601f01601f19169290920160200192915050565b60e08152845160e082015260006020860151600281106133a057634e487b7160e01b600052602160045260246000fd5b61010083015260408601516001600160a01b031661012083015260608601516133d56101408401826001600160a01b03169052565b50608086015161016083015260a086015160c06101808401526133fc6101a0840182613323565b91505061343c602083018680516001600160a01b039081168352602080830151151590840152604080830151909116908301526060908101511515910152565b60a082019390935260c0015292915050565b83151581526060602082015260006134696060830185613323565b90508260070b6040830152949350505050565b634e487b7160e01b600052603160045260246000fd5b600063ffffffff8216806134a8576134a861310b565b600019019291505056fea26469706673582212205db49f2d0e51c54209abfb39ba05fc777ca6681911273816c85ac1d7944f128e64736f6c634300080a0033000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b35168045500000000000000000000000062f161bf3692e4015befb05a03a94a40f520d1c0f481a073666136ab1f5e93b296e84df58092065256d0db23b2d22b62c68e978d000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000c68e2bab13a7a2344bb81badbea626012c62c510

Deployed Bytecode

0x6080604052600436106100915760003560e01c80639b07d342116100595780639b07d3421461020b578063a46b17231461021e578063ac4afa381461023e578063beb5ca32146102bf578063e03da821146102f757600080fd5b806305ff03ba146100965780630ba460ff146100b857806326c3b515146101615780632a113d6e14610191578063748c72d4146101dd575b600080fd5b3480156100a257600080fd5b506100b66100b1366004612e6d565b610324565b005b3480156100c457600080fd5b5061011c6100d3366004612eb4565b600060208190529081526040902080546001909101546001600160a01b038116906001600160401b03600160a01b8204169060ff600160e01b8204811691600160e81b90041685565b604080519586526001600160a01b0390941660208601526001600160401b039092169284019290925290151560608301521515608082015260a0015b60405180910390f35b61017461016f366004612ee5565b610334565b604080519384526020840192909252151590820152606001610158565b34801561019d57600080fd5b506101c57f000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b35168045581565b6040516001600160a01b039091168152602001610158565b3480156101e957600080fd5b506101fd6101f8366004612eb4565b610723565b604051908152602001610158565b610174610219366004612f7b565b610785565b34801561022a57600080fd5b506101fd610239366004612ff0565b610cc1565b34801561024a57600080fd5b50610290610259366004612eb4565b6002602081905260009182526040909120805460018201549282015460039092015490926001600160a01b03908116928116911684565b604080519485526001600160a01b03938416602086015291831691840191909152166060820152608001610158565b3480156102cb57600080fd5b506102df6102da366004613025565b610d11565b6040516001600160401b039091168152602001610158565b34801561030357600080fd5b50610317610312366004613051565b610d5d565b604051610158919061306e565b61032f838383610e60565b505050565b6000806000805a90506000336001600160a01b037f000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b3516804551614610388576040516306a8611160e11b815260040160405180910390fd5b8c358b35146103aa57604051633a8b0fa560e01b815260040160405180910390fd5b60028d60400160208101906103bf91906130d1565b60038111156103d0576103d06130bb565b146103ee57604051633841b42760e21b815260040160405180910390fd5b600061040060608e0160408f016130d1565b6003811115610411576104116130bb565b1461042f5760405163057d2bf960e51b815260040160405180910390fd5b600061044160608c0160408d016130d1565b6003811115610452576104526130bb565b14610470576040516338e2878f60e01b815260040160405180910390fd5b600088815260208190526040902060010154600160a01b90046001600160401b0316156104b05760405163691f18df60e01b815260040160405180910390fd5b600192506000945060009350600060405180608001604052808f60200160208101906104dc9190613051565b6001600160a01b031681526020018b81526020018a8152602001896001600160401b0316815250905060006002600061051d84600001518560600151610cc1565b8152602081019190915260400160002060018101549091506001600160a01b03168061055c576040516301de8c6d60e01b815260040160405180910390fd5b60008190506000816001600160a01b031663aa082a9d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105c591906130f2565b9050806001600160401b031642106105f057604051635a1032c960e11b815260040160405180910390fd5b60006106058660000151868860200151611859565b6040808801805160009081526020819052919091208281556001810180546001600160401b038716600160a01b026001600160e01b03199091166001600160a01b038a161717905590519192509061065d9084611b5f565b506001600160a01b038516600090815260036020526040812080549091849183919061068a908490613121565b909155505060038101805463ffffffff8082166001011663ffffffff199091161790555a8a03985087604001517fc621d102de25d9fb4a882d97639da3cb4a20f336efcf731704d7ba6e2d36f4ea89602001518b6040516106f892919091825260070b602082015260400190565b60405180910390a261070b6107d0611c0c565b50505050505050505050985098509895505050505050565b60008181526020819052604081206001810154600160a01b90046001600160401b03166107635760405163c2c1a8e760e01b815260040160405180910390fd5b600101546001600160a01b031660009081526004602052604090205492915050565b6000806000805a90506000336001600160a01b037f000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b35168045516146107d9576040516306a8611160e11b815260040160405180910390fd5b60008781526020819052604090206001810154600160a01b90046001600160401b03166108195760405163c2c1a8e760e01b815260040160405180910390fd5b600181015442600160a01b9091046001600160401b03161061084e57604051634010786d60e11b815260040160405180910390fd5b6001810154600160e01b900460ff161561087b5760405163db4c3b1160e01b815260040160405180910390fd5b60018101546001600160a01b0316600090815260036020819052604090912090810154815463ffffffff9091169081610901576108e0848c6040518060400160405280600d81526020016c2727afa222a827a9a4aa29af9960991b8152506000611d1e565b6108ea848c611d78565b506000806000985098509850505050505050610cb5565b60026003840154600160401b900460ff166002811115610923576109236130bb565b14610aa457600184015460405163884e17f360e01b8152600481018390523060248201526001600160a01b0390911690819063884e17f3906044016020604051808303816000875af1925050508015610999575060408051601f3d908101601f19168201909252610996918101906130f2565b60015b610a7c576109a5613139565b806308c379a01415610a0e57506109ba61318f565b806109c55750610a10565b5a880396506109d6868e838a611d1e565b60038501805460ff60401b1916600160401b1790556109f5868e611d78565b5060008060009a509a509a505050505050505050610cb5565b505b5a87039550610a45858d6040518060400160405280600c81526020016b2ba4aa24222920abafa2a92960a11b81525089611d1e565b60038401805460ff60401b1916600160401b179055610a64858d611d78565b50600080600099509950995050505050505050610cb5565b6001850181905560028501555060038301805460ff60401b1916680200000000000000001790555b600081610ac8578263ffffffff168460010154610ac19190613218565b9050610ade565b610adb8460010154866000015484611ef9565b90505b6003840154600090610b029063ffffffff640100000000909104811690861661323a565b9050600181131580610b175750846002015482115b15610b2457846002015491505b81856002016000828254610b389190613279565b9250508190555084600301600481819054906101000a900463ffffffff168092919060010191906101000a81548163ffffffff021916908363ffffffff160217905550508e6020016020810190610b8f9190613051565b60405163095ea7b360e01b81526001600160a01b037f000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b3516804558116600483015260248201859052919091169063095ea7b3906044016020604051808303816000875af1158015610c00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c249190613290565b5060018601805460ff60e01b1916600160e01b179055610c44868e611d78565b50819a5060009950600198505a880396508c7fcdb222b9bdf555fd0196a74228f1d9a5eb9b4dd230de179690409b2fa1e7ee0e8a89604051610ca4929190911515825260606020830181905260009083015260070b604082015260800190565b60405180910390a250505050505050505b96509650969350505050565b6040516bffffffffffffffffffffffff19606084901b1660208201526001600160401b038216603482015260009060540160408051601f1981840301815291905280516020909101209392505050565b60016020528160005260406000208181548110610d2d57600080fd5b9060005260206000209060049182820401919006600802915091509054906101000a90046001600160401b031681565b6001600160a01b038116600090815260016020908152604091829020805483518184028101840190945280845260609392830182828015610def57602002820191906000526020600020906000905b82829054906101000a90046001600160401b03166001600160401b031681526020019060080190602082600701049283019260010382029150808411610dac5790505b50505050509050919050565b60005b8163ffffffff16811015610e5157600180840180548083018255600091825260209091206004820401805460086003909316929092026101000a6001600160401b03028019909216909117905501610dfe565b5050805463ffffffff19169055565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091526000839050806001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610f00575060408051601f3d908101601f19168201909252610efd918101906132b2565b60015b610f1d5760405163eda1d2cf60e01b815260040160405180910390fd5b6001600160a01b031660408381019190915280516bffffffffffffffffffffffff19606087811b82166020808501919091526001600160401b038816603480860191909152855180860390910181526054850186528051908201206001600160f81b031960748601527f00000000000000000000000062f161bf3692e4015befb05a03a94a40f520d1c090921b909216607584015260898301527ff481a073666136ab1f5e93b296e84df58092065256d0db23b2d22b62c68e978d60a9808401919091528351808403909101815260c990920190925280519101206001600160a01b031660608301819052604080516309218e9160e01b8152905182916309218e919160048083019260209291908290030181865afa925050508015611060575060408051601f3d908101601f1916820190925261105d918101906132b2565b60015b61107d57604051633299481b60e01b815260040160405180910390fd5b6001600160a01b03166080840152806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156110e5575060408051601f3d908101601f191682019092526110e2918101906132b2565b60015b61110257604051633299481b60e01b815260040160405180910390fd5b6001600160a01b031660a08401526000816001600160a01b031663aa082a9d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561116c575060408051601f3d908101601f19168201909252611169918101906130f2565b60015b61118957604051633299481b60e01b815260040160405180910390fd5b9050846001600160401b0316816001600160401b0316146111bc576040516249491b60e41b815260040160405180910390fd5b856001600160a01b031684608001516001600160a01b0316146111f1576040516259150160e81b815260040160405180910390fd5b83604001516001600160a01b03168460a001516001600160a01b03161461122b57604051635ffd9a8d60e11b815260040160405180910390fd5b6000879050806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561128a575060408051601f3d908101601f19168201909252611287918101906132b2565b60015b6112a75760405163015216d560e21b815260040160405180910390fd5b6001600160a01b031660c0860152806001600160a01b0316634665096d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561130f575060408051601f3d908101601f1916820190925261130c918101906130f2565b60015b61132c5760405163015216d560e21b815260040160405180910390fd5b8552806001600160a01b0316638d928af86040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611388575060408051601f3d908101601f19168201909252611385918101906132b2565b60015b6113a55760405163015216d560e21b815260040160405180910390fd5b6001600160a01b031660e0860152806001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561140d575060408051601f3d908101601f1916820190925261140a918101906130f2565b60015b61142a5760405163015216d560e21b815260040160405180910390fd5b602086015284604001516001600160a01b03168560c001516001600160a01b03161461146957604051631c368bd160e11b815260040160405180910390fd5b84516001600160401b0387161461149357604051630cb15d9960e31b815260040160405180910390fd5b7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b03168560e001516001600160a01b0316146114e957604051630adf24e160e31b815260040160405180910390fd5b602085015160405163f6c0092760e01b815260048101919091527f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8906000906001600160a01b0383169063f6c00927906024016040805180830381865afa158015611558573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061157c91906132cf565b509050806001600160a01b03168a6001600160a01b0316146115b157604051630e7c481d60e31b815260040160405180910390fd5b6115bb898b611fae565b60006115cb886040015186610cc1565b905060405180608001604052808960200151815260200189606001516001600160a01b031681526020018c6001600160a01b031681526020018b6001600160a01b0316815250600260008381526020019081526020016000206000820151816000015560208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b031602179055509050506000600160008a604001516001600160a01b03166001600160a01b03168152602001908152602001600020905060005b8154811080156117395750866001600160401b031682828154811061170f5761170f61330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b031614155b15611746576001016116e8565b815481141561178d5781546001810183556000838152602090206004820401805460039092166008026101000a6001600160401b0381810219909316928a16029190911790555b61179a8a6060015161216e565b6001600160401b038716600090815260076020526040902080546117e6576001600160401b03881660009081526007602090815260408220805460018101825590835291206000199101555b7f5ee59c475c00a3d1aadd3f845a455b20c79ba7f236b2c185f3f9bd8ca995c9438e8e8a604051611841939291906001600160a01b0393841681529190921660208201526001600160401b0391909116604082015260600190565b60405180910390a15050505050505050505050505050565b6040805160c08101825283548152600060208083018290526001600160a01b03878116848601819052600188015482166060808701919091526080808701899052875180890189526004808252630307830360e41b8288015260a0890191909152885191820189523080835295820187905281890195909552908101859052955163095ea7b360e01b81527f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8909216928201929092526024810186905291939163095ea7b3906044016020604051808303816000875af1158015611941573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119659190613290565b5060018501546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156119b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119d591906130f2565b6040516352bbbe2960e01b81529091506001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c816906352bbbe2990611a2a90869086908a904290600401613370565b6020604051808303816000875af1158015611a49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a6d91906130f2565b60018701546040516370a0823160e01b81523060048201529195506000916001600160a01b03909116906370a0823190602401602060405180830381865afa158015611abd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae191906130f2565b905081811015611b045760405163037d1b3160e41b815260040160405180910390fd5b6000611b108383613279565b9050858114611b32576040516304e41c7d60e31b815260040160405180910390fd5b86861015611b535760405163c2ef4e0560e01b815260040160405180910390fd5b50505050509392505050565b6001600160401b03811660009081526007602052604081208054600181148015611ba7575060001982600081548110611b9a57611b9a61330d565b9060005260206000200154145b15611bd1578482600081548110611bc057611bc061330d565b600091825260209091200155611beb565b815460018181018455600084815260209020909101869055015b8060011415611c0457611bff6005856121ac565b600192505b505092915050565b600081611c1d6107d0619c40613121565b611c279190613121565b90506000611c37836107d0613121565b90505b815a111561032f57600080611c4e83612287565b9150915081611c5e575050505050565b60005a9050838111611c7257505050505050565b6000611c7e8583613279565b6040516310311e8d60e31b8152600481018590529091506001600160a01b037f000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b3516804551690638188f46890839060240160206040518083038160008887f193505050508015611d07575060408051601f3d908101601f19168201909252611d0491810190613290565b60015b611d145750505050505050565b5050505050611c3a565b60018401805460ff60e81b1916600160e81b17905560405183907fcdb222b9bdf555fd0196a74228f1d9a5eb9b4dd230de179690409b2fa1e7ee0e90611d6a906000908690869061344e565b60405180910390a250505050565b6001820154600160a01b90046001600160401b03166000818152600760205260408120805491929180611db15760009350505050611ef3565b6000611dbe600183613279565b90505b600081118015611ded575085838281548110611ddf57611ddf61330d565b906000526020600020015414155b15611dfb5760001901611dc1565b85838281548110611e0e57611e0e61330d565b906000526020600020015414611e2b576000945050505050611ef3565b611e36600183613279565b8114611e825782611e48600184613279565b81548110611e5857611e5861330d565b9060005260206000200154838281548110611e7557611e7561330d565b6000918252602090912001555b82805480611e9257611e9261347c565b600190038181906000526020600020016000905590558160011415611eea57611ebc6005856124ac565b6001600160401b0384166000908152600760205260408120611edd91612e02565b6001945050505050611ef3565b60009450505050505b92915050565b600080806000198587098587029250828110838203039150508060001415611f335760008411611f2857600080fd5b508290049050611fa7565b808411611f3f57600080fd5b600084868809851960019081018716968790049682860381900495909211909303600082900391909104909201919091029190911760038402600290811880860282030280860282030280860282030280860282030280860282030280860290910302029150505b9392505050565b6040516318d2af8560e31b81526001600160a01b0382811660048301527f000000000000000000000000c68e2bab13a7a2344bb81badbea626012c62c510919082169063c6957c2890602401602060405180830381865afa158015612017573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061203b9190613290565b6120585760405163bdc96a2960e01b815260040160405180910390fd5b604051639221015760e01b81526001600160a01b038481166004830152821690639221015790602401602060405180830381865afa15801561209e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c29190613290565b6120df5760405163764c28c560e11b815260040160405180910390fd5b60405163c1c6917560e01b81526001600160a01b038481166004830152838116602483015282169063c1c6917590604401602060405180830381865afa15801561212d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121519190613290565b61032f5760405163064a479b60e01b815260040160405180910390fd5b6001600160a01b038116600090815260046020526040902054806121a8576001600160a01b03821660009081526004602052604090204390555b5050565b8154600183015463ffffffff90911690811415612209576001838101805491820181556000908152602090206004820401805460039092166008026101000a6001600160401b03818102199093169285160291909117905561225f565b81836001018263ffffffff16815481106122255761222561330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b031602179055505b825463ffffffff19166001820163ffffffff90811691909117845561032f90849083166125a4565b60008061229960055463ffffffff1690565b6122a857506000928392509050565b60006122b460056126f6565b905042816001600160401b0316106122d25750600093849350915050565b6001600160401b0381166000908152600760205260408120805490916122fa614e2088613121565b90505b60008211801561230d5750805a10155b1561247457600083612320600185613279565b815481106123305761233061330d565b9060005260206000200154905060001981141561237c57838054806123575761235761347c565b60019003818190600052602060002001600090559055828060019003935050506122fd565b60008181526020819052604090206001810154600160a01b90046001600160401b031615806123b657506001810154600160e01b900460ff165b806123cc57506001810154600160e81b900460ff165b1561240757848054806123e1576123e161347c565b6001900381819060005260206000200160009055905583806001900394505050506122fd565b60008061241383612764565b9150915081612461576124298385836000611d1e565b868054806124395761243961347c565b60019003818190600052602060002001600090559055858060019003965050505050506122fd565b5060019a92995091975050505050505050565b8115801561248d57506124896161a888613121565b5a10155b1561249d5761249d6005856124ac565b50600096879650945050505050565b815460009063ffffffff165b8063ffffffff16821080156125115750826001600160401b03168460010183815481106124e7576124e761330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b031614155b15612521578160010191506124b8565b8063ffffffff168214156125355750505050565b81156125955760008460010183815481106125525761255261330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b0316021790555061259584836125a4565b61259e84612ba1565b50505050565b60008260010182815481106125bb576125bb61330d565b60009182526020822060048204015460039091166008026101000a90046001600160401b031691505b82156126a15760006001808503901c9150826001600160401b03168560010183815481106126145761261461330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b03169150811161264957506126a1565b8085600101858154811061265f5761265f61330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b03160217905550819350506125e4565b818460010184815481106126b7576126b761330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b0316021790555050505050565b805460009063ffffffff1661271e57604051639622ab6160e01b815260040160405180910390fd5b816001016000815481106127345761273461330d565b90600052602060002090600491828204019190066008029054906101000a90046001600160401b03169050919050565b60018101546001600160a01b031660009081526003602081905260408220908101546060919063ffffffff166127c65760006040518060400160405280600d81526020016c4e4f5f4445504f534954535f3160981b8152509250925050915091565b60016003820154600160401b900460ff1660028111156127e8576127e86130bb565b141561282457600060405180604001604052806011815260200170149151115354151253d397d19052531151607a1b8152509250925050915091565b60026003820154600160401b900460ff166002811115612846576128466130bb565b14156128a55760028101546128895760006040518060400160405280600f81526020016e119553131657d0531313d0d0551151608a1b8152509250925050915091565b6001604051806020016040528060008152509250925050915091565b60018401546040805163421b15c160e01b815290516001600160a01b0390921691600091839163421b15c1916004808201926020929091908290030181865afa1580156128f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061291a91906130f2565b9050801561297e5760006129316202a30083613121565b90504281111561297c57505050600301805460ff60401b1916600160401b17905550506040805180820190915260098152680535045454442554d560bc1b6020820152600092909150565b505b6000826001600160a01b03166309218e916040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129e291906132b2565b905060008190506000816001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a4d91906132b2565b90506000826001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ab391906132b2565b6040516370a0823160e01b81526001600160a01b0380831660048301529192506000918416906370a0823190602401602060405180830381865afa158015612aff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b2391906130f2565b90508088600001541115612b7e5750505050600393909301805460ff60401b1916600160401b179055505060408051808201909152600d81526c5641554c545f42414c414e434560981b602082015260009590945092505050565b600160405180602001604052806000815250995099505050505050505050915091565b805463ffffffff1680612bb2575050565b600060018301612bc183613492565b92508263ffffffff1681548110612bda57612bda61330d565b60009182526020822060048204015460039091166008026101000a90046001600160401b0316915080805b8463ffffffff16831015612de3575050600181811b908101906002018284600063ffffffff881685108015612c805750816001600160401b0316896001018681548110612c5457612c5461330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b0316915081105b15612c8c578492508091505b8763ffffffff1684108015612ce45750816001600160401b0316896001018581548110612cbb57612cbb61330d565b6000918252602090912060048204015460039091166008026101000a90046001600160401b0316105b15612ced578392505b85831415612d4c5781896001018781548110612d0b57612d0b61330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b03160217905550505050612de3565b886001018381548110612d6157612d6161330d565b90600052602060002090600491828204019190066008029054906101000a90046001600160401b0316896001018781548110612d9f57612d9f61330d565b90600052602060002090600491828204019190066008026101000a8154816001600160401b0302191690836001600160401b03160217905550829550505050612c05565b5050835463ffffffff191663ffffffff93909316929092179092555050565b5080546000825590600052602060002090810190612e209190612e23565b50565b5b80821115612e385760008155600101612e24565b5090565b6001600160a01b0381168114612e2057600080fd5b80356001600160401b0381168114612e6857600080fd5b919050565b600080600060608486031215612e8257600080fd5b8335612e8d81612e3c565b92506020840135612e9d81612e3c565b9150612eab60408501612e51565b90509250925092565b600060208284031215612ec657600080fd5b5035919050565b600060608284031215612edf57600080fd5b50919050565b600080600080600080600080610200898b031215612f0257600080fd5b612f0c8a8a612ecd565b9750612f1b8a60608b01612ecd565b9650612f2a8a60c08b01612ecd565b9550612f3a8a6101208b01612ecd565b945061018089013593506101a08901359250612f596101c08a01612e51565b91506101e0890135612f6a81612e3c565b809150509295985092959890939650565b6000806000806000806101c08789031215612f9557600080fd5b612f9f8888612ecd565b9550612fae8860608901612ecd565b9450612fbd8860c08901612ecd565b9350612fcd886101208901612ecd565b92506101808701359150612fe46101a08801612e51565b90509295509295509295565b6000806040838503121561300357600080fd5b823561300e81612e3c565b915061301c60208401612e51565b90509250929050565b6000806040838503121561303857600080fd5b823561304381612e3c565b946020939093013593505050565b60006020828403121561306357600080fd5b8135611fa781612e3c565b6020808252825182820181905260009190848201906040850190845b818110156130af5783516001600160401b03168352928401929184019160010161308a565b50909695505050505050565b634e487b7160e01b600052602160045260246000fd5b6000602082840312156130e357600080fd5b813560048110611fa757600080fd5b60006020828403121561310457600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156131345761313461310b565b500190565b600060033d11156131525760046000803e5060005160e01c5b90565b601f8201601f191681016001600160401b038111828210171561318857634e487b7160e01b600052604160045260246000fd5b6040525050565b600060443d101561319d5790565b6040516003193d81016004833e81513d6001600160401b0381602484011181841117156131cc57505050505090565b82850191508151818111156131e45750505050505090565b843d87010160208285010111156131fe5750505050505090565b61320d60208286010187613155565b509095945050505050565b60008261323557634e487b7160e01b600052601260045260246000fd5b500490565b60008083128015600160ff1b8501841216156132585761325861310b565b6001600160ff1b03840183138116156132735761327361310b565b50500390565b60008282101561328b5761328b61310b565b500390565b6000602082840312156132a257600080fd5b81518015158114611fa757600080fd5b6000602082840312156132c457600080fd5b8151611fa781612e3c565b600080604083850312156132e257600080fd5b82516132ed81612e3c565b60208401519092506003811061330257600080fd5b809150509250929050565b634e487b7160e01b600052603260045260246000fd5b6000815180845260005b818110156133495760208185018101518683018201520161332d565b8181111561335b576000602083870101525b50601f01601f19169290920160200192915050565b60e08152845160e082015260006020860151600281106133a057634e487b7160e01b600052602160045260246000fd5b61010083015260408601516001600160a01b031661012083015260608601516133d56101408401826001600160a01b03169052565b50608086015161016083015260a086015160c06101808401526133fc6101a0840182613323565b91505061343c602083018680516001600160a01b039081168352602080830151151590840152604080830151909116908301526060908101511515910152565b60a082019390935260c0015292915050565b83151581526060602082015260006134696060830185613323565b90508260070b6040830152949350505050565b634e487b7160e01b600052603160045260246000fd5b600063ffffffff8216806134a8576134a861310b565b600019019291505056fea26469706673582212205db49f2d0e51c54209abfb39ba05fc777ca6681911273816c85ac1d7944f128e64736f6c634300080a0033

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

000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b35168045500000000000000000000000062f161bf3692e4015befb05a03a94a40f520d1c0f481a073666136ab1f5e93b296e84df58092065256d0db23b2d22b62c68e978d000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000c68e2bab13a7a2344bb81badbea626012c62c510

-----Decoded View---------------
Arg [0] : _rollupProcessor (address): 0xFF1F2B4ADb9dF6FC8eAFecDcbF96A2B351680455
Arg [1] : _trancheFactory (address): 0x62F161BF3692E4015BefB05A03a94A40f520d1c0
Arg [2] : _trancheBytecodeHash (bytes32): 0xf481a073666136ab1f5e93b296e84df58092065256d0db23b2d22b62c68e978d
Arg [3] : _balancerVaultAddress (address): 0xBA12222222228d8Ba445958a75a0704d566BF2C8
Arg [4] : _elementDeploymentValidatorAddress (address): 0xc68e2BAb13a7A2344bb81badBeA626012C62C510

-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 000000000000000000000000ff1f2b4adb9df6fc8eafecdcbf96a2b351680455
Arg [1] : 00000000000000000000000062f161bf3692e4015befb05a03a94a40f520d1c0
Arg [2] : f481a073666136ab1f5e93b296e84df58092065256d0db23b2d22b62c68e978d
Arg [3] : 000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Arg [4] : 000000000000000000000000c68e2bab13a7a2344bb81badbea626012c62c510


Block Transaction Difficulty 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
Loading...
Loading
[ 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.