Contract

0x1498437067d7bdDc4C9427964F073eE1AB4f50fC

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

-

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Latest 2 internal transactions

Parent Transaction Hash Block From To
4800432024-12-16 13:05:282 days ago1734354328
0x14984370...1AB4f50fC
 Contract Creation0 S
4800432024-12-16 13:05:282 days ago1734354328
0x14984370...1AB4f50fC
 Contract Creation0 S
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
BatchRelayerLibrary

Compiler Version
v0.7.1+commit.f4a555be

Optimization Enabled:
Yes with 9999 runs

Other Settings:
default evmVersion
File 1 of 51 : BatchRelayerLibrary.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "./relayer/BaseRelayerLibrary.sol";

import "./relayer/GaugeActions.sol";
import "./relayer/LidoWrapping.sol";
import "./relayer/VaultActions.sol";
import "./relayer/VaultPermit.sol";
import "./relayer/ReliquaryStaking.sol";

/**
 * @title Batch Relayer Library
 * @notice This contract is not a relayer by itself and calls into it directly will fail.
 * The associated relayer can be found by calling `getEntrypoint` on this contract.
 */
contract BatchRelayerLibrary is
    BaseRelayerLibrary,
    GaugeActions,
    LidoWrapping,
    VaultActions,
    VaultPermit,
    ReliquaryStaking
{
    constructor(
        IVault vault,
        IERC20 wstETH,
        IBalancerMinter minter,
        bool canCallUserCheckpoint,
        string memory version,
        IReliquary reliquary
    )
        BaseRelayerLibrary(vault, version)
        LidoWrapping(wstETH)
        GaugeActions(minter, canCallUserCheckpoint)
        ReliquaryStaking(reliquary)
    {
        // solhint-disable-previous-line no-empty-blocks
    }
}

File 2 of 51 : IBalancerMinter.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

import "../solidity-utils/openzeppelin/IERC20.sol";

/**
 * @dev Base minter interface, applicable to Mainnet minter or L2 pseudo minters.
 */
interface IBalancerMinter {
    event Minted(address indexed recipient, address gauge, uint256 minted);

    /**
     * @notice Returns the address of the Balancer Governance Token
     */
    function getBalancerToken() external view returns (IERC20);

    /**
     * @notice Mint everything which belongs to `msg.sender` and send to them
     * @param gauge `LiquidityGauge` address to get mintable amount from
     */
    function mint(address gauge) external returns (uint256);

    /**
     * @notice Mint everything which belongs to `msg.sender` across multiple gauges
     * @param gauges List of `LiquidityGauge` addresses
     */
    function mintMany(address[] calldata gauges) external returns (uint256);

    /**
     * @notice Mint tokens for `user`
     * @dev Only possible when `msg.sender` has been approved by `user` to mint on their behalf
     * @param gauge `LiquidityGauge` address to get mintable amount from
     * @param user Address to mint to
     */
    function mintFor(address gauge, address user) external returns (uint256);

    /**
     * @notice Mint tokens for `user` across multiple gauges
     * @dev Only possible when `msg.sender` has been approved by `user` to mint on their behalf
     * @param gauges List of `LiquidityGauge` addresses
     * @param user Address to mint to
     */
    function mintManyFor(address[] calldata gauges, address user) external returns (uint256);

    /**
     * @notice The total number of tokens minted for `user` from `gauge`
     */
    function minted(address user, address gauge) external view returns (uint256);

    /**
     * @notice Whether `minter` is approved to mint tokens for `user`
     */
    function getMinterApproval(address minter, address user) external view returns (bool);

    /**
     * @notice Set whether `minter` is approved to mint tokens on your behalf
     */
    function setMinterApproval(address minter, bool approval) external;

    /**
     * @notice Set whether `minter` is approved to mint tokens on behalf of `user`, who has signed a message authorizing
     * them.
     */
    function setMinterApprovalWithSignature(
        address minter,
        bool approval,
        address user,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    // The below functions are near-duplicates of functions available above.
    // They are included for ABI compatibility with snake_casing as used in vyper contracts.
    // solhint-disable func-name-mixedcase

    /**
     * @notice Whether `minter` is approved to mint tokens for `user`
     */
    function allowed_to_mint_for(address minter, address user) external view returns (bool);

    /**
     * @notice Mint everything which belongs to `msg.sender` across multiple gauges
     * @dev This function is not recommended as `mintMany()` is more flexible and gas efficient
     * @param gauges List of `LiquidityGauge` addresses
     */
    function mint_many(address[8] calldata gauges) external;

    /**
     * @notice Mint tokens for `user`
     * @dev Only possible when `msg.sender` has been approved by `user` to mint on their behalf
     * @param gauge `LiquidityGauge` address to get mintable amount from
     * @param user Address to mint to
     */
    function mint_for(address gauge, address user) external;

    /**
     * @notice Toggle whether `minter` is approved to mint tokens for `user`
     */
    function toggle_approve_mint(address minter) external;
}

File 3 of 51 : ILiquidityGauge.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

// For compatibility, we're keeping the same function names as in the original Curve code, including the mixed-case
// naming convention.
// solhint-disable func-name-mixedcase
// solhint-disable func-param-name-mixedcase

interface ILiquidityGauge {
    // solhint-disable-next-line var-name-mixedcase
    event RelativeWeightCapChanged(uint256 new_relative_weight_cap);

    /**
     * @notice Returns BAL liquidity emissions calculated during checkpoints for the given user.
     * @param user User address.
     * @return uint256 BAL amount to issue for the address.
     */
    function integrate_fraction(address user) external view returns (uint256);

    /**
     * @notice Record a checkpoint for a given user.
     * @param user User address.
     * @return bool Always true.
     */
    function user_checkpoint(address user) external returns (bool);

    /**
     * @notice Returns true if gauge is killed; false otherwise.
     */
    function is_killed() external view returns (bool);

    /**
     * @notice Kills the gauge so it cannot mint BAL.
     */
    function killGauge() external;

    /**
     * @notice Unkills the gauge so it can mint BAL again.
     */
    function unkillGauge() external;

    /**
     * @notice Sets a new relative weight cap for the gauge.
     * The value shall be normalized to 1e18, and not greater than MAX_RELATIVE_WEIGHT_CAP.
     * @param relativeWeightCap New relative weight cap.
     */
    function setRelativeWeightCap(uint256 relativeWeightCap) external;

    /**
     * @notice Gets the relative weight cap for the gauge.
     */
    function getRelativeWeightCap() external view returns (uint256);

    /**
     * @notice Returns the gauge's relative weight for a given time, capped to its relative weight cap attribute.
     * @param time Timestamp in the past or present.
     */
    function getCappedRelativeWeight(uint256 time) external view returns (uint256);
}

File 4 of 51 : IReliquary.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC721Enumerable.sol";

interface IEmissionCurve {
    function getRate(uint256 lastRewardTime) external view returns (uint256 rate);
}

interface INFTDescriptor {
    function constructTokenURI(uint256 relicId) external view returns (string memory);
}

/**
 * @notice Info for each Reliquary position.
 * `amount` LP token amount the position owner has provided.
 * `rewardDebt` Amount of reward token accumalated before the position's entry or last harvest.
 * `rewardCredit` Amount of reward token owed to the user on next harvest.
 * `entry` Used to determine the maturity of the position.
 * `poolId` ID of the pool to which this position belongs.
 * `level` Index of this position's level within the pool's array of levels.
 */
struct PositionInfo {
    uint256 amount;
    uint256 rewardDebt;
    uint256 rewardCredit;
    uint256 entry; // position owner's relative entry into the pool.
    uint256 poolId; // ensures that a single Relic is only used for one pool.
    uint256 level;
}

/**
 * @notice Info of each Reliquary pool.
 * `accRewardPerShare` Accumulated reward tokens per share of pool (1 / 1e12).
 * `lastRewardTime` Last timestamp the accumulated reward was updated.
 * `allocPoint` Pool's individual allocation - ratio of the total allocation.
 * `name` Name of pool to be displayed in NFT image.
 */
struct PoolInfo {
    uint256 accRewardPerShare;
    uint256 lastRewardTime;
    uint256 allocPoint;
    string name;
}

/**
 * @notice Info for each level in a pool that determines how maturity is rewarded.
 * `requiredMaturities` The minimum maturity (in seconds) required to reach each Level.
 * `multipliers` Multiplier for each level applied to amount of incentivized token when calculating rewards in the pool.
 *     This is applied to both the numerator and denominator in the calculation such that the size of a user's position
 *     is effectively considered to be the actual number of tokens times the multiplier for their level.
 *     Also note that these multipliers do not affect the overall emission rate.
 * `balance` Total (actual) number of tokens deposited in positions at each level.
 */
struct LevelInfo {
    uint256[] requiredMaturities;
    uint256[] multipliers;
    uint256[] balance;
}

/**
 * @notice Object representing pending rewards and related data for a position.
 * `relicId` The NFT ID of the given position.
 * `poolId` ID of the pool to which this position belongs.
 * `pendingReward` pending reward amount for a given position.
 */
struct PendingReward {
    uint256 relicId;
    uint256 poolId;
    uint256 pendingReward;
}

interface IReliquary is IERC721Enumerable {
    function setEmissionCurve(address _emissionCurve) external;

    function addPool(
        uint256 allocPoint,
        address _poolToken,
        address _rewarder,
        uint256[] calldata requiredMaturity,
        uint256[] calldata allocPoints,
        string memory name,
        address _nftDescriptor
    ) external;

    function modifyPool(
        uint256 pid,
        uint256 allocPoint,
        address _rewarder,
        string calldata name,
        address _nftDescriptor,
        bool overwriteRewarder
    ) external;

    function massUpdatePools(uint256[] calldata pids) external;

    function updatePool(uint256 pid) external;

    function deposit(uint256 amount, uint256 relicId) external;

    function withdraw(uint256 amount, uint256 relicId) external;

    function harvest(uint256 relicId, address harvestTo) external;

    function withdrawAndHarvest(
        uint256 amount,
        uint256 relicId,
        address harvestTo
    ) external;

    function emergencyWithdraw(uint256 relicId) external;

    function updatePosition(uint256 relicId) external;

    function getPositionForId(uint256) external view returns (PositionInfo memory);

    function getPoolInfo(uint256) external view returns (PoolInfo memory);

    function getLevelInfo(uint256) external view returns (LevelInfo memory);

    function pendingRewardsOfOwner(address owner) external view returns (PendingReward[] memory pendingRewards);

    function relicPositionsOfOwner(address owner)
        external
        view
        returns (uint256[] memory relicIds, PositionInfo[] memory positionInfos);

    function isApprovedOrOwner(address, uint256) external view returns (bool);

    function createRelicAndDeposit(
        address to,
        uint256 pid,
        uint256 amount
    ) external returns (uint256 id);

    // function split(uint relicId, uint amount, address to) external returns (uint newId);
    // function shift(uint fromId, uint toId, uint amount) external;
    // function merge(uint fromId, uint toId) external;
    function burn(uint256 tokenId) external;

    function pendingReward(uint256 relicId) external view returns (uint256 pending);

    function levelOnUpdate(uint256 relicId) external view returns (uint256 level);

    function poolLength() external view returns (uint256);

    function rewardToken() external view returns (address);

    function nftDescriptor(uint256) external view returns (address);

    function emissionCurve() external view returns (address);

    function poolToken(uint256) external view returns (address);

    function rewarder(uint256) external view returns (address);

    function totalAllocPoint() external view returns (uint256);
}

File 5 of 51 : IReliquaryRewarder.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20.sol";

interface IRewarder {
    function onReward(
        uint256 relicId,
        uint256 rewardAmount,
        address to
    ) external;

    function onDeposit(uint256 relicId, uint256 depositAmount) external;

    function onWithdraw(uint256 relicId, uint256 withdrawalAmount) external;

    function pendingTokens(uint256 relicId, uint256 rewardAmount)
        external
        view
        returns (IERC20[] memory, uint256[] memory);
}

File 6 of 51 : IRewardTokenDistributor.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../solidity-utils/openzeppelin/IERC20.sol";

// For compatibility, we're keeping the same function names as in the original Curve code, including the mixed-case
// naming convention.
// solhint-disable func-name-mixedcase, var-name-mixedcase

interface IRewardTokenDistributor {
    struct Reward {
        IERC20 token;
        address distributor;
        uint256 period_finish;
        uint256 rate;
        uint256 last_update;
        uint256 integral;
    }

    function reward_tokens(uint256 index) external view returns (IERC20);

    function reward_data(IERC20 token) external view returns (Reward memory);

    function claim_rewards(address user) external;

    function add_reward(IERC20 rewardToken, address distributor) external;

    function set_reward_distributor(IERC20 rewardToken, address distributor) external;

    function deposit_reward_token(IERC20 rewardToken, uint256 amount) external;

    function claimable_reward(address rewardToken, address user) external view returns (uint256);

    function claimable_reward_write(address rewardToken, address user) external returns (uint256);
}

File 7 of 51 : IStakingLiquidityGauge.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../solidity-utils/openzeppelin/IERC20.sol";

import "./ILiquidityGauge.sol";
import "./IRewardTokenDistributor.sol";

// For compatibility, we're keeping the same function names as in the original Curve code, including the mixed-case
// naming convention.
// solhint-disable func-name-mixedcase, var-name-mixedcase

interface IStakingLiquidityGauge is IRewardTokenDistributor, ILiquidityGauge, IERC20 {
    function initialize(address lpToken, uint256 relativeWeightCap) external;

    function lp_token() external view returns (IERC20);

    function deposit(uint256 value, address recipient) external;

    function withdraw(uint256 value) external;
}

File 8 of 51 : StablePoolUserData.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

library StablePoolUserData {
    enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT }
    enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT, EXACT_BPT_IN_FOR_ALL_TOKENS_OUT }

    function joinKind(bytes memory self) internal pure returns (JoinKind) {
        return abi.decode(self, (JoinKind));
    }

    function exitKind(bytes memory self) internal pure returns (ExitKind) {
        return abi.decode(self, (ExitKind));
    }

    // Joins

    function initialAmountsIn(bytes memory self) internal pure returns (uint256[] memory amountsIn) {
        (, amountsIn) = abi.decode(self, (JoinKind, uint256[]));
    }

    function exactTokensInForBptOut(bytes memory self)
        internal
        pure
        returns (uint256[] memory amountsIn, uint256 minBPTAmountOut)
    {
        (, amountsIn, minBPTAmountOut) = abi.decode(self, (JoinKind, uint256[], uint256));
    }

    function tokenInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut, uint256 tokenIndex) {
        (, bptAmountOut, tokenIndex) = abi.decode(self, (JoinKind, uint256, uint256));
    }

    function allTokensInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut) {
        (, bptAmountOut) = abi.decode(self, (JoinKind, uint256));
    }

    // Exits

    function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
        (, bptAmountIn, tokenIndex) = abi.decode(self, (ExitKind, uint256, uint256));
    }

    function exactBptInForTokensOut(bytes memory self) internal pure returns (uint256 bptAmountIn) {
        (, bptAmountIn) = abi.decode(self, (ExitKind, uint256));
    }

    function bptInForExactTokensOut(bytes memory self)
        internal
        pure
        returns (uint256[] memory amountsOut, uint256 maxBPTAmountIn)
    {
        (, amountsOut, maxBPTAmountIn) = abi.decode(self, (ExitKind, uint256[], uint256));
    }
}

File 9 of 51 : BasePoolUserData.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

library BasePoolUserData {
    // Special ExitKind for all pools, used in Recovery Mode. Use the max 8-bit value to prevent conflicts
    // with future additions to the ExitKind enums (or any front-end code that maps to existing values)
    uint8 public constant RECOVERY_MODE_EXIT_KIND = 255;

    // Return true if this is the special exit kind.
    function isRecoveryModeExitKind(bytes memory self) internal pure returns (bool) {
        // Check for the "no data" case, or abi.decode would revert
        return self.length > 0 && abi.decode(self, (uint8)) == RECOVERY_MODE_EXIT_KIND;
    }

    // Parse the bptAmountIn out of the userData
    function recoveryModeExit(bytes memory self) internal pure returns (uint256 bptAmountIn) {
        (, bptAmountIn) = abi.decode(self, (uint8, uint256));
    }
}

File 10 of 51 : WeightedPoolUserData.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

import "../solidity-utils/openzeppelin/IERC20.sol";

library WeightedPoolUserData {
    // In order to preserve backwards compatibility, make sure new join and exit kinds are added at the end of the enum.
    enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT }
    enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT }

    function joinKind(bytes memory self) internal pure returns (JoinKind) {
        return abi.decode(self, (JoinKind));
    }

    function exitKind(bytes memory self) internal pure returns (ExitKind) {
        return abi.decode(self, (ExitKind));
    }

    // Joins

    function initialAmountsIn(bytes memory self) internal pure returns (uint256[] memory amountsIn) {
        (, amountsIn) = abi.decode(self, (JoinKind, uint256[]));
    }

    function exactTokensInForBptOut(bytes memory self)
        internal
        pure
        returns (uint256[] memory amountsIn, uint256 minBPTAmountOut)
    {
        (, amountsIn, minBPTAmountOut) = abi.decode(self, (JoinKind, uint256[], uint256));
    }

    function tokenInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut, uint256 tokenIndex) {
        (, bptAmountOut, tokenIndex) = abi.decode(self, (JoinKind, uint256, uint256));
    }

    function allTokensInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut) {
        (, bptAmountOut) = abi.decode(self, (JoinKind, uint256));
    }

    // Exits

    function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
        (, bptAmountIn, tokenIndex) = abi.decode(self, (ExitKind, uint256, uint256));
    }

    function exactBptInForTokensOut(bytes memory self) internal pure returns (uint256 bptAmountIn) {
        (, bptAmountIn) = abi.decode(self, (ExitKind, uint256));
    }

    function bptInForExactTokensOut(bytes memory self)
        internal
        pure
        returns (uint256[] memory amountsOut, uint256 maxBPTAmountIn)
    {
        (, amountsOut, maxBPTAmountIn) = abi.decode(self, (ExitKind, uint256[], uint256));
    }
}

File 11 of 51 : BalancerErrors.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.1 <0.9.0;

// solhint-disable

/**
 * @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are
 * supported.
 * Uses the default 'BAL' prefix for the error code
 */
function _require(bool condition, uint256 errorCode) pure {
    if (!condition) _revert(errorCode);
}

/**
 * @dev Reverts if `condition` is false, with a revert reason containing `errorCode`. Only codes up to 999 are
 * supported.
 */
function _require(
    bool condition,
    uint256 errorCode,
    bytes3 prefix
) pure {
    if (!condition) _revert(errorCode, prefix);
}

/**
 * @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported.
 * Uses the default 'BAL' prefix for the error code
 */
function _revert(uint256 errorCode) pure {
    _revert(errorCode, 0x42414c); // This is the raw byte representation of "BAL"
}

/**
 * @dev Reverts with a revert reason containing `errorCode`. Only codes up to 999 are supported.
 */
function _revert(uint256 errorCode, bytes3 prefix) pure {
    uint256 prefixUint = uint256(uint24(prefix));
    // We're going to dynamically create a revert string based on the error code, with the following format:
    // 'BAL#{errorCode}'
    // where the code is left-padded with zeroes to three digits (so they range from 000 to 999).
    //
    // We don't have revert strings embedded in the contract to save bytecode size: it takes much less space to store a
    // number (8 to 16 bits) than the individual string characters.
    //
    // The dynamic string creation algorithm that follows could be implemented in Solidity, but assembly allows for a
    // much denser implementation, again saving bytecode size. Given this function unconditionally reverts, this is a
    // safe place to rely on it without worrying about how its usage might affect e.g. memory contents.
    assembly {
        // First, we need to compute the ASCII representation of the error code. We assume that it is in the 0-999
        // range, so we only need to convert three digits. To convert the digits to ASCII, we add 0x30, the value for
        // the '0' character.

        let units := add(mod(errorCode, 10), 0x30)

        errorCode := div(errorCode, 10)
        let tenths := add(mod(errorCode, 10), 0x30)

        errorCode := div(errorCode, 10)
        let hundreds := add(mod(errorCode, 10), 0x30)

        // With the individual characters, we can now construct the full string.
        // We first append the '#' character (0x23) to the prefix. In the case of 'BAL', it results in 0x42414c23 ('BAL#')
        // Then, we shift this by 24 (to provide space for the 3 bytes of the error code), and add the
        // characters to it, each shifted by a multiple of 8.
        // The revert reason is then shifted left by 200 bits (256 minus the length of the string, 7 characters * 8 bits
        // per character = 56) to locate it in the most significant part of the 256 slot (the beginning of a byte
        // array).
        let formattedPrefix := shl(24, add(0x23, shl(8, prefixUint)))

        let revertReason := shl(200, add(formattedPrefix, add(add(units, shl(8, tenths)), shl(16, hundreds))))

        // We can now encode the reason in memory, which can be safely overwritten as we're about to revert. The encoded
        // message will have the following layout:
        // [ revert reason identifier ] [ string location offset ] [ string length ] [ string contents ]

        // The Solidity revert reason identifier is 0x08c739a0, the function selector of the Error(string) function. We
        // also write zeroes to the next 28 bytes of memory, but those are about to be overwritten.
        mstore(0x0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
        // Next is the offset to the location of the string, which will be placed immediately after (20 bytes away).
        mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
        // The string length is fixed: 7 characters.
        mstore(0x24, 7)
        // Finally, the string itself is stored.
        mstore(0x44, revertReason)

        // Even if the string is only 7 bytes long, we need to return a full 32 byte slot containing it. The length of
        // the encoded message is therefore 4 + 32 + 32 + 32 = 100.
        revert(0, 100)
    }
}

library Errors {
    // Math
    uint256 internal constant ADD_OVERFLOW = 0;
    uint256 internal constant SUB_OVERFLOW = 1;
    uint256 internal constant SUB_UNDERFLOW = 2;
    uint256 internal constant MUL_OVERFLOW = 3;
    uint256 internal constant ZERO_DIVISION = 4;
    uint256 internal constant DIV_INTERNAL = 5;
    uint256 internal constant X_OUT_OF_BOUNDS = 6;
    uint256 internal constant Y_OUT_OF_BOUNDS = 7;
    uint256 internal constant PRODUCT_OUT_OF_BOUNDS = 8;
    uint256 internal constant INVALID_EXPONENT = 9;

    // Input
    uint256 internal constant OUT_OF_BOUNDS = 100;
    uint256 internal constant UNSORTED_ARRAY = 101;
    uint256 internal constant UNSORTED_TOKENS = 102;
    uint256 internal constant INPUT_LENGTH_MISMATCH = 103;
    uint256 internal constant ZERO_TOKEN = 104;
    uint256 internal constant INSUFFICIENT_DATA = 105;

    // Shared pools
    uint256 internal constant MIN_TOKENS = 200;
    uint256 internal constant MAX_TOKENS = 201;
    uint256 internal constant MAX_SWAP_FEE_PERCENTAGE = 202;
    uint256 internal constant MIN_SWAP_FEE_PERCENTAGE = 203;
    uint256 internal constant MINIMUM_BPT = 204;
    uint256 internal constant CALLER_NOT_VAULT = 205;
    uint256 internal constant UNINITIALIZED = 206;
    uint256 internal constant BPT_IN_MAX_AMOUNT = 207;
    uint256 internal constant BPT_OUT_MIN_AMOUNT = 208;
    uint256 internal constant EXPIRED_PERMIT = 209;
    uint256 internal constant NOT_TWO_TOKENS = 210;
    uint256 internal constant DISABLED = 211;

    // Pools
    uint256 internal constant MIN_AMP = 300;
    uint256 internal constant MAX_AMP = 301;
    uint256 internal constant MIN_WEIGHT = 302;
    uint256 internal constant MAX_STABLE_TOKENS = 303;
    uint256 internal constant MAX_IN_RATIO = 304;
    uint256 internal constant MAX_OUT_RATIO = 305;
    uint256 internal constant MIN_BPT_IN_FOR_TOKEN_OUT = 306;
    uint256 internal constant MAX_OUT_BPT_FOR_TOKEN_IN = 307;
    uint256 internal constant NORMALIZED_WEIGHT_INVARIANT = 308;
    uint256 internal constant INVALID_TOKEN = 309;
    uint256 internal constant UNHANDLED_JOIN_KIND = 310;
    uint256 internal constant ZERO_INVARIANT = 311;
    uint256 internal constant ORACLE_INVALID_SECONDS_QUERY = 312;
    uint256 internal constant ORACLE_NOT_INITIALIZED = 313;
    uint256 internal constant ORACLE_QUERY_TOO_OLD = 314;
    uint256 internal constant ORACLE_INVALID_INDEX = 315;
    uint256 internal constant ORACLE_BAD_SECS = 316;
    uint256 internal constant AMP_END_TIME_TOO_CLOSE = 317;
    uint256 internal constant AMP_ONGOING_UPDATE = 318;
    uint256 internal constant AMP_RATE_TOO_HIGH = 319;
    uint256 internal constant AMP_NO_ONGOING_UPDATE = 320;
    uint256 internal constant STABLE_INVARIANT_DIDNT_CONVERGE = 321;
    uint256 internal constant STABLE_GET_BALANCE_DIDNT_CONVERGE = 322;
    uint256 internal constant RELAYER_NOT_CONTRACT = 323;
    uint256 internal constant BASE_POOL_RELAYER_NOT_CALLED = 324;
    uint256 internal constant REBALANCING_RELAYER_REENTERED = 325;
    uint256 internal constant GRADUAL_UPDATE_TIME_TRAVEL = 326;
    uint256 internal constant SWAPS_DISABLED = 327;
    uint256 internal constant CALLER_IS_NOT_LBP_OWNER = 328;
    uint256 internal constant PRICE_RATE_OVERFLOW = 329;
    uint256 internal constant INVALID_JOIN_EXIT_KIND_WHILE_SWAPS_DISABLED = 330;
    uint256 internal constant WEIGHT_CHANGE_TOO_FAST = 331;
    uint256 internal constant LOWER_GREATER_THAN_UPPER_TARGET = 332;
    uint256 internal constant UPPER_TARGET_TOO_HIGH = 333;
    uint256 internal constant UNHANDLED_BY_LINEAR_POOL = 334;
    uint256 internal constant OUT_OF_TARGET_RANGE = 335;
    uint256 internal constant UNHANDLED_EXIT_KIND = 336;
    uint256 internal constant UNAUTHORIZED_EXIT = 337;
    uint256 internal constant MAX_MANAGEMENT_SWAP_FEE_PERCENTAGE = 338;
    uint256 internal constant UNHANDLED_BY_MANAGED_POOL = 339;
    uint256 internal constant UNHANDLED_BY_PHANTOM_POOL = 340;
    uint256 internal constant TOKEN_DOES_NOT_HAVE_RATE_PROVIDER = 341;
    uint256 internal constant INVALID_INITIALIZATION = 342;
    uint256 internal constant OUT_OF_NEW_TARGET_RANGE = 343;
    uint256 internal constant FEATURE_DISABLED = 344;
    uint256 internal constant UNINITIALIZED_POOL_CONTROLLER = 345;
    uint256 internal constant SET_SWAP_FEE_DURING_FEE_CHANGE = 346;
    uint256 internal constant SET_SWAP_FEE_PENDING_FEE_CHANGE = 347;
    uint256 internal constant CHANGE_TOKENS_DURING_WEIGHT_CHANGE = 348;
    uint256 internal constant CHANGE_TOKENS_PENDING_WEIGHT_CHANGE = 349;
    uint256 internal constant MAX_WEIGHT = 350;
    uint256 internal constant UNAUTHORIZED_JOIN = 351;
    uint256 internal constant MAX_MANAGEMENT_AUM_FEE_PERCENTAGE = 352;
    uint256 internal constant FRACTIONAL_TARGET = 353;
    uint256 internal constant ADD_OR_REMOVE_BPT = 354;
    uint256 internal constant INVALID_CIRCUIT_BREAKER_BOUNDS = 355;
    uint256 internal constant CIRCUIT_BREAKER_TRIPPED = 356;
    uint256 internal constant MALICIOUS_QUERY_REVERT = 357;
    uint256 internal constant JOINS_EXITS_DISABLED = 358;

    // Lib
    uint256 internal constant REENTRANCY = 400;
    uint256 internal constant SENDER_NOT_ALLOWED = 401;
    uint256 internal constant PAUSED = 402;
    uint256 internal constant PAUSE_WINDOW_EXPIRED = 403;
    uint256 internal constant MAX_PAUSE_WINDOW_DURATION = 404;
    uint256 internal constant MAX_BUFFER_PERIOD_DURATION = 405;
    uint256 internal constant INSUFFICIENT_BALANCE = 406;
    uint256 internal constant INSUFFICIENT_ALLOWANCE = 407;
    uint256 internal constant ERC20_TRANSFER_FROM_ZERO_ADDRESS = 408;
    uint256 internal constant ERC20_TRANSFER_TO_ZERO_ADDRESS = 409;
    uint256 internal constant ERC20_MINT_TO_ZERO_ADDRESS = 410;
    uint256 internal constant ERC20_BURN_FROM_ZERO_ADDRESS = 411;
    uint256 internal constant ERC20_APPROVE_FROM_ZERO_ADDRESS = 412;
    uint256 internal constant ERC20_APPROVE_TO_ZERO_ADDRESS = 413;
    uint256 internal constant ERC20_TRANSFER_EXCEEDS_ALLOWANCE = 414;
    uint256 internal constant ERC20_DECREASED_ALLOWANCE_BELOW_ZERO = 415;
    uint256 internal constant ERC20_TRANSFER_EXCEEDS_BALANCE = 416;
    uint256 internal constant ERC20_BURN_EXCEEDS_ALLOWANCE = 417;
    uint256 internal constant SAFE_ERC20_CALL_FAILED = 418;
    uint256 internal constant ADDRESS_INSUFFICIENT_BALANCE = 419;
    uint256 internal constant ADDRESS_CANNOT_SEND_VALUE = 420;
    uint256 internal constant SAFE_CAST_VALUE_CANT_FIT_INT256 = 421;
    uint256 internal constant GRANT_SENDER_NOT_ADMIN = 422;
    uint256 internal constant REVOKE_SENDER_NOT_ADMIN = 423;
    uint256 internal constant RENOUNCE_SENDER_NOT_ALLOWED = 424;
    uint256 internal constant BUFFER_PERIOD_EXPIRED = 425;
    uint256 internal constant CALLER_IS_NOT_OWNER = 426;
    uint256 internal constant NEW_OWNER_IS_ZERO = 427;
    uint256 internal constant CODE_DEPLOYMENT_FAILED = 428;
    uint256 internal constant CALL_TO_NON_CONTRACT = 429;
    uint256 internal constant LOW_LEVEL_CALL_FAILED = 430;
    uint256 internal constant NOT_PAUSED = 431;
    uint256 internal constant ADDRESS_ALREADY_ALLOWLISTED = 432;
    uint256 internal constant ADDRESS_NOT_ALLOWLISTED = 433;
    uint256 internal constant ERC20_BURN_EXCEEDS_BALANCE = 434;
    uint256 internal constant INVALID_OPERATION = 435;
    uint256 internal constant CODEC_OVERFLOW = 436;
    uint256 internal constant IN_RECOVERY_MODE = 437;
    uint256 internal constant NOT_IN_RECOVERY_MODE = 438;
    uint256 internal constant INDUCED_FAILURE = 439;
    uint256 internal constant EXPIRED_SIGNATURE = 440;
    uint256 internal constant MALFORMED_SIGNATURE = 441;
    uint256 internal constant SAFE_CAST_VALUE_CANT_FIT_UINT64 = 442;
    uint256 internal constant UNHANDLED_FEE_TYPE = 443;
    uint256 internal constant BURN_FROM_ZERO = 444;

    // Vault
    uint256 internal constant INVALID_POOL_ID = 500;
    uint256 internal constant CALLER_NOT_POOL = 501;
    uint256 internal constant SENDER_NOT_ASSET_MANAGER = 502;
    uint256 internal constant USER_DOESNT_ALLOW_RELAYER = 503;
    uint256 internal constant INVALID_SIGNATURE = 504;
    uint256 internal constant EXIT_BELOW_MIN = 505;
    uint256 internal constant JOIN_ABOVE_MAX = 506;
    uint256 internal constant SWAP_LIMIT = 507;
    uint256 internal constant SWAP_DEADLINE = 508;
    uint256 internal constant CANNOT_SWAP_SAME_TOKEN = 509;
    uint256 internal constant UNKNOWN_AMOUNT_IN_FIRST_SWAP = 510;
    uint256 internal constant MALCONSTRUCTED_MULTIHOP_SWAP = 511;
    uint256 internal constant INTERNAL_BALANCE_OVERFLOW = 512;
    uint256 internal constant INSUFFICIENT_INTERNAL_BALANCE = 513;
    uint256 internal constant INVALID_ETH_INTERNAL_BALANCE = 514;
    uint256 internal constant INVALID_POST_LOAN_BALANCE = 515;
    uint256 internal constant INSUFFICIENT_ETH = 516;
    uint256 internal constant UNALLOCATED_ETH = 517;
    uint256 internal constant ETH_TRANSFER = 518;
    uint256 internal constant CANNOT_USE_ETH_SENTINEL = 519;
    uint256 internal constant TOKENS_MISMATCH = 520;
    uint256 internal constant TOKEN_NOT_REGISTERED = 521;
    uint256 internal constant TOKEN_ALREADY_REGISTERED = 522;
    uint256 internal constant TOKENS_ALREADY_SET = 523;
    uint256 internal constant TOKENS_LENGTH_MUST_BE_2 = 524;
    uint256 internal constant NONZERO_TOKEN_BALANCE = 525;
    uint256 internal constant BALANCE_TOTAL_OVERFLOW = 526;
    uint256 internal constant POOL_NO_TOKENS = 527;
    uint256 internal constant INSUFFICIENT_FLASH_LOAN_BALANCE = 528;

    // Fees
    uint256 internal constant SWAP_FEE_PERCENTAGE_TOO_HIGH = 600;
    uint256 internal constant FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH = 601;
    uint256 internal constant INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT = 602;
    uint256 internal constant AUM_FEE_PERCENTAGE_TOO_HIGH = 603;

    // FeeSplitter
    uint256 internal constant SPLITTER_FEE_PERCENTAGE_TOO_HIGH = 700;

    // Misc
    uint256 internal constant UNIMPLEMENTED = 998;
    uint256 internal constant SHOULD_NOT_HAPPEN = 999;
}

File 12 of 51 : IAuthentication.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

interface IAuthentication {
    /**
     * @dev Returns the action identifier associated with the external function described by `selector`.
     */
    function getActionId(bytes4 selector) external view returns (bytes32);
}

File 13 of 51 : ISignaturesValidator.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

/**
 * @dev Interface for the SignatureValidator helper, used to support meta-transactions.
 */
interface ISignaturesValidator {
    /**
     * @dev Returns the EIP712 domain separator.
     */
    function getDomainSeparator() external view returns (bytes32);

    /**
     * @dev Returns the next nonce used by an address to sign messages.
     */
    function getNextNonce(address user) external view returns (uint256);
}

File 14 of 51 : ITemporarilyPausable.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

/**
 * @dev Interface for the TemporarilyPausable helper.
 */
interface ITemporarilyPausable {
    /**
     * @dev Emitted every time the pause state changes by `_setPaused`.
     */
    event PausedStateChanged(bool paused);

    /**
     * @dev Returns the current paused state.
     */
    function getPausedState()
        external
        view
        returns (
            bool paused,
            uint256 pauseWindowEndTime,
            uint256 bufferPeriodEndTime
        );
}

File 15 of 51 : IVersion.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

/**
 * @notice Simple interface to retrieve the version of a deployed contract.
 */
interface IVersion {
    /**
     * @dev Returns a JSON representation of the contract version containing name, version number and task ID.
     */
    function version() external view returns (string memory);
}

File 16 of 51 : IWETH.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

import "../openzeppelin/IERC20.sol";

/**
 * @dev Interface for WETH9.
 * See https://github.com/gnosis/canonical-weth/blob/0dd1ea3e295eef916d0c6223ec63141137d22d67/contracts/WETH9.sol
 */
interface IWETH is IERC20 {
    function deposit() external payable;

    function withdraw(uint256 amount) external;
}

File 17 of 51 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

File 18 of 51 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @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);
}

File 19 of 51 : IERC20Permit.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

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

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

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

File 20 of 51 : IERC20PermitDAI.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

interface IERC20PermitDAI {
    /**
     * @notice update allowance with a signed permit
     * @param holder    Token owner's address (Authorizer)
     * @param spender   Spender's address
     * @param nonce     The permit nonce
     * @param expiry    The time at which this expires (unix time)
     * @param allowed   Whether the spender is allowed or disallowed from spending
     * @param v         v of the signature
     * @param r         r of the signature
     * @param s         s of the signature
     */
    function permit(
        address holder,
        address spender,
        uint256 nonce,
        uint256 expiry,
        bool allowed,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
}

File 21 of 51 : IERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "./IERC165.sol";

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

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

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

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

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

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

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

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

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

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

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

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

File 22 of 51 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

import "./IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

File 23 of 51 : IBalancerRelayer.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../vault/IVault.sol";

/**
 * @title IBalancerRelayer
 * @notice Allows safe multicall execution of a relayer's functions
 */
interface IBalancerRelayer {
    function getLibrary() external view returns (address);

    function getQueryLibrary() external view returns (address);

    function getVault() external view returns (IVault);

    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);

    function vaultActionsQueryMulticall(bytes[] calldata data) external returns (bytes[] memory results);
}

File 24 of 51 : IstETH.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

import "../solidity-utils/openzeppelin/IERC20.sol";

// solhint-disable-next-line max-line-length
// Based on https://github.com/lidofinance/lido-dao/blob/816bf1d0995ba5cfdfc264de4acda34a7fe93eba/contracts/0.4.24/Lido.sol

interface IstETH is IERC20 {
    function submit(address referral) external payable returns (uint256);
}

File 25 of 51 : IwstETH.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

import "../solidity-utils/openzeppelin/IERC20.sol";

import "./IstETH.sol";

// solhint-disable-next-line max-line-length
// Based on https://github.com/lidofinance/lido-dao/blob/2b46615a11dee77d4d22066f942f6c6afab9b87a/contracts/0.6.12/WstETH.sol

/**
 * @title StETH token wrapper with static balances.
 * @dev It's an ERC20 token that represents the account's share of the total
 * supply of stETH tokens. WstETH token's balance only changes on transfers,
 * unlike StETH that is also changed when oracles report staking rewards and
 * penalties. It's a "power user" token for DeFi protocols which don't
 * support rebasable tokens.
 *
 * The contract is also a trustless wrapper that accepts stETH tokens and mints
 * wstETH in return. Then the user unwraps, the contract burns user's wstETH
 * and sends user locked stETH in return.
 *
 * The contract provides the staking shortcut: user can send ETH with regular
 * transfer and get wstETH in return. The contract will send ETH to Lido submit
 * method, staking it and wrapping the received stETH.
 *
 */
interface IwstETH is IERC20 {
    function stETH() external returns (IstETH);

    /**
     * @notice Exchanges stETH to wstETH
     * @param _stETHAmount amount of stETH to wrap in exchange for wstETH
     * @dev Requirements:
     *  - `_stETHAmount` must be non-zero
     *  - msg.sender must approve at least `_stETHAmount` stETH to this
     *    contract.
     *  - msg.sender must have at least `_stETHAmount` of stETH.
     * User should first approve _stETHAmount to the WstETH contract
     * @return Amount of wstETH user receives after wrap
     */
    function wrap(uint256 _stETHAmount) external returns (uint256);

    /**
     * @notice Exchanges wstETH to stETH
     * @param _wstETHAmount amount of wstETH to uwrap in exchange for stETH
     * @dev Requirements:
     *  - `_wstETHAmount` must be non-zero
     *  - msg.sender must have at least `_wstETHAmount` wstETH.
     * @return Amount of stETH user receives after unwrap
     */
    function unwrap(uint256 _wstETHAmount) external returns (uint256);

    /**
     * @notice Get amount of wstETH for a given amount of stETH
     * @param _stETHAmount amount of stETH
     * @return Amount of wstETH for a given stETH amount
     */
    function getWstETHByStETH(uint256 _stETHAmount) external view returns (uint256);

    /**
     * @notice Get amount of stETH for a given amount of wstETH
     * @param _wstETHAmount amount of wstETH
     * @return Amount of stETH for a given wstETH amount
     */
    function getStETHByWstETH(uint256 _wstETHAmount) external view returns (uint256);

    /**
     * @notice Get amount of wstETH for a one stETH
     * @return Amount of stETH for 1 wstETH
     */
    function stEthPerToken() external view returns (uint256);

    /**
     * @notice Get amount of stETH for a one wstETH
     * @return Amount of wstETH for a 1 stETH
     */
    function tokensPerStEth() external view returns (uint256);
}

File 26 of 51 : IAsset.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

/**
 * @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero
 * address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like
 * types.
 *
 * This concept is unrelated to a Pool's Asset Managers.
 */
interface IAsset {
    // solhint-disable-previous-line no-empty-blocks
}

File 27 of 51 : IAuthorizer.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

interface IAuthorizer {
    /**
     * @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`.
     */
    function canPerform(
        bytes32 actionId,
        address account,
        address where
    ) external view returns (bool);
}

File 28 of 51 : IBasePool.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./IVault.sol";
import "./IPoolSwapStructs.sol";

/**
 * @dev Interface for adding and removing liquidity that all Pool contracts should implement. Note that this is not
 * the complete Pool contract interface, as it is missing the swap hooks. Pool contracts should also inherit from
 * either IGeneralPool or IMinimalSwapInfoPool
 */
interface IBasePool is IPoolSwapStructs {
    /**
     * @dev Called by the Vault when a user calls `IVault.joinPool` to add liquidity to this Pool. Returns how many of
     * each registered token the user should provide, as well as the amount of protocol fees the Pool owes to the Vault.
     * The Vault will then take tokens from `sender` and add them to the Pool's balances, as well as collect
     * the reported amount in protocol fees, which the pool should calculate based on `protocolSwapFeePercentage`.
     *
     * Protocol fees are reported and charged on join events so that the Pool is free of debt whenever new users join.
     *
     * `sender` is the account performing the join (from which tokens will be withdrawn), and `recipient` is the account
     * designated to receive any benefits (typically pool shares). `balances` contains the total balances
     * for each token the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return.
     *
     * `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total
     * balance.
     *
     * `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of
     * join (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.)
     *
     * Contracts implementing this function should check that the caller is indeed the Vault before performing any
     * state-changing operations, such as minting pool shares.
     */
    function onJoinPool(
        bytes32 poolId,
        address sender,
        address recipient,
        uint256[] memory balances,
        uint256 lastChangeBlock,
        uint256 protocolSwapFeePercentage,
        bytes memory userData
    ) external returns (uint256[] memory amountsIn, uint256[] memory dueProtocolFeeAmounts);

    /**
     * @dev Called by the Vault when a user calls `IVault.exitPool` to remove liquidity from this Pool. Returns how many
     * tokens the Vault should deduct from the Pool's balances, as well as the amount of protocol fees the Pool owes
     * to the Vault. The Vault will then take tokens from the Pool's balances and send them to `recipient`,
     * as well as collect the reported amount in protocol fees, which the Pool should calculate based on
     * `protocolSwapFeePercentage`.
     *
     * Protocol fees are charged on exit events to guarantee that users exiting the Pool have paid their share.
     *
     * `sender` is the account performing the exit (typically the pool shareholder), and `recipient` is the account
     * to which the Vault will send the proceeds. `balances` contains the total token balances for each token
     * the Pool registered in the Vault, in the same order that `IVault.getPoolTokens` would return.
     *
     * `lastChangeBlock` is the last block in which *any* of the Pool's registered tokens last changed its total
     * balance.
     *
     * `userData` contains any pool-specific instructions needed to perform the calculations, such as the type of
     * exit (e.g., proportional given an amount of pool shares, single-asset, multi-asset, etc.)
     *
     * Contracts implementing this function should check that the caller is indeed the Vault before performing any
     * state-changing operations, such as burning pool shares.
     */
    function onExitPool(
        bytes32 poolId,
        address sender,
        address recipient,
        uint256[] memory balances,
        uint256 lastChangeBlock,
        uint256 protocolSwapFeePercentage,
        bytes memory userData
    ) external returns (uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts);

    /**
     * @dev Returns this Pool's ID, used when interacting with the Vault (to e.g. join the Pool or swap with it).
     */
    function getPoolId() external view returns (bytes32);

    /**
     * @dev Returns the current swap fee percentage as a 18 decimal fixed point number, so e.g. 1e17 corresponds to a
     * 10% swap fee.
     */
    function getSwapFeePercentage() external view returns (uint256);

    /**
     * @dev Returns the scaling factors of each of the Pool's tokens. This is an implementation detail that is typically
     * not relevant for outside parties, but which might be useful for some types of Pools.
     */
    function getScalingFactors() external view returns (uint256[] memory);

    function queryJoin(
        bytes32 poolId,
        address sender,
        address recipient,
        uint256[] memory balances,
        uint256 lastChangeBlock,
        uint256 protocolSwapFeePercentage,
        bytes memory userData
    ) external returns (uint256 bptOut, uint256[] memory amountsIn);

    function queryExit(
        bytes32 poolId,
        address sender,
        address recipient,
        uint256[] memory balances,
        uint256 lastChangeBlock,
        uint256 protocolSwapFeePercentage,
        bytes memory userData
    ) external returns (uint256 bptIn, uint256[] memory amountsOut);
}

File 29 of 51 : IFlashLoanRecipient.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

// Inspired by Aave Protocol's IFlashLoanReceiver.

import "../solidity-utils/openzeppelin/IERC20.sol";

interface IFlashLoanRecipient {
    /**
     * @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient.
     *
     * At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this
     * call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the
     * Vault, or else the entire flash loan will revert.
     *
     * `userData` is the same value passed in the `IVault.flashLoan` call.
     */
    function receiveFlashLoan(
        IERC20[] memory tokens,
        uint256[] memory amounts,
        uint256[] memory feeAmounts,
        bytes memory userData
    ) external;
}

File 30 of 51 : IPoolSwapStructs.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../solidity-utils/openzeppelin/IERC20.sol";

import "./IVault.sol";

interface IPoolSwapStructs {
    // This is not really an interface - it just defines common structs used by other interfaces: IGeneralPool and
    // IMinimalSwapInfoPool.
    //
    // This data structure represents a request for a token swap, where `kind` indicates the swap type ('given in' or
    // 'given out') which indicates whether or not the amount sent by the pool is known.
    //
    // The pool receives `tokenIn` and sends `tokenOut`. `amount` is the number of `tokenIn` tokens the pool will take
    // in, or the number of `tokenOut` tokens the Pool will send out, depending on the given swap `kind`.
    //
    // All other fields are not strictly necessary for most swaps, but are provided to support advanced scenarios in
    // some Pools.
    //
    // `poolId` is the ID of the Pool involved in the swap - this is useful for Pool contracts that implement more than
    // one Pool.
    //
    // The meaning of `lastChangeBlock` depends on the Pool specialization:
    //  - Two Token or Minimal Swap Info: the last block in which either `tokenIn` or `tokenOut` changed its total
    //    balance.
    //  - General: the last block in which *any* of the Pool's registered tokens changed its total balance.
    //
    // `from` is the origin address for the funds the Pool receives, and `to` is the destination address
    // where the Pool sends the outgoing tokens.
    //
    // `userData` is extra data provided by the caller - typically a signature from a trusted party.
    struct SwapRequest {
        IVault.SwapKind kind;
        IERC20 tokenIn;
        IERC20 tokenOut;
        uint256 amount;
        // Misc data
        bytes32 poolId;
        uint256 lastChangeBlock;
        address from;
        address to;
        bytes userData;
    }
}

File 31 of 51 : IProtocolFeesCollector.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../solidity-utils/openzeppelin/IERC20.sol";

import "./IVault.sol";
import "./IAuthorizer.sol";

interface IProtocolFeesCollector {
    event SwapFeePercentageChanged(uint256 newSwapFeePercentage);
    event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage);

    function withdrawCollectedFees(
        IERC20[] calldata tokens,
        uint256[] calldata amounts,
        address recipient
    ) external;

    function setSwapFeePercentage(uint256 newSwapFeePercentage) external;

    function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external;

    function getSwapFeePercentage() external view returns (uint256);

    function getFlashLoanFeePercentage() external view returns (uint256);

    function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts);

    function getAuthorizer() external view returns (IAuthorizer);

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

File 32 of 51 : IVault.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma experimental ABIEncoderV2;

import "../solidity-utils/openzeppelin/IERC20.sol";
import "../solidity-utils/helpers/IAuthentication.sol";
import "../solidity-utils/helpers/ISignaturesValidator.sol";
import "../solidity-utils/helpers/ITemporarilyPausable.sol";
import "../solidity-utils/misc/IWETH.sol";

import "./IAsset.sol";
import "./IAuthorizer.sol";
import "./IFlashLoanRecipient.sol";
import "./IProtocolFeesCollector.sol";

pragma solidity >=0.7.0 <0.9.0;

/**
 * @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that
 * don't override one of these declarations.
 */
interface IVault is ISignaturesValidator, ITemporarilyPausable, IAuthentication {
    // Generalities about the Vault:
    //
    // - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are
    // transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling
    // `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by
    // calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning
    // a boolean value: in these scenarios, a non-reverting call is assumed to be successful.
    //
    // - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g.
    // while execution control is transferred to a token contract during a swap) will result in a revert. View
    // functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results.
    // Contracts calling view functions in the Vault must make sure the Vault has not already been entered.
    //
    // - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools.

    // Authorizer
    //
    // Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists
    // outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller
    // can perform a given action.

    /**
     * @dev Returns the Vault's Authorizer.
     */
    function getAuthorizer() external view returns (IAuthorizer);

    /**
     * @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this.
     *
     * Emits an `AuthorizerChanged` event.
     */
    function setAuthorizer(IAuthorizer newAuthorizer) external;

    /**
     * @dev Emitted when a new authorizer is set by `setAuthorizer`.
     */
    event AuthorizerChanged(IAuthorizer indexed newAuthorizer);

    // Relayers
    //
    // Additionally, it is possible for an account to perform certain actions on behalf of another one, using their
    // Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions,
    // and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield
    // this power, two things must occur:
    //  - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This
    //    means that Balancer governance must approve each individual contract to act as a relayer for the intended
    //    functions.
    //  - Each user must approve the relayer to act on their behalf.
    // This double protection means users cannot be tricked into approving malicious relayers (because they will not
    // have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised
    // Authorizer or governance drain user funds, since they would also need to be approved by each individual user.

    /**
     * @dev Returns true if `user` has approved `relayer` to act as a relayer for them.
     */
    function hasApprovedRelayer(address user, address relayer) external view returns (bool);

    /**
     * @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise.
     *
     * Emits a `RelayerApprovalChanged` event.
     */
    function setRelayerApproval(
        address sender,
        address relayer,
        bool approved
    ) external;

    /**
     * @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`.
     */
    event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved);

    // Internal Balance
    //
    // Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later
    // transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination
    // when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced
    // gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users.
    //
    // Internal Balance management features batching, which means a single contract call can be used to perform multiple
    // operations of different kinds, with different senders and recipients, at once.

    /**
     * @dev Returns `user`'s Internal Balance for a set of tokens.
     */
    function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory);

    /**
     * @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer)
     * and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as
     * it lets integrators reuse a user's Vault allowance.
     *
     * For each operation, if the caller is not `sender`, it must be an authorized relayer for them.
     */
    function manageUserBalance(UserBalanceOp[] memory ops) external payable;

    /**
     * @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received
     without manual WETH wrapping or unwrapping.
     */
    struct UserBalanceOp {
        UserBalanceOpKind kind;
        IAsset asset;
        uint256 amount;
        address sender;
        address payable recipient;
    }

    // There are four possible operations in `manageUserBalance`:
    //
    // - DEPOSIT_INTERNAL
    // Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding
    // `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`.
    //
    // ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped
    // and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is
    // relevant for relayers).
    //
    // Emits an `InternalBalanceChanged` event.
    //
    //
    // - WITHDRAW_INTERNAL
    // Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`.
    //
    // ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send
    // it to the recipient as ETH.
    //
    // Emits an `InternalBalanceChanged` event.
    //
    //
    // - TRANSFER_INTERNAL
    // Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`.
    //
    // Reverts if the ETH sentinel value is passed.
    //
    // Emits an `InternalBalanceChanged` event.
    //
    //
    // - TRANSFER_EXTERNAL
    // Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by
    // relayers, as it lets them reuse a user's Vault allowance.
    //
    // Reverts if the ETH sentinel value is passed.
    //
    // Emits an `ExternalBalanceTransfer` event.

    enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL }

    /**
     * @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through
     * interacting with Pools using Internal Balance.
     *
     * Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH
     * address.
     */
    event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta);

    /**
     * @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account.
     */
    event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount);

    // Pools
    //
    // There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced
    // functionality:
    //
    //  - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the
    // balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads),
    // which increase with the number of registered tokens.
    //
    //  - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the
    // balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted
    // constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are
    // independent of the number of registered tokens.
    //
    //  - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like
    // minimal swap info Pools, these are called via IMinimalSwapInfoPool.

    enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN }

    /**
     * @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which
     * is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be
     * changed.
     *
     * The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`,
     * depending on the chosen specialization setting. This contract is known as the Pool's contract.
     *
     * Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words,
     * multiple Pools may share the same contract.
     *
     * Emits a `PoolRegistered` event.
     */
    function registerPool(PoolSpecialization specialization) external returns (bytes32);

    /**
     * @dev Emitted when a Pool is registered by calling `registerPool`.
     */
    event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization);

    /**
     * @dev Returns a Pool's contract address and specialization setting.
     */
    function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);

    /**
     * @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
     *
     * Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens,
     * exit by receiving registered tokens, and can only swap registered tokens.
     *
     * Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length
     * of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in
     * ascending order.
     *
     * The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset
     * Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`,
     * depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore
     * expected to be highly secured smart contracts with sound design principles, and the decision to register an
     * Asset Manager should not be made lightly.
     *
     * Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset
     * Manager is set, it cannot be changed except by deregistering the associated token and registering again with a
     * different Asset Manager.
     *
     * Emits a `TokensRegistered` event.
     */
    function registerTokens(
        bytes32 poolId,
        IERC20[] memory tokens,
        address[] memory assetManagers
    ) external;

    /**
     * @dev Emitted when a Pool registers tokens by calling `registerTokens`.
     */
    event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers);

    /**
     * @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
     *
     * Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total
     * balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens
     * must be deregistered in the same `deregisterTokens` call.
     *
     * A deregistered token can be re-registered later on, possibly with a different Asset Manager.
     *
     * Emits a `TokensDeregistered` event.
     */
    function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external;

    /**
     * @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`.
     */
    event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens);

    /**
     * @dev Returns detailed information for a Pool's registered token.
     *
     * `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens
     * withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token`
     * equals the sum of `cash` and `managed`.
     *
     * Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`,
     * `managed` or `total` balance to be greater than 2^112 - 1.
     *
     * `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a
     * join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for
     * example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a
     * change for this purpose, and will update `lastChangeBlock`.
     *
     * `assetManager` is the Pool's token Asset Manager.
     */
    function getPoolTokenInfo(bytes32 poolId, IERC20 token)
        external
        view
        returns (
            uint256 cash,
            uint256 managed,
            uint256 lastChangeBlock,
            address assetManager
        );

    /**
     * @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
        );

    /**
     * @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will
     * trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized
     * Pool shares.
     *
     * If the caller is not `sender`, it must be an authorized relayer for them.
     *
     * The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount
     * to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces
     * these maximums.
     *
     * If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable
     * this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the
     * WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent
     * back to the caller (not the sender, which is important for relayers).
     *
     * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
     * interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be
     * sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final
     * `assets` array might not be sorted. Pools with no registered tokens cannot be joined.
     *
     * If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only
     * be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be
     * withdrawn from Internal Balance: attempting to do so will trigger a revert.
     *
     * This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement
     * their own custom logic. This typically requires additional information from the user (such as the expected number
     * of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed
     * directly to the Pool's contract, as is `recipient`.
     *
     * Emits a `PoolBalanceChanged` event.
     */
    function joinPool(
        bytes32 poolId,
        address sender,
        address recipient,
        JoinPoolRequest memory request
    ) external payable;

    struct JoinPoolRequest {
        IAsset[] assets;
        uint256[] maxAmountsIn;
        bytes userData;
        bool fromInternalBalance;
    }

    /**
     * @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will
     * trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized
     * Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see
     * `getPoolTokenInfo`).
     *
     * If the caller is not `sender`, it must be an authorized relayer for them.
     *
     * The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum
     * token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault:
     * it just enforces these minimums.
     *
     * If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To
     * enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead
     * of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit.
     *
     * `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
     * interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must
     * be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the
     * final `assets` array might not be sorted. Pools with no registered tokens cannot be exited.
     *
     * If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise,
     * an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to
     * do so will trigger a revert.
     *
     * `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the
     * `tokens` array. This array must match the Pool's registered tokens.
     *
     * This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement
     * their own custom logic. This typically requires additional information from the user (such as the expected number
     * of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and
     * passed directly to the Pool's contract.
     *
     * Emits a `PoolBalanceChanged` event.
     */
    function exitPool(
        bytes32 poolId,
        address sender,
        address payable recipient,
        ExitPoolRequest memory request
    ) external;

    struct ExitPoolRequest {
        IAsset[] assets;
        uint256[] minAmountsOut;
        bytes userData;
        bool toInternalBalance;
    }

    /**
     * @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively.
     */
    event PoolBalanceChanged(
        bytes32 indexed poolId,
        address indexed liquidityProvider,
        IERC20[] tokens,
        int256[] deltas,
        uint256[] protocolFeeAmounts
    );

    enum PoolBalanceChangeKind { JOIN, EXIT }

    // Swaps
    //
    // Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this,
    // they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be
    // aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote.
    //
    // The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence.
    // In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'),
    // and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out').
    // More complex swaps, such as one token in to multiple tokens out can be achieved by batching together
    // individual swaps.
    //
    // There are two swap kinds:
    //  - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the
    // `onSwap` hook) the amount of tokens out (to send to the recipient).
    //  - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines
    // (via the `onSwap` hook) the amount of tokens in (to receive from the sender).
    //
    // Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with
    // the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated
    // tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended
    // swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at
    // the final intended token.
    //
    // In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal
    // Balance) after all individual swaps have been completed, and the net token balance change computed. This makes
    // certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost
    // much less gas than they would otherwise.
    //
    // It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple
    // Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only
    // updating the Pool's internal accounting).
    //
    // To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token
    // involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the
    // minimum amount of tokens to receive (by passing a negative value) is specified.
    //
    // Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after
    // this point in time (e.g. if the transaction failed to be included in a block promptly).
    //
    // If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do
    // the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be
    // passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the
    // same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers).
    //
    // Finally, Internal Balance can be used when either sending or receiving tokens.

    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 Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either
     * the amount of tokens sent to or received from the Pool, depending on the `kind` value.
     *
     * Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the
     * Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at
     * the same index in the `assets` array.
     *
     * Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a
     * Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or
     * `amountOut` depending on the swap kind.
     *
     * Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out
     * of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal
     * the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`.
     *
     * The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses,
     * or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and
     * out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to
     * or unwrapped from WETH by the Vault.
     *
     * Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies
     * the minimum or maximum amount of each token the vault is allowed to transfer.
     *
     * `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the
     * equivalent `swap` call.
     *
     * Emits `Swap` events.
     */
    function batchSwap(
        SwapKind kind,
        BatchSwapStep[] memory swaps,
        IAsset[] memory assets,
        FundManagement memory funds,
        int256[] memory limits,
        uint256 deadline
    ) external payable returns (int256[] memory);

    /**
     * @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the
     * `assets` array passed to that function, and ETH assets are converted to WETH.
     *
     * If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out
     * from the previous swap, depending on the swap kind.
     *
     * 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 BatchSwapStep {
        bytes32 poolId;
        uint256 assetInIndex;
        uint256 assetOutIndex;
        uint256 amount;
        bytes userData;
    }

    /**
     * @dev Emitted for each individual swap performed by `swap` or `batchSwap`.
     */
    event Swap(
        bytes32 indexed poolId,
        IERC20 indexed tokenIn,
        IERC20 indexed tokenOut,
        uint256 amountIn,
        uint256 amountOut
    );

    /**
     * @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;
    }

    /**
     * @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.
     */
    function queryBatchSwap(
        SwapKind kind,
        BatchSwapStep[] memory swaps,
        IAsset[] memory assets,
        FundManagement memory funds
    ) external returns (int256[] memory assetDeltas);

    // Flash Loans

    /**
     * @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it,
     * and then reverting unless the tokens plus a proportional protocol fee have been returned.
     *
     * The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount
     * for each token contract. `tokens` must be sorted in ascending order.
     *
     * The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the
     * `receiveFlashLoan` call.
     *
     * Emits `FlashLoan` events.
     */
    function flashLoan(
        IFlashLoanRecipient recipient,
        IERC20[] memory tokens,
        uint256[] memory amounts,
        bytes memory userData
    ) external;

    /**
     * @dev Emitted for each individual flash loan performed by `flashLoan`.
     */
    event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount);

    // Asset Management
    //
    // Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's
    // tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see
    // `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly
    // controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the
    // prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore
    // not constrained to the tokens they are managing, but extends to the entire Pool's holdings.
    //
    // However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit,
    // for example by lending unused tokens out for interest, or using them to participate in voting protocols.
    //
    // This concept is unrelated to the IAsset interface.

    /**
     * @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates.
     *
     * Pool Balance management features batching, which means a single contract call can be used to perform multiple
     * operations of different kinds, with different Pools and tokens, at once.
     *
     * For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`.
     */
    function managePoolBalance(PoolBalanceOp[] memory ops) external;

    struct PoolBalanceOp {
        PoolBalanceOpKind kind;
        bytes32 poolId;
        IERC20 token;
        uint256 amount;
    }

    /**
     * Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged.
     *
     * Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged.
     *
     * Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total.
     * The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss).
     */
    enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE }

    /**
     * @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`.
     */
    event PoolBalanceManaged(
        bytes32 indexed poolId,
        address indexed assetManager,
        IERC20 indexed token,
        int256 cashDelta,
        int256 managedDelta
    );

    // Protocol Fees
    //
    // Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by
    // permissioned accounts.
    //
    // There are two kinds of protocol fees:
    //
    //  - flash loan fees: charged on all flash loans, as a percentage of the amounts lent.
    //
    //  - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including
    // swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather,
    // Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the
    // Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as
    // exiting a Pool in debt without first paying their share.

    /**
     * @dev Returns the current protocol fee module.
     */
    function getProtocolFeesCollector() external view returns (IProtocolFeesCollector);

    /**
     * @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an
     * error in some part of the system.
     *
     * The Vault can only be paused during an initial time period, after which pausing is forever disabled.
     *
     * While the contract is paused, the following features are disabled:
     * - depositing and transferring internal balance
     * - transferring external balance (using the Vault's allowance)
     * - swaps
     * - joining Pools
     * - Asset Manager interactions
     *
     * Internal Balance can still be withdrawn, and Pools exited.
     */
    function setPaused(bool paused) external;

    /**
     * @dev Returns the Vault's WETH instance.
     */
    function WETH() external view returns (IWETH);
    // solhint-disable-previous-line func-name-mixedcase
}

File 33 of 51 : InputHelpers.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20.sol";
import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol";

library InputHelpers {
    function ensureInputLengthMatch(uint256 a, uint256 b) internal pure {
        _require(a == b, Errors.INPUT_LENGTH_MISMATCH);
    }

    function ensureInputLengthMatch(
        uint256 a,
        uint256 b,
        uint256 c
    ) internal pure {
        _require(a == b && b == c, Errors.INPUT_LENGTH_MISMATCH);
    }

    function ensureArrayIsSorted(IERC20[] memory array) internal pure {
        address[] memory addressArray;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            addressArray := array
        }
        ensureArrayIsSorted(addressArray);
    }

    function ensureArrayIsSorted(address[] memory array) internal pure {
        if (array.length < 2) {
            return;
        }

        address previous = array[0];
        for (uint256 i = 1; i < array.length; ++i) {
            address current = array[i];
            _require(previous < current, Errors.UNSORTED_ARRAY);
            previous = current;
        }
    }
}

File 34 of 51 : VaultHelpers.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;

library VaultHelpers {
    /**
     * @dev Returns the address of a Pool's contract.
     *
     * This is the same code the Vault runs in `PoolRegistry._getPoolAddress`.
     */
    function toPoolAddress(bytes32 poolId) internal pure returns (address) {
        // 12 byte logical shift left to remove the nonce and specialization setting. We don't need to mask,
        // since the logical shift already sets the upper bits to zero.
        return address(uint256(poolId) >> (12 * 8));
    }
}

File 35 of 51 : Version.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/IVersion.sol";

/**
 * @notice Retrieves a contract's version set at creation time from storage.
 */
contract Version is IVersion {
    string private _version;

    constructor(string memory version) {
        _setVersion(version);
    }

    function version() external view override returns (string memory) {
        return _version;
    }

    /**
     * @dev Internal setter that allows this contract to be used in proxies.
     */
    function _setVersion(string memory newVersion) internal {
        _version = newVersion;
    }
}

File 36 of 51 : Math.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol";

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow checks.
 * Adapted from OpenZeppelin's SafeMath library.
 */
library Math {
    // solhint-disable no-inline-assembly

    /**
     * @dev Returns the absolute value of a signed integer.
     */
    function abs(int256 a) internal pure returns (uint256 result) {
        // Equivalent to:
        // result = a > 0 ? uint256(a) : uint256(-a)
        assembly {
            let s := sar(255, a)
            result := sub(xor(a, s), s)
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers of 256 bits, reverting on overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        _require(c >= a, Errors.ADD_OVERFLOW);
        return c;
    }

    /**
     * @dev Returns the addition of two signed integers, reverting on overflow.
     */
    function add(int256 a, int256 b) internal pure returns (int256) {
        int256 c = a + b;
        _require((b >= 0 && c >= a) || (b < 0 && c < a), Errors.ADD_OVERFLOW);
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers of 256 bits, reverting on overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        _require(b <= a, Errors.SUB_OVERFLOW);
        uint256 c = a - b;
        return c;
    }

    /**
     * @dev Returns the subtraction of two signed integers, reverting on overflow.
     */
    function sub(int256 a, int256 b) internal pure returns (int256) {
        int256 c = a - b;
        _require((b >= 0 && c <= a) || (b < 0 && c > a), Errors.SUB_OVERFLOW);
        return c;
    }

    /**
     * @dev Returns the largest of two numbers of 256 bits.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256 result) {
        // Equivalent to:
        // result = (a < b) ? b : a;
        assembly {
            result := sub(a, mul(sub(a, b), lt(a, b)))
        }
    }

    /**
     * @dev Returns the smallest of two numbers of 256 bits.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256 result) {
        // Equivalent to `result = (a < b) ? a : b`
        assembly {
            result := sub(a, mul(sub(a, b), gt(a, b)))
        }
    }

    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a * b;
        _require(a == 0 || c / a == b, Errors.MUL_OVERFLOW);
        return c;
    }

    function div(
        uint256 a,
        uint256 b,
        bool roundUp
    ) internal pure returns (uint256) {
        return roundUp ? divUp(a, b) : divDown(a, b);
    }

    function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
        _require(b != 0, Errors.ZERO_DIVISION);
        return a / b;
    }

    function divUp(uint256 a, uint256 b) internal pure returns (uint256 result) {
        _require(b != 0, Errors.ZERO_DIVISION);

        // Equivalent to:
        // result = a == 0 ? 0 : 1 + (a - 1) / b;
        assembly {
            result := mul(iszero(iszero(a)), add(1, div(sub(a, 1), b)))
        }
    }
}

File 37 of 51 : Address.sol
// SPDX-License-Identifier: MIT

// Based on the Address library from OpenZeppelin Contracts, altered by removing the `isContract` checks on
// `functionCall` and `functionDelegateCall` in order to save gas, as the recipients are known to be contracts.

pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol";

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    // solhint-disable max-line-length

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        _require(address(this).balance >= amount, Errors.ADDRESS_INSUFFICIENT_BALANCE);

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        _require(success, Errors.ADDRESS_CANNOT_SEND_VALUE);
    }

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

    // solhint-enable max-line-length

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but passing some native ETH as msg.value to the call.
     *
     * _Available since v3.4._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return verifyCallResult(success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling up the
     * revert reason or using the one provided.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly
                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                _revert(Errors.LOW_LEVEL_CALL_FAILED);
            }
        }
    }
}

File 38 of 51 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

// Based on the ReentrancyGuard library from OpenZeppelin Contracts, altered to reduce bytecode size.
// Modifier code is inlined by the compiler, which causes its code to appear multiple times in the codebase. By using
// private functions, we achieve the same end result with slightly higher runtime gas costs, but reduced bytecode size.

pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol";

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _enterNonReentrant();
        _;
        _exitNonReentrant();
    }

    function _enterNonReentrant() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        _require(_status != _ENTERED, Errors.REENTRANCY);

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

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

File 39 of 51 : SafeERC20.sol
// SPDX-License-Identifier: MIT

// Based on the ReentrancyGuard library from OpenZeppelin Contracts, altered to reduce gas costs.
// The `safeTransfer` and `safeTransferFrom` functions assume that `token` is a contract (an account with code), and
// work differently from the OpenZeppelin version if it is not.

pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol";
import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20.sol";

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

    function safeApprove(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        // Some contracts need their allowance reduced to 0 before setting it to an arbitrary amount.
        if (value != 0 && token.allowance(address(this), address(to)) != 0) {
            _callOptionalReturn(address(token), abi.encodeWithSelector(token.approve.selector, to, 0));
        }

        _callOptionalReturn(address(token), abi.encodeWithSelector(token.approve.selector, to, value));
    }

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     *
     * WARNING: `token` is assumed to be a contract: calls to EOAs will *not* revert.
     */
    function _callOptionalReturn(address token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves.
        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = token.call(data);

        // If the low-level call didn't succeed we return whatever was returned from it.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            if eq(success, 0) {
                returndatacopy(0, 0, returndatasize())
                revert(0, returndatasize())
            }
        }

        // Finally we check the returndata size is either zero or true - note that this check will always pass for EOAs
        _require(returndata.length == 0 || abi.decode(returndata, (bool)), Errors.SAFE_ERC20_CALL_FAILED);
    }
}

File 40 of 51 : AssetHelpers.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20.sol";
import "@balancer-labs/v2-interfaces/contracts/solidity-utils/misc/IWETH.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IAsset.sol";

abstract contract AssetHelpers {
    // solhint-disable-next-line var-name-mixedcase
    IWETH private immutable _weth;

    // Sentinel value used to indicate WETH with wrapping/unwrapping semantics. The zero address is a good choice for
    // multiple reasons: it is cheap to pass as a calldata argument, it is a known invalid token and non-contract, and
    // it is an address Pools cannot register as a token.
    address private constant _ETH = address(0);

    constructor(IWETH weth) {
        _weth = weth;
    }

    // solhint-disable-next-line func-name-mixedcase
    function _WETH() internal view returns (IWETH) {
        return _weth;
    }

    /**
     * @dev Returns true if `asset` is the sentinel value that represents ETH.
     */
    function _isETH(IAsset asset) internal pure returns (bool) {
        return address(asset) == _ETH;
    }

    /**
     * @dev Translates `asset` into an equivalent IERC20 token address. If `asset` represents ETH, it will be translated
     * to the WETH contract.
     */
    function _translateToIERC20(IAsset asset) internal view returns (IERC20) {
        return _isETH(asset) ? _WETH() : _asIERC20(asset);
    }

    /**
     * @dev Same as `_translateToIERC20(IAsset)`, but for an entire array.
     */
    function _translateToIERC20(IAsset[] memory assets) internal view returns (IERC20[] memory) {
        IERC20[] memory tokens = new IERC20[](assets.length);
        for (uint256 i = 0; i < assets.length; ++i) {
            tokens[i] = _translateToIERC20(assets[i]);
        }
        return tokens;
    }

    /**
     * @dev Interprets `asset` as an IERC20 token. This function should only be called on `asset` if `_isETH` previously
     * returned false for it, that is, if `asset` is guaranteed not to be the ETH sentinel value.
     */
    function _asIERC20(IAsset asset) internal pure returns (IERC20) {
        return IERC20(address(asset));
    }
}

File 41 of 51 : BatchRelayerQueryLibrary.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "./relayer/BaseRelayerLibraryCommon.sol";

import "./relayer/VaultQueryActions.sol";

/**
 * @title Batch Relayer Library
 * @notice This contract is not a relayer by itself and calls into it directly will fail.
 * The associated relayer can be found by calling `getEntrypoint` on this contract.
 */
contract BatchRelayerQueryLibrary is BaseRelayerLibraryCommon, VaultQueryActions {
    constructor(IVault vault) BaseRelayerLibraryCommon(vault) {
        //solhint-disable-previous-line no-empty-blocks
    }
}

File 42 of 51 : BalancerRelayer.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IBalancerRelayer.sol";

import "@balancer-labs/v2-solidity-utils/contracts/helpers/Version.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ReentrancyGuard.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/Address.sol";

/**
 * @title Balancer Relayer
 * @notice Allows safe multicall execution of a relayer's functions
 * @dev
 * Relayers are composed of two contracts:
 *  - This contract, which acts as a single point of entry into the system through a multicall function.
 *  - A library contract, which defines the allowed behaviour of the relayer.
 *
 * The relayer entrypoint can then repeatedly delegatecall into the library's code to perform actions.
 * We can then run combinations of the library contract's functions in the context of the relayer entrypoint,
 * without having to expose all these functions on the entrypoint contract itself. The multicall function is
 * then a single point of entry for all actions, so we can easily prevent reentrancy.
 *
 * This design gives much stronger reentrancy guarantees, as otherwise a malicious contract could reenter
 * the relayer through another function (which must allow reentrancy for multicall logic), and that would
 * potentially allow them to manipulate global state, resulting in loss of funds in some cases:
 * e.g., sweeping any leftover ETH that should have been refunded to the user.
 *
 * NOTE: Only the entrypoint contract should be allowlisted by Balancer governance as a relayer, so that the
 * Vault will reject calls from outside the context of the entrypoint: e.g., if a user mistakenly called directly
 * into the library contract.
 */
contract BalancerRelayer is IBalancerRelayer, Version, ReentrancyGuard {
    using Address for address payable;
    using Address for address;

    IVault private immutable _vault;
    address private immutable _library;
    address private immutable _queryLibrary;

    /**
     * @dev This contract is not meant to be deployed directly by an EOA, but rather during construction of a contract
     * derived from `BaseRelayerLibrary`, which will provide its own address as the relayer's library.
     */
    constructor(
        IVault vault,
        address libraryAddress,
        address queryLibrary,
        string memory version
    ) Version(version) {
        _vault = vault;
        _library = libraryAddress;
        _queryLibrary = queryLibrary;
    }

    receive() external payable {
        // Only accept ETH transfers from the Vault. This is expected to happen due to a swap/exit/withdrawal
        // with ETH as an output, should the relayer be listed as the recipient. This may also happen when
        // joining a pool, performing a swap, or if managing a user's balance uses less than the full ETH value
        // provided. Any excess ETH will be refunded to this contract, and then forwarded to the original sender.
        _require(msg.sender == address(_vault), Errors.ETH_TRANSFER);
    }

    function getVault() external view override returns (IVault) {
        return _vault;
    }

    function getLibrary() external view override returns (address) {
        return _library;
    }

    function getQueryLibrary() external view override returns (address) {
        return _queryLibrary;
    }

    function multicall(bytes[] calldata data) external payable override nonReentrant returns (bytes[] memory results) {
        uint256 numData = data.length;

        results = new bytes[](numData);
        for (uint256 i = 0; i < numData; i++) {
            results[i] = _library.functionDelegateCall(data[i]);
        }

        _refundETH();
    }

    function vaultActionsQueryMulticall(bytes[] calldata data)
        external
        override
        nonReentrant
        returns (bytes[] memory results)
    {
        uint256 numData = data.length;

        results = new bytes[](numData);
        for (uint256 i = 0; i < numData; i++) {
            results[i] = _queryLibrary.functionDelegateCall(data[i]);
        }
    }

    function _refundETH() private {
        uint256 remainingEth = address(this).balance;
        if (remainingEth > 0) {
            msg.sender.sendValue(remainingEth);
        }
    }
}

File 43 of 51 : BaseRelayerLibrary.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IBalancerRelayer.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeERC20.sol";

import "./IBaseRelayerLibrary.sol";
import "../BatchRelayerQueryLibrary.sol";
import "./BalancerRelayer.sol";

/**
 * @title Base Relayer Library
 * @notice Core functionality of a relayer. Allow users to use a signature to approve this contract
 * to take further actions on their behalf.
 * @dev
 * Relayers are composed of two contracts:
 *  - A `BalancerRelayer` contract, which acts as a single point of entry into the system through a multicall function
 *  - A library contract such as this one, which defines the allowed behaviour of the relayer

 * NOTE: Only the entrypoint contract should be allowlisted by Balancer governance as a relayer, so that the Vault
 * will reject calls from outside the entrypoint context.
 *
 * This contract should neither be allowlisted as a relayer, nor called directly by the user.
 * No guarantees can be made about fund safety when calling this contract in an improper manner.
 *
 * All functions that are meant to be called from the entrypoint via `multicall` must be payable so that they
 * do not revert in a call involving ETH. This also applies to functions that do not alter the state and would be
 * usually labeled as `view`.
 */
contract BaseRelayerLibrary is BaseRelayerLibraryCommon {
    using Address for address;
    using SafeERC20 for IERC20;

    IVault private immutable _vault;
    IBalancerRelayer private immutable _entrypoint;

    constructor(IVault vault, string memory version) BaseRelayerLibraryCommon(vault) {
        _vault = vault;

        IBaseRelayerLibrary queryLibrary = new BatchRelayerQueryLibrary(vault);

        _entrypoint = new BalancerRelayer(vault, address(this), address(queryLibrary), version);
    }

    function getEntrypoint() external view returns (IBalancerRelayer) {
        return _entrypoint;
    }

    /**
     * @notice Sets whether a particular relayer is authorised to act on behalf of the user
     */
    function setRelayerApproval(
        address relayer,
        bool approved,
        bytes calldata authorisation
    ) external payable {
        require(relayer == address(this) || !approved, "Relayer can only approve itself");
        bytes memory data = abi.encodePacked(
            abi.encodeWithSelector(_vault.setRelayerApproval.selector, msg.sender, relayer, approved),
            authorisation
        );

        address(_vault).functionCall(data);
    }
}

File 44 of 51 : BaseRelayerLibraryCommon.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IBalancerRelayer.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeERC20.sol";

import "./IBaseRelayerLibrary.sol";
import "./BalancerRelayer.sol";

/**
 * @title Base Relayer Library
 * @notice Core functionality of a relayer. Allow users to use a signature to approve this contract
 * to take further actions on their behalf.
 * @dev
 * Relayers are composed of two contracts:
 *  - A `BalancerRelayer` contract, which acts as a single point of entry into the system through a multicall function
 *  - A library contract such as this one, which defines the allowed behaviour of the relayer

 * NOTE: Only the entrypoint contract should be allowlisted by Balancer governance as a relayer, so that the Vault
 * will reject calls from outside the entrypoint context.
 *
 * This contract should neither be allowlisted as a relayer, nor called directly by the user.
 * No guarantees can be made about fund safety when calling this contract in an improper manner.
 *
 * All functions that are meant to be called from the entrypoint via `multicall` must be payable so that they
 * do not revert in a call involving ETH. This also applies to functions that do not alter the state and would be
 * usually labeled as `view`.
 */
abstract contract BaseRelayerLibraryCommon is IBaseRelayerLibrary {
    using Address for address;
    using SafeERC20 for IERC20;

    IVault private immutable _vault;

    constructor(IVault vault) IBaseRelayerLibrary(vault.WETH()) {
        _vault = vault;
    }

    function getVault() public view override returns (IVault) {
        return _vault;
    }

    /**
     * @notice Approves the Vault to use tokens held in the relayer
     * @dev This is needed to avoid having to send intermediate tokens back to the user
     */
    function approveVault(IERC20 token, uint256 amount) external payable override {
        if (_isChainedReference(amount)) {
            amount = _getChainedReferenceValue(amount);
        }
        // TODO: gas golf this a bit
        token.safeApprove(address(getVault()), amount);
    }

    /**
     * @notice Returns the amount referenced by chained reference `ref`.
     * @dev It does not alter the reference (even if it's marked as temporary).
     *
     * This function does not alter the state in any way. It is not marked as view because it has to be `payable`
     * in order to be used in a batch transaction.
     *
     * Use a static call to read the state off-chain.
     */
    function peekChainedReferenceValue(uint256 ref) external payable override returns (uint256 value) {
        (, value) = _peekChainedReferenceValue(ref);
    }

    function _pullToken(
        address sender,
        IERC20 token,
        uint256 amount
    ) internal override {
        if (amount == 0) return;
        IERC20[] memory tokens = new IERC20[](1);
        tokens[0] = token;
        uint256[] memory amounts = new uint256[](1);
        amounts[0] = amount;

        _pullTokens(sender, tokens, amounts);
    }

    function _pullTokens(
        address sender,
        IERC20[] memory tokens,
        uint256[] memory amounts
    ) internal override {
        IVault.UserBalanceOp[] memory ops = new IVault.UserBalanceOp[](tokens.length);
        for (uint256 i; i < tokens.length; i++) {
            ops[i] = IVault.UserBalanceOp({
                asset: IAsset(address(tokens[i])),
                amount: amounts[i],
                sender: sender,
                recipient: payable(address(this)),
                kind: IVault.UserBalanceOpKind.TRANSFER_EXTERNAL
            });
        }

        getVault().manageUserBalance(ops);
    }

    /**
     * @dev Returns true if `amount` is not actually an amount, but rather a chained reference.
     */
    function _isChainedReference(uint256 amount) internal pure override returns (bool) {
        // First 3 nibbles are enough to determine if it's a chained reference.
        return
            (amount & 0xfff0000000000000000000000000000000000000000000000000000000000000) ==
            0xba10000000000000000000000000000000000000000000000000000000000000;
    }

    /**
     * @dev Returns true if `ref` is temporary reference, i.e. to be deleted after reading it.
     */
    function _isTemporaryChainedReference(uint256 amount) internal pure returns (bool) {
        // First 3 nibbles determine if it's a chained reference.
        // If the 4th nibble is 0 it is temporary; otherwise it is considered read-only.
        // In practice, we shall use '0xba11' for read-only references.
        return
            (amount & 0xffff000000000000000000000000000000000000000000000000000000000000) ==
            0xba10000000000000000000000000000000000000000000000000000000000000;
    }

    /**
     * @dev Stores `value` as the amount referenced by chained reference `ref`.
     */
    function _setChainedReferenceValue(uint256 ref, uint256 value) internal override {
        bytes32 slot = _getStorageSlot(ref);

        // Since we do manual calculation of storage slots, it is easier (and cheaper) to rely on internal assembly to
        // access it.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            sstore(slot, value)
        }
    }

    /**
     * @dev Returns the amount referenced by chained reference `ref`.
     * If the reference is temporary, it will be cleared after reading it, so they can each only be read once.
     * If the reference is not temporary (i.e. read-only), it will not be cleared after reading it
     * (see `_isTemporaryChainedReference` function).
     */
    function _getChainedReferenceValue(uint256 ref) internal override returns (uint256) {
        (bytes32 slot, uint256 value) = _peekChainedReferenceValue(ref);

        if (_isTemporaryChainedReference(ref)) {
            // solhint-disable-next-line no-inline-assembly
            assembly {
                sstore(slot, 0)
            }
        }
        return value;
    }

    /**
     * @dev Returns the storage slot for reference `ref` as well as the amount referenced by it.
     * It does not alter the reference (even if it's marked as temporary).
     */
    function _peekChainedReferenceValue(uint256 ref) private view returns (bytes32 slot, uint256 value) {
        slot = _getStorageSlot(ref);

        // Since we do manual calculation of storage slots, it is easier (and cheaper) to rely on internal assembly to
        // access it.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            value := sload(slot)
        }
    }

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private immutable _TEMP_STORAGE_SUFFIX = keccak256("balancer.base-relayer-library");

    function _getStorageSlot(uint256 ref) private view returns (bytes32) {
        // This replicates the mechanism Solidity uses to allocate storage slots for mappings, but using a hash as the
        // mapping's storage slot, and subtracting 1 at the end. This should be more than enough to prevent collisions
        // with other state variables this or derived contracts might use.
        // See https://docs.soliditylang.org/en/v0.8.9/internals/layout_in_storage.html

        return bytes32(uint256(keccak256(abi.encodePacked(_removeReferencePrefix(ref), _TEMP_STORAGE_SUFFIX))) - 1);
    }

    /**
     * @dev Returns a reference without its prefix.
     * Use this function to calculate the storage slot so that it's the same for temporary and read-only references.
     */
    function _removeReferencePrefix(uint256 ref) private pure returns (uint256) {
        return (ref & 0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
    }
}

File 45 of 51 : GaugeActions.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/liquidity-mining/IBalancerMinter.sol";
import "@balancer-labs/v2-interfaces/contracts/liquidity-mining/IStakingLiquidityGauge.sol";

import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeERC20.sol";

import "./IBaseRelayerLibrary.sol";

/**
 * @title GaugeActions
 * @dev All functions must be payable so they can be called from a multicall involving ETH
 */
abstract contract GaugeActions is IBaseRelayerLibrary {
    using SafeERC20 for IERC20;

    IBalancerMinter private immutable _balancerMinter;
    bool private immutable _canCallUserCheckpoint;

    /**
     * @dev The zero address may be passed as balancerMinter to safely disable features
     *      which only exist on mainnet
     */
    constructor(IBalancerMinter balancerMinter, bool canCallUserCheckpoint) {
        _balancerMinter = balancerMinter;
        _canCallUserCheckpoint = canCallUserCheckpoint;
    }

    /**
     * @notice Returns true if the relayer is configured to checkpoint gauges directly via `user_checkpoint`.
     * @dev This method is not expected to be called inside `multicall` so it is not marked as `payable`.
     */
    function canCallUserCheckpoint() external view returns (bool) {
        return _canCallUserCheckpoint;
    }

    function gaugeDeposit(
        IStakingLiquidityGauge gauge,
        address sender,
        address recipient,
        uint256 amount
    ) external payable {
        // We can query which token to pull and approve from the wrapper contract.
        IERC20 bptToken = gauge.lp_token();

        amount = _resolveAmountPullTokenAndApproveSpender(bptToken, address(gauge), amount, sender);

        gauge.deposit(amount, recipient);
    }

    function gaugeWithdraw(
        IStakingLiquidityGauge gauge,
        address sender,
        address recipient,
        uint256 amount
    ) external payable {
        amount = _resolveAmountAndPullToken(gauge, amount, sender);

        // No approval is needed here, as the gauge Tokens are burned directly from the relayer's account.
        gauge.withdraw(amount);

        // Gauge does not support withdrawing BPT to another address atomically.
        // If intended recipient is not the relayer then forward the withdrawn BPT on to the recipient.
        if (recipient != address(this)) {
            IERC20 bptToken = gauge.lp_token();

            bptToken.safeTransfer(recipient, amount);
        }
    }

    function gaugeMint(address[] calldata gauges, uint256 outputReference) external payable {
        uint256 balMinted = _balancerMinter.mintManyFor(gauges, msg.sender);

        _setChainedReference(outputReference, balMinted);
    }

    function gaugeSetMinterApproval(
        bool approval,
        address user,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable {
        _balancerMinter.setMinterApprovalWithSignature(address(this), approval, user, deadline, v, r, s);
    }

    function gaugeClaimRewards(IStakingLiquidityGauge[] calldata gauges) external payable {
        uint256 numGauges = gauges.length;
        for (uint256 i; i < numGauges; ++i) {
            gauges[i].claim_rewards(msg.sender);
        }
    }

    /**
     * @notice Perform a user checkpoint for the given user on the given set of gauges.
     * @dev Both mainnet and child chain gauges are supported.
     */
    function gaugeCheckpoint(address user, IStakingLiquidityGauge[] calldata gauges) external payable {
        if (_canCallUserCheckpoint) {
            _checkpointGaugesViaUserCheckpoint(user, gauges);
        } else {
            _checkpointGaugesViaUserBalance(user, gauges);
        }
    }

    function _checkpointGaugesViaUserCheckpoint(address user, IStakingLiquidityGauge[] calldata gauges) internal {
        uint256 numGauges = gauges.length;
        // In L2s (child chain gauges), `user_checkpoint` is not permissioned, so we can just call it directly.
        for (uint256 i = 0; i < numGauges; ++i) {
            gauges[i].user_checkpoint(user);
        }
    }

    function _checkpointGaugesViaUserBalance(address user, IStakingLiquidityGauge[] calldata gauges) internal {
        uint256 numGauges = gauges.length;
        IVault.UserBalanceOp[] memory ops = new IVault.UserBalanceOp[](numGauges);

        // In mainnet, `user_checkpoint` is permissioned for liquidity gauges, so we cannot call it directly.
        // However, some non-permissioned actions cause the gauge to checkpoint a user as a side effect,
        // even if the operation itself is a no-op. The simplest of these is a gauge token transfer, which we
        // perform here. Since the Vault has an unlimited allowance for gauge tokens, and user balance
        // operations use the Vault allowance, no approvals are necessary.
        // The amount has to be greater than 0 for the checkpoint to take place, so we use 1 wei.
        // There is no actual value transfer since the sender and the recipient are the same.
        for (uint256 i = 0; i < numGauges; ++i) {
            // We first prepare all the transfer operations for each of the gauges.
            ops[i] = IVault.UserBalanceOp({
                asset: IAsset(address(gauges[i])),
                amount: 1,
                sender: user,
                recipient: payable(address(user)),
                kind: IVault.UserBalanceOpKind.TRANSFER_EXTERNAL
            });
        }
        // And we execute all of them at once.
        getVault().manageUserBalance(ops);
    }
}

File 46 of 51 : IBaseRelayerLibrary.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";

import "@balancer-labs/v2-vault/contracts/AssetHelpers.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeERC20.sol";

/**
 * @title IBaseRelayerLibrary
 */
abstract contract IBaseRelayerLibrary is AssetHelpers {
    using SafeERC20 for IERC20;

    constructor(IWETH weth) AssetHelpers(weth) {
        // solhint-disable-previous-line no-empty-blocks
    }

    function getVault() public view virtual returns (IVault);

    function approveVault(IERC20 token, uint256 amount) external payable virtual;

    function peekChainedReferenceValue(uint256 ref) external payable virtual returns (uint256);

    function _pullToken(
        address sender,
        IERC20 token,
        uint256 amount
    ) internal virtual;

    function _pullTokens(
        address sender,
        IERC20[] memory tokens,
        uint256[] memory amounts
    ) internal virtual;

    function _isChainedReference(uint256 amount) internal pure virtual returns (bool);

    function _setChainedReferenceValue(uint256 ref, uint256 value) internal virtual;

    function _getChainedReferenceValue(uint256 ref) internal virtual returns (uint256);

    /**
     * @dev This reuses `_resolveAmountAndPullToken` to adjust the `amount` in case it is a chained reference,
     * then pull that amount of `token` to the relayer. Additionally, it approves the `spender` to enable
     * wrapping operations. The spender is usually a token, but could also be another kind of contract (e.g.,
     * a protocol or gauge).
     */
    function _resolveAmountPullTokenAndApproveSpender(
        IERC20 token,
        address spender,
        uint256 amount,
        address sender
    ) internal returns (uint256 resolvedAmount) {
        resolvedAmount = _resolveAmountAndPullToken(token, amount, sender);

        token.safeApprove(spender, resolvedAmount);
    }

    /**
     * @dev Extract the `amount` (if it is a chained reference), and pull that amount of `token` to
     * this contract.
     */
    function _resolveAmountAndPullToken(
        IERC20 token,
        uint256 amount,
        address sender
    ) internal returns (uint256 resolvedAmount) {
        resolvedAmount = _resolveAmount(amount);

        // The wrap caller is the implicit sender of tokens, so if the goal is for the tokens
        // to be sourced from outside the relayer, we must first pull them here.
        if (sender != address(this)) {
            require(sender == msg.sender, "Incorrect sender");
            _pullToken(sender, token, resolvedAmount);
        }
    }

    /**
     * @dev Resolve an amount from a possible chained reference. This is internal, since some wrappers
     * call it independently.
     */
    function _resolveAmount(uint256 amount) internal returns (uint256) {
        return _isChainedReference(amount) ? _getChainedReferenceValue(amount) : amount;
    }

    /**
     * @dev Transfer the given `amount` of `token` to `recipient`, then call `_setChainedReference`
     * with that amount, in case it needs to be encoded as an output reference.
     */
    function _transferAndSetChainedReference(
        IERC20 token,
        address recipient,
        uint256 amount,
        uint256 outputReference
    ) internal {
        if (recipient != address(this)) {
            token.safeTransfer(recipient, amount);
        }

        _setChainedReference(outputReference, amount);
    }

    /**
     * @dev Check for a chained output reference, and encode the given `amount` if necessary.
     * This is internal, since some wrappers call it independently.
     */
    function _setChainedReference(uint256 outputReference, uint256 amount) internal {
        if (_isChainedReference(outputReference)) {
            _setChainedReferenceValue(outputReference, amount);
        }
    }
}

File 47 of 51 : LidoWrapping.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IstETH.sol";
import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IwstETH.sol";

import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/Address.sol";

import "./IBaseRelayerLibrary.sol";

/**
 * @title LidoWrapping
 * @notice Allows users to wrap and unwrap stETH
 * @dev All functions must be payable so they can be called from a multicall involving ETH
 */
abstract contract LidoWrapping is IBaseRelayerLibrary {
    using Address for address payable;

    IstETH private immutable _stETH;
    IwstETH private immutable _wstETH;

    /**
     * @dev The zero address may be passed as wstETH to safely disable this module
     * @param wstETH - the address of Lido's wrapped stETH contract
     */
    constructor(IERC20 wstETH) {
        // Safely disable stETH wrapping if no address has been passed for wstETH
        _stETH = wstETH != IERC20(0) ? IwstETH(address(wstETH)).stETH() : IstETH(0);
        _wstETH = IwstETH(address(wstETH));
    }

    function wrapStETH(
        address sender,
        address recipient,
        uint256 amount,
        uint256 outputReference
    ) external payable {
        amount = _resolveAmountPullTokenAndApproveSpender(_stETH, address(_wstETH), amount, sender);

        uint256 result = IwstETH(_wstETH).wrap(amount);

        _transferAndSetChainedReference(_wstETH, recipient, result, outputReference);
    }

    function unwrapWstETH(
        address sender,
        address recipient,
        uint256 amount,
        uint256 outputReference
    ) external payable {
        amount = _resolveAmountAndPullToken(_wstETH, amount, sender);

        // No approval is needed here, as wstETH is burned directly from the relayer's account
        uint256 result = _wstETH.unwrap(amount);

        _transferAndSetChainedReference(_stETH, recipient, result, outputReference);
    }

    function stakeETH(
        address recipient,
        uint256 amount,
        uint256 outputReference
    ) external payable {
        amount = _resolveAmount(amount);

        uint256 result = _stETH.submit{ value: amount }(address(this));

        _transferAndSetChainedReference(_stETH, recipient, result, outputReference);
    }

    function stakeETHAndWrap(
        address recipient,
        uint256 amount,
        uint256 outputReference
    ) external payable {
        amount = _resolveAmount(amount);

        // We must query this separately, since the wstETH contract doesn't return how much wstETH is minted.
        uint256 result = _wstETH.getWstETHByStETH(amount);

        // The fallback function on the wstETH contract automatically stakes and wraps any ETH sent to it.
        // We can then send the ETH safely, and only have to ensure that the call doesn't revert.
        //
        // This would be dangerous if `_wstETH` were set to the zero address. However, in this scenario,
        // this function would have already reverted during the call to `getWstETHByStETH`, preventing loss of funds.
        payable(address(_wstETH)).sendValue(amount);

        _transferAndSetChainedReference(_wstETH, recipient, result, outputReference);
    }
}

File 48 of 51 : ReliquaryStaking.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/Address.sol";
import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20.sol";
import "@balancer-labs/v2-interfaces/contracts/liquidity-mining/IReliquary.sol";
import "@balancer-labs/v2-interfaces/contracts/liquidity-mining/IReliquaryRewarder.sol";
import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/SafeERC20.sol";
import "./IBaseRelayerLibrary.sol";

/**
 * @title ReliquaryStaking
 * @notice Allows users to deposit and withdraw BPT to/from relic
 * @dev All functions must be payable so that it can be called as part of a multicall involving ETH
 */
abstract contract ReliquaryStaking is IBaseRelayerLibrary {
    using Address for address payable;
    using SafeERC20 for IERC20;

    IReliquary private immutable _reliquary;

    constructor(IReliquary reliquary) {
        _reliquary = reliquary;
    }

    function reliquaryCreateRelicAndDeposit(
        address sender,
        address recipient,
        IERC20 token,
        uint256 poolId,
        uint256 amount,
        uint256 outputReference
    ) external payable {
        if (_isChainedReference(amount)) {
            amount = _getChainedReferenceValue(amount);
        }
        require(_reliquary.poolToken(poolId) == address(token), "Incorrect token for pid");

        // The deposit caller is the implicit sender of tokens, so if the goal is for the tokens
        // to be sourced from outside the relayer, we must first pull them here.
        if (sender != address(this)) {
            require(sender == msg.sender, "Incorrect sender");
            _pullToken(sender, token, amount);
        }

        token.approve(address(_reliquary), amount);
        // mint a new relic and deposit the tokens
        _reliquary.createRelicAndDeposit(recipient, poolId, amount);

        if (_isChainedReference(outputReference)) {
            _setChainedReferenceValue(outputReference, amount);
        }
    }

    function reliquaryDeposit(
        address sender,
        IERC20 token,
        uint256 relicId,
        uint256 amount,
        uint256 outputReference
    ) external payable {
        if (_isChainedReference(amount)) {
            amount = _getChainedReferenceValue(amount);
        }
        PositionInfo memory position = _reliquary.getPositionForId(relicId);
        require(_reliquary.poolToken(position.poolId) == address(token), "Incorrect token for pid");

        // The deposit caller is the implicit sender of tokens, so if the goal is for the tokens
        // to be sourced from outside the relayer, we must first pull them here.
        if (sender != address(this)) {
            require(sender == msg.sender, "Incorrect sender");
            _pullToken(sender, token, amount);
        }

        token.approve(address(_reliquary), amount);
        // deposit the tokens to an existing relic
        _reliquary.deposit(amount, relicId);

        if (_isChainedReference(outputReference)) {
            _setChainedReferenceValue(outputReference, amount);
        }
    }

    function reliquaryWithdrawAndHarvest(
        address recipient,
        uint256 relicId,
        uint256 amount,
        uint256 outputReference
    ) external payable {
        if (_isChainedReference(amount)) {
            amount = _getChainedReferenceValue(amount);
        }

        require(msg.sender == _reliquary.ownerOf(relicId), "Sender not owner of relic");
        PositionInfo memory position = _reliquary.getPositionForId(relicId);
        IERC20 poolToken = IERC20(_reliquary.poolToken(position.poolId));

        _reliquary.withdrawAndHarvest(amount, relicId, recipient);
        poolToken.transfer(recipient, amount);

        if (_isChainedReference(outputReference)) {
            _setChainedReferenceValue(outputReference, amount);
        }
    }

    function reliquaryHarvestAll(uint256[] memory relicIds, address recipient) external payable {
        for (uint256 i = 0; i < relicIds.length; i++) {
            require(msg.sender == _reliquary.ownerOf(relicIds[i]), "Sender not owner of relic");
            _reliquary.harvest(relicIds[i], recipient);
        }
    }
}

File 49 of 51 : VaultActions.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-weighted/WeightedPoolUserData.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-stable/StablePoolUserData.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-utils/BasePoolUserData.sol";

import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol";
import "@balancer-labs/v2-solidity-utils/contracts/helpers/VaultHelpers.sol";
import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol";

import "./IBaseRelayerLibrary.sol";

/**
 * @title VaultActions
 * @notice Allows users to call the core functions on the Balancer Vault (swaps/joins/exits/user balance management)
 * @dev Since the relayer is not expected to hold user funds, we expect the user to be the recipient of any token
 * transfers from the Vault.
 *
 * All functions must be payable so they can be called from a multicall involving ETH.
 *
 * Note that this is a base contract for VaultQueryActions. Any functions that should not be called in a query context
 * (e.g., `manageUserBalance`), should be virtual here, and overridden to revert in VaultQueryActions.
 */
abstract contract VaultActions is IBaseRelayerLibrary {
    using Math for uint256;

    /**
     * @dev In a relayer, "chaining" - passing values between otherwise independent operations in a multicall - is
     * achieved by passing reference structures between operations. Each reference has an index, corresponding to
     * an offset into the input or output array (e.g., 0 means the first element of the inputs or results), and
     * a key (computed from a hash of the index and some text), which is interpreted as a storage slot. Note that
     * the actual data of the reference is NOT stored in the reference structure, but rather at the storage slot
     * given by the key.
     *
     * The relayer uses masking on the unused MSB bits of all incoming and outgoing values to identify which are
     * references, and which are simply values that can be used directly. Incoming references are replaced with
     * their values before being forwarded to the underlying function. Likewise, outputs of underlying functions
     * that need to be chained are converted to references before being passed as inputs to the next function.
     * See `BaseRelayerLibrary`.
     */
    struct OutputReference {
        uint256 index;
        uint256 key;
    }

    function swap(
        IVault.SingleSwap memory singleSwap,
        IVault.FundManagement calldata funds,
        uint256 limit,
        uint256 deadline,
        uint256 value,
        uint256 outputReference
    ) external payable virtual returns (uint256 result) {
        require(funds.sender == msg.sender || funds.sender == address(this), "Incorrect sender");

        if (_isChainedReference(singleSwap.amount)) {
            singleSwap.amount = _getChainedReferenceValue(singleSwap.amount);
        }

        result = getVault().swap{ value: value }(singleSwap, funds, limit, deadline);

        if (_isChainedReference(outputReference)) {
            _setChainedReferenceValue(outputReference, result);
        }
    }

    function batchSwap(
        IVault.SwapKind kind,
        IVault.BatchSwapStep[] memory swaps,
        IAsset[] calldata assets,
        IVault.FundManagement calldata funds,
        int256[] calldata limits,
        uint256 deadline,
        uint256 value,
        OutputReference[] calldata outputReferences
    ) external payable virtual returns (int256[] memory results) {
        require(funds.sender == msg.sender || funds.sender == address(this), "Incorrect sender");

        for (uint256 i = 0; i < swaps.length; ++i) {
            uint256 amount = swaps[i].amount;
            if (_isChainedReference(amount)) {
                swaps[i].amount = _getChainedReferenceValue(amount);
            }
        }

        results = getVault().batchSwap{ value: value }(kind, swaps, assets, funds, limits, deadline);

        for (uint256 i = 0; i < outputReferences.length; ++i) {
            require(_isChainedReference(outputReferences[i].key), "invalid chained reference");

            // Batch swap return values are signed, as they are Vault deltas (positive values correspond to assets sent
            // to the Vault, and negative values are assets received from the Vault). To simplify the chained reference
            // value model, we simply store the absolute value.
            // This should be fine for most use cases, as the caller can reason about swap results via the `limits`
            // parameter.
            _setChainedReferenceValue(outputReferences[i].key, Math.abs(results[outputReferences[i].index]));
        }
    }

    function manageUserBalance(
        IVault.UserBalanceOp[] memory ops,
        uint256 value,
        OutputReference[] calldata outputReferences
    ) external payable virtual {
        for (uint256 i = 0; i < ops.length; i++) {
            require(ops[i].sender == msg.sender || ops[i].sender == address(this), "Incorrect sender");

            uint256 amount = ops[i].amount;
            if (_isChainedReference(amount)) {
                ops[i].amount = _getChainedReferenceValue(amount);
            }
        }

        getVault().manageUserBalance{ value: value }(ops);

        // `manageUserBalance` does not return results, but there is no calculation of amounts as with swaps.
        // We can just use the original amounts.
        for (uint256 i = 0; i < outputReferences.length; ++i) {
            require(_isChainedReference(outputReferences[i].key), "invalid chained reference");

            _setChainedReferenceValue(outputReferences[i].key, ops[outputReferences[i].index].amount);
        }
    }

    enum PoolKind { WEIGHTED, LEGACY_STABLE, COMPOSABLE_STABLE, COMPOSABLE_STABLE_V2 }

    function joinPool(
        bytes32 poolId,
        PoolKind kind,
        address sender,
        address recipient,
        IVault.JoinPoolRequest memory request,
        uint256 value,
        uint256 outputReference
    ) external payable virtual {
        require(sender == msg.sender || sender == address(this), "Incorrect sender");

        // The output of a join will be the Pool's token contract, typically known as BPT (Balancer Pool Tokens).
        // Since the Vault is unaware of this (BPT tokens are minted directly to the recipient), we manually
        // measure this balance increase: but only if an output reference is provided.
        IERC20 bpt = IERC20(VaultHelpers.toPoolAddress(poolId));
        uint256 maybeInitialRecipientBPT = _isChainedReference(outputReference) ? bpt.balanceOf(recipient) : 0;

        request.userData = _doJoinPoolChainedReferenceReplacements(kind, request.userData);

        getVault().joinPool{ value: value }(poolId, sender, recipient, request);

        if (_isChainedReference(outputReference)) {
            // In this context, `maybeInitialRecipientBPT` is guaranteed to have been initialized, so we can safely read
            // from it. Note that we assume the recipient balance change has a positive sign (i.e. the recipient
            // received BPT).
            uint256 finalRecipientBPT = bpt.balanceOf(recipient);
            _setChainedReferenceValue(outputReference, finalRecipientBPT.sub(maybeInitialRecipientBPT));
        }
    }

    /**
     * @dev Compute the final userData for a join, depending on the PoolKind, performing replacements for chained
     * references as necessary.
     */
    function _doJoinPoolChainedReferenceReplacements(PoolKind kind, bytes memory userData)
        internal
        returns (bytes memory)
    {
        if (kind == PoolKind.WEIGHTED) {
            return _doWeightedJoinChainedReferenceReplacements(userData);
        } else if (
            kind == PoolKind.LEGACY_STABLE ||
            kind == PoolKind.COMPOSABLE_STABLE ||
            kind == PoolKind.COMPOSABLE_STABLE_V2
        ) {
            return _doStableJoinChainedReferenceReplacements(userData);
        } else {
            revert("UNHANDLED_POOL_KIND");
        }
    }

    function _doWeightedJoinChainedReferenceReplacements(bytes memory userData) private returns (bytes memory) {
        WeightedPoolUserData.JoinKind kind = WeightedPoolUserData.joinKind(userData);

        if (kind == WeightedPoolUserData.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT) {
            return _doWeightedExactTokensInForBPTOutReplacements(userData);
        } else {
            // All other join kinds are 'given out' (i.e the parameter is a BPT amount),
            // so we don't do replacements for those.
            return userData;
        }
    }

    function _doWeightedExactTokensInForBPTOutReplacements(bytes memory userData) private returns (bytes memory) {
        (uint256[] memory amountsIn, uint256 minBPTAmountOut) = WeightedPoolUserData.exactTokensInForBptOut(userData);

        // Save gas by only re-encoding the data if we actually performed a replacement
        return
            _replacedAmounts(amountsIn)
                ? abi.encode(WeightedPoolUserData.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT, amountsIn, minBPTAmountOut)
                : userData;
    }

    function _doStableJoinChainedReferenceReplacements(bytes memory userData) private returns (bytes memory) {
        // The only 'given in' join (in which the parameters are the amounts in) is EXACT_TOKENS_IN_FOR_BPT_OUT,
        // so that is the only one where we do replacements. Luckily all versions of Stable Pool share the same
        // enum value for it, so we can treat them all the same, and just use the latest version.

        // Note that ComposableStablePool versions V2 and up support a proportional join kind, which some previous
        // versions did not. While it is not rejected here, if passed to the Pool it will revert.

        StablePoolUserData.JoinKind kind = StablePoolUserData.joinKind(userData);

        if (kind == StablePoolUserData.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT) {
            return _doStableExactTokensInForBPTOutReplacements(userData);
        } else {
            // All other join kinds are 'given out' (i.e the parameter is a BPT amount),
            // so we don't do replacements for those.
            return userData;
        }
    }

    function _doStableExactTokensInForBPTOutReplacements(bytes memory userData) private returns (bytes memory) {
        (uint256[] memory amountsIn, uint256 minBPTAmountOut) = StablePoolUserData.exactTokensInForBptOut(userData);

        // Save gas by only re-encoding the data if we actually performed a replacement
        return
            _replacedAmounts(amountsIn)
                ? abi.encode(StablePoolUserData.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT, amountsIn, minBPTAmountOut)
                : userData;
    }

    // Mutates amountsIn, and returns true if any replacements were made
    function _replacedAmounts(uint256[] memory amountsIn) private returns (bool) {
        bool madeReplacements = false;

        for (uint256 i = 0; i < amountsIn.length; ++i) {
            uint256 amount = amountsIn[i];
            if (_isChainedReference(amount)) {
                amountsIn[i] = _getChainedReferenceValue(amount);
                madeReplacements = true;
            }
        }

        return madeReplacements;
    }

    function exitPool(
        bytes32 poolId,
        PoolKind kind,
        address sender,
        address payable recipient,
        IVault.ExitPoolRequest memory request,
        OutputReference[] calldata outputReferences
    ) external payable virtual {
        require(sender == msg.sender || sender == address(this), "Incorrect sender");

        // To track the changes of internal balances, we need an array of token addresses.
        // We save this here to avoid having to recalculate after the exit.
        IERC20[] memory trackedTokens = new IERC20[](outputReferences.length);

        // Query initial balances for all tokens, and record them as chained references
        uint256[] memory initialRecipientBalances = new uint256[](outputReferences.length);
        for (uint256 i = 0; i < outputReferences.length; i++) {
            require(_isChainedReference(outputReferences[i].key), "invalid chained reference");

            IAsset asset = request.assets[outputReferences[i].index];
            if (request.toInternalBalance) {
                trackedTokens[i] = _asIERC20(asset);
            } else {
                initialRecipientBalances[i] = _isETH(asset) ? recipient.balance : _asIERC20(asset).balanceOf(recipient);
            }
        }
        if (request.toInternalBalance) {
            initialRecipientBalances = getVault().getInternalBalance(recipient, trackedTokens);
        }

        // Exit the Pool
        request.userData = _doExitPoolChainedReferenceReplacements(kind, request.userData);
        getVault().exitPool(poolId, sender, recipient, request);

        // Query final balances for all tokens of interest
        uint256[] memory finalRecipientTokenBalances = new uint256[](outputReferences.length);
        if (request.toInternalBalance) {
            finalRecipientTokenBalances = getVault().getInternalBalance(recipient, trackedTokens);
        } else {
            for (uint256 i = 0; i < outputReferences.length; i++) {
                IAsset asset = request.assets[outputReferences[i].index];
                finalRecipientTokenBalances[i] = _isETH(asset)
                    ? recipient.balance
                    : _asIERC20(asset).balanceOf(recipient);
            }
        }

        // Calculate deltas and save as chained references
        for (uint256 i = 0; i < outputReferences.length; i++) {
            _setChainedReferenceValue(
                outputReferences[i].key,
                finalRecipientTokenBalances[i].sub(initialRecipientBalances[i])
            );
        }
    }

    /**
     * @dev Compute the final userData for an exit, depending on the PoolKind, performing replacements for chained
     * references as necessary.
     */
    function _doExitPoolChainedReferenceReplacements(PoolKind kind, bytes memory userData)
        internal
        returns (bytes memory)
    {
        // Must check for the recovery mode ExitKind first, which is common to all pool types.
        // If it is just a regular exit, pass it to the appropriate PoolKind handler for interpretation.
        if (BasePoolUserData.isRecoveryModeExitKind(userData)) {
            return _doRecoveryExitReplacements(userData);
        } else if (kind == PoolKind.WEIGHTED) {
            return _doWeightedExitChainedReferenceReplacements(userData);
        } else {
            if (kind == PoolKind.LEGACY_STABLE) {
                return _doLegacyStableExitChainedReferenceReplacements(userData);
            } else if (kind == PoolKind.COMPOSABLE_STABLE) {
                return _doComposableStableExitChainedReferenceReplacements(userData);
            } else if (kind == PoolKind.COMPOSABLE_STABLE_V2) {
                return _doComposableStableV2ExitChainedReferenceReplacements(userData);
            } else {
                revert("UNHANDLED_POOL_KIND");
            }
        }
    }

    function _doWeightedExitChainedReferenceReplacements(bytes memory userData) private returns (bytes memory) {
        WeightedPoolUserData.ExitKind kind = WeightedPoolUserData.exitKind(userData);

        if (kind == WeightedPoolUserData.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT) {
            return _doWeightedExactBptInForOneTokenOutReplacements(userData);
        } else if (kind == WeightedPoolUserData.ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT) {
            return _doWeightedExactBptInForTokensOutReplacements(userData);
        } else {
            // All other exit kinds are 'given out' (i.e the parameter is a token amount),
            // so we don't do replacements for those.
            return userData;
        }
    }

    function _doWeightedExactBptInForOneTokenOutReplacements(bytes memory userData) private returns (bytes memory) {
        (uint256 bptAmountIn, uint256 tokenIndex) = WeightedPoolUserData.exactBptInForTokenOut(userData);

        if (_isChainedReference(bptAmountIn)) {
            bptAmountIn = _getChainedReferenceValue(bptAmountIn);
            return abi.encode(WeightedPoolUserData.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, bptAmountIn, tokenIndex);
        } else {
            // Save gas by only re-encoding the data if we actually performed a replacement
            return userData;
        }
    }

    function _doWeightedExactBptInForTokensOutReplacements(bytes memory userData) private returns (bytes memory) {
        uint256 bptAmountIn = WeightedPoolUserData.exactBptInForTokensOut(userData);

        if (_isChainedReference(bptAmountIn)) {
            bptAmountIn = _getChainedReferenceValue(bptAmountIn);
            return abi.encode(WeightedPoolUserData.ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT, bptAmountIn);
        } else {
            // Save gas by only re-encoding the data if we actually performed a replacement
            return userData;
        }
    }

    function _doRecoveryExitReplacements(bytes memory userData) private returns (bytes memory) {
        uint256 bptAmountIn = BasePoolUserData.recoveryModeExit(userData);

        if (_isChainedReference(bptAmountIn)) {
            bptAmountIn = _getChainedReferenceValue(bptAmountIn);
            return abi.encode(BasePoolUserData.RECOVERY_MODE_EXIT_KIND, bptAmountIn);
        } else {
            // Save gas by only re-encoding the data if we actually performed a replacement
            return userData;
        }
    }

    // Stable Pool version-dependent recoding dispatch functions

    /*
     * While all Stable Pool versions fortuitously support the same join kinds (V2 and higher support one extra),
     * they do NOT all support the same exit kinds. Also, though the encoding of the data associated with the exit
     * is uniform across pool kinds for the same exit method, the ExitKind ID itself may have a different value.
     *
     * For instance, BPT_IN_FOR_EXACT_TOKENS_OUT is 2 in legacy Stable Pools, but 1 in Composable Stable Pools.
     * (See the reference comment and libraries below.)
     *
     * Accordingly, the three do[PoolKind]ExitChainedReferenceReplacements functions below (for LegacyStable,
     * ComposableStable, and CopmosableStableV2) extract the exitKind and pass it through to the shared
     * recoding functions.
     */

    function _doLegacyStableExitChainedReferenceReplacements(bytes memory userData) private returns (bytes memory) {
        uint8 exitKind = uint8(StablePoolUserData.exitKind(userData));

        if (exitKind == uint8(LegacyStablePoolUserData.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT)) {
            return _doStableExactBptInForOneTokenOutReplacements(userData, exitKind);
        } else if (exitKind == uint8(LegacyStablePoolUserData.ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT)) {
            return _doStableExactBptInForTokensOutReplacements(userData, exitKind);
        } else {
            // All other exit kinds are 'given out' (i.e the parameter is a token amount),
            // so we don't do replacements for those.
            return userData;
        }
    }

    // For the first deployment of ComposableStablePool
    function _doComposableStableExitChainedReferenceReplacements(bytes memory userData) private returns (bytes memory) {
        uint8 exitKind = uint8(StablePoolUserData.exitKind(userData));

        if (exitKind == uint8(ComposableStablePoolUserData.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT)) {
            return _doStableExactBptInForOneTokenOutReplacements(userData, exitKind);
        } else {
            // All other exit kinds are 'given out' (i.e the parameter is a token amount),
            // so we don't do replacements for those.
            return userData;
        }
    }

    // For ComposableStablePool V2 and V3
    function _doComposableStableV2ExitChainedReferenceReplacements(bytes memory userData)
        private
        returns (bytes memory)
    {
        uint8 exitKind = uint8(StablePoolUserData.exitKind(userData));

        if (exitKind == uint8(StablePoolUserData.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT)) {
            return _doStableExactBptInForOneTokenOutReplacements(userData, exitKind);
        } else if (exitKind == uint8(StablePoolUserData.ExitKind.EXACT_BPT_IN_FOR_ALL_TOKENS_OUT)) {
            return _doStableExactBptInForTokensOutReplacements(userData, exitKind);
        } else {
            // All other exit kinds are 'given out' (i.e the parameter is a token amount),
            // so we don't do replacements for those.
            return userData;
        }
    }

    // Shared Stable Exit recoding functions

    // The following two functions perform the actual recoding, which involves parsing and re-encoding the userData.
    // The encoding of the actual arguments is uniform across pool kinds, which allows these recoding functions to be
    // shared. However, the ExitKind ID itself can vary, so it must be passed in from each specific pool kind handler.

    function _doStableExactBptInForOneTokenOutReplacements(bytes memory userData, uint8 exitKind)
        private
        returns (bytes memory)
    {
        (uint256 bptAmountIn, uint256 tokenIndex) = StablePoolUserData.exactBptInForTokenOut(userData);

        if (_isChainedReference(bptAmountIn)) {
            bptAmountIn = _getChainedReferenceValue(bptAmountIn);
            return abi.encode(exitKind, bptAmountIn, tokenIndex);
        } else {
            // Save gas by only re-encoding the data if we actually performed a replacement
            return userData;
        }
    }

    function _doStableExactBptInForTokensOutReplacements(bytes memory userData, uint8 exitKind)
        private
        returns (bytes memory)
    {
        uint256 bptAmountIn = StablePoolUserData.exactBptInForTokensOut(userData);

        if (_isChainedReference(bptAmountIn)) {
            bptAmountIn = _getChainedReferenceValue(bptAmountIn);
            return abi.encode(exitKind, bptAmountIn);
        } else {
            // Save gas by only re-encoding the data if we actually performed a replacement
            return userData;
        }
    }
}

/*
    For reference:

    StablePoolUserData (applies to ComposableStablePool V2+):

    enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT }
    enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT, EXACT_BPT_IN_FOR_ALL_TOKENS_OUT }

    WeightedPoolUserData:

    enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT }
    enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT }

    StablePhantomPools can only be exited proportionally when the pool is paused: and the pause window has expired.
    They have their own enum:

    enum ExitKindPhantom { EXACT_BPT_IN_FOR_TOKENS_OUT }
*/

// Applies to StablePool, MetaStablePool, StablePool V2
library LegacyStablePoolUserData {
    enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT }
    enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT }
}

// Applies to the first deployment of ComposableStablePool (pre-Versioning)
library ComposableStablePoolUserData {
    enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT }
    enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT }
}

File 50 of 51 : VaultPermit.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20Permit.sol";
import "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20PermitDAI.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";

import "./IBaseRelayerLibrary.sol";

/**
 * @title VaultPermit
 * @notice Allows users to use permit (where supported) to approve the Balancer Vault to use their tokens
 * @dev All functions must be payable so they can be called from a multicall involving ETH
 */
abstract contract VaultPermit is IBaseRelayerLibrary {
    function vaultPermit(
        IERC20Permit token,
        address owner,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public payable {
        token.permit(owner, address(getVault()), value, deadline, v, r, s);
    }

    function vaultPermitDAI(
        IERC20PermitDAI token,
        address holder,
        uint256 nonce,
        uint256 expiry,
        bool allowed,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public payable {
        token.permit(holder, address(getVault()), nonce, expiry, allowed, v, r, s);
    }
}

File 51 of 51 : VaultQueryActions.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/vault/IBasePool.sol";

import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol";

import "./VaultActions.sol";

/**
 * @title VaultQueryActions
 * @notice Allows users to simulate the core functions on the Balancer Vault (swaps/joins/exits), using queries instead
 * of the actual operations.
 * @dev Inherits from VaultActions to maximize reuse - but also pulls in `manageUserBalance`. This might not hurt
 * anything, but isn't intended behavior in a query context, so we override and disable it. Anything else added to the
 * base contract that isn't query-friendly should likewise be disabled.
 */
abstract contract VaultQueryActions is VaultActions {
    function swap(
        IVault.SingleSwap memory singleSwap,
        IVault.FundManagement calldata funds,
        uint256 limit,
        uint256, // deadline
        uint256, // value
        uint256 outputReference
    ) external payable override returns (uint256 result) {
        require(funds.sender == msg.sender || funds.sender == address(this), "Incorrect sender");

        if (_isChainedReference(singleSwap.amount)) {
            singleSwap.amount = _getChainedReferenceValue(singleSwap.amount);
        }

        result = _querySwap(singleSwap, funds);

        _require(singleSwap.kind == IVault.SwapKind.GIVEN_IN ? result >= limit : result <= limit, Errors.SWAP_LIMIT);

        if (_isChainedReference(outputReference)) {
            _setChainedReferenceValue(outputReference, result);
        }
    }

    function _querySwap(IVault.SingleSwap memory singleSwap, IVault.FundManagement memory funds)
        private
        returns (uint256)
    {
        // The Vault only supports batch swap queries, so we need to convert the swap call into an equivalent batch
        // swap. The result will be identical.

        // The main difference between swaps and batch swaps is that batch swaps require an assets array. We're going
        // to place the asset in at index 0, and asset out at index 1.
        IAsset[] memory assets = new IAsset[](2);
        assets[0] = singleSwap.assetIn;
        assets[1] = singleSwap.assetOut;

        IVault.BatchSwapStep[] memory swaps = new IVault.BatchSwapStep[](1);
        swaps[0] = IVault.BatchSwapStep({
            poolId: singleSwap.poolId,
            assetInIndex: 0,
            assetOutIndex: 1,
            amount: singleSwap.amount,
            userData: singleSwap.userData
        });

        int256[] memory assetDeltas = getVault().queryBatchSwap(singleSwap.kind, swaps, assets, funds);

        // Batch swaps return the full Vault asset deltas, which in the special case of a single step swap contains more
        // information than we need (as the amount in is known in a GIVEN_IN swap, and the amount out is known in a
        // GIVEN_OUT swap). We extract the information we're interested in.
        if (singleSwap.kind == IVault.SwapKind.GIVEN_IN) {
            // The asset out will have a negative Vault delta (the assets are coming out of the Pool and the user is
            // receiving them), so make it positive to match the `swap` interface.

            _require(assetDeltas[1] <= 0, Errors.SHOULD_NOT_HAPPEN);
            return uint256(-assetDeltas[1]);
        } else {
            // The asset in will have a positive Vault delta (the assets are going into the Pool and the user is
            // sending them), so we don't need to do anything.
            return uint256(assetDeltas[0]);
        }
    }

    function batchSwap(
        IVault.SwapKind kind,
        IVault.BatchSwapStep[] memory swaps,
        IAsset[] calldata assets,
        IVault.FundManagement calldata funds,
        int256[] calldata limits,
        uint256, // deadline
        uint256, // value
        OutputReference[] calldata outputReferences
    ) external payable override returns (int256[] memory results) {
        require(funds.sender == msg.sender || funds.sender == address(this), "Incorrect sender");

        for (uint256 i = 0; i < swaps.length; ++i) {
            uint256 amount = swaps[i].amount;
            if (_isChainedReference(amount)) {
                swaps[i].amount = _getChainedReferenceValue(amount);
            }
        }

        results = getVault().queryBatchSwap(kind, swaps, assets, funds);

        for (uint256 i = 0; i < outputReferences.length; ++i) {
            require(_isChainedReference(outputReferences[i].key), "invalid chained reference");

            _require(results[i] <= limits[i], Errors.SWAP_LIMIT);

            // Batch swap return values are signed, as they are Vault deltas (positive values correspond to assets sent
            // to the Vault, and negative values are assets received from the Vault). To simplify the chained reference
            // value model, we simply store the absolute value.
            // This should be fine for most use cases, as the caller can reason about swap results via the `limits`
            // parameter.
            _setChainedReferenceValue(outputReferences[i].key, Math.abs(results[outputReferences[i].index]));
        }
    }

    function joinPool(
        bytes32 poolId,
        PoolKind kind,
        address sender,
        address recipient,
        IVault.JoinPoolRequest memory request,
        uint256, // value
        uint256 outputReference
    ) external payable override {
        require(sender == msg.sender || sender == address(this), "Incorrect sender");

        request.userData = _doJoinPoolChainedReferenceReplacements(kind, request.userData);

        uint256 bptOut = _queryJoin(poolId, sender, recipient, request);

        if (_isChainedReference(outputReference)) {
            _setChainedReferenceValue(outputReference, bptOut);
        }
    }

    function _queryJoin(
        bytes32 poolId,
        address sender,
        address recipient,
        IVault.JoinPoolRequest memory request
    ) private returns (uint256 bptOut) {
        (address pool, ) = getVault().getPool(poolId);
        (uint256[] memory balances, uint256 lastChangeBlock) = _validateAssetsAndGetBalances(poolId, request.assets);
        IProtocolFeesCollector feesCollector = getVault().getProtocolFeesCollector();

        (bptOut, ) = IBasePool(pool).queryJoin(
            poolId,
            sender,
            recipient,
            balances,
            lastChangeBlock,
            feesCollector.getSwapFeePercentage(),
            request.userData
        );
    }

    function exitPool(
        bytes32 poolId,
        PoolKind kind,
        address sender,
        address payable recipient,
        IVault.ExitPoolRequest memory request,
        OutputReference[] calldata outputReferences
    ) external payable override {
        require(sender == msg.sender || sender == address(this), "Incorrect sender");

        // Exit the Pool
        request.userData = _doExitPoolChainedReferenceReplacements(kind, request.userData);

        uint256[] memory amountsOut = _queryExit(poolId, sender, recipient, request);

        // Save as chained references
        for (uint256 i = 0; i < outputReferences.length; i++) {
            _setChainedReferenceValue(outputReferences[i].key, amountsOut[outputReferences[i].index]);
        }
    }

    function _queryExit(
        bytes32 poolId,
        address sender,
        address recipient,
        IVault.ExitPoolRequest memory request
    ) private returns (uint256[] memory amountsOut) {
        (address pool, ) = getVault().getPool(poolId);
        (uint256[] memory balances, uint256 lastChangeBlock) = _validateAssetsAndGetBalances(poolId, request.assets);
        IProtocolFeesCollector feesCollector = getVault().getProtocolFeesCollector();

        (, amountsOut) = IBasePool(pool).queryExit(
            poolId,
            sender,
            recipient,
            balances,
            lastChangeBlock,
            feesCollector.getSwapFeePercentage(),
            request.userData
        );
    }

    function _validateAssetsAndGetBalances(bytes32 poolId, IAsset[] memory expectedAssets)
        private
        view
        returns (uint256[] memory balances, uint256 lastChangeBlock)
    {
        IERC20[] memory actualTokens;
        IERC20[] memory expectedTokens = _translateToIERC20(expectedAssets);

        (actualTokens, balances, lastChangeBlock) = getVault().getPoolTokens(poolId);
        InputHelpers.ensureInputLengthMatch(actualTokens.length, expectedTokens.length);

        for (uint256 i = 0; i < actualTokens.length; ++i) {
            IERC20 token = actualTokens[i];
            _require(token == expectedTokens[i], Errors.TOKENS_MISMATCH);
        }
    }

    /// @dev Prevent `vaultActionsQueryMulticall` from calling manageUserBalance.
    function manageUserBalance(
        IVault.UserBalanceOp[] memory,
        uint256,
        OutputReference[] calldata
    ) external payable override {
        _revert(Errors.UNIMPLEMENTED);
    }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IVault","name":"vault","type":"address"},{"internalType":"contract IERC20","name":"wstETH","type":"address"},{"internalType":"contract IBalancerMinter","name":"minter","type":"address"},{"internalType":"bool","name":"canCallUserCheckpoint","type":"bool"},{"internalType":"string","name":"version","type":"string"},{"internalType":"contract IReliquary","name":"reliquary","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approveVault","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"enum IVault.SwapKind","name":"kind","type":"uint8"},{"components":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"uint256","name":"assetInIndex","type":"uint256"},{"internalType":"uint256","name":"assetOutIndex","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"}],"internalType":"struct IVault.BatchSwapStep[]","name":"swaps","type":"tuple[]"},{"internalType":"contract IAsset[]","name":"assets","type":"address[]"},{"components":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"bool","name":"fromInternalBalance","type":"bool"},{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"bool","name":"toInternalBalance","type":"bool"}],"internalType":"struct IVault.FundManagement","name":"funds","type":"tuple"},{"internalType":"int256[]","name":"limits","type":"int256[]"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"},{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"key","type":"uint256"}],"internalType":"struct VaultActions.OutputReference[]","name":"outputReferences","type":"tuple[]"}],"name":"batchSwap","outputs":[{"internalType":"int256[]","name":"results","type":"int256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"canCallUserCheckpoint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"enum VaultActions.PoolKind","name":"kind","type":"uint8"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address payable","name":"recipient","type":"address"},{"components":[{"internalType":"contract IAsset[]","name":"assets","type":"address[]"},{"internalType":"uint256[]","name":"minAmountsOut","type":"uint256[]"},{"internalType":"bytes","name":"userData","type":"bytes"},{"internalType":"bool","name":"toInternalBalance","type":"bool"}],"internalType":"struct IVault.ExitPoolRequest","name":"request","type":"tuple"},{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"key","type":"uint256"}],"internalType":"struct VaultActions.OutputReference[]","name":"outputReferences","type":"tuple[]"}],"name":"exitPool","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"contract IStakingLiquidityGauge[]","name":"gauges","type":"address[]"}],"name":"gaugeCheckpoint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IStakingLiquidityGauge[]","name":"gauges","type":"address[]"}],"name":"gaugeClaimRewards","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IStakingLiquidityGauge","name":"gauge","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"gaugeDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"gauges","type":"address[]"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"gaugeMint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bool","name":"approval","type":"bool"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"gaugeSetMinterApproval","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IStakingLiquidityGauge","name":"gauge","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"gaugeWithdraw","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getEntrypoint","outputs":[{"internalType":"contract IBalancerRelayer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVault","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"enum VaultActions.PoolKind","name":"kind","type":"uint8"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"components":[{"internalType":"contract IAsset[]","name":"assets","type":"address[]"},{"internalType":"uint256[]","name":"maxAmountsIn","type":"uint256[]"},{"internalType":"bytes","name":"userData","type":"bytes"},{"internalType":"bool","name":"fromInternalBalance","type":"bool"}],"internalType":"struct IVault.JoinPoolRequest","name":"request","type":"tuple"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"joinPool","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"enum IVault.UserBalanceOpKind","name":"kind","type":"uint8"},{"internalType":"contract IAsset","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address payable","name":"recipient","type":"address"}],"internalType":"struct IVault.UserBalanceOp[]","name":"ops","type":"tuple[]"},{"internalType":"uint256","name":"value","type":"uint256"},{"components":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"key","type":"uint256"}],"internalType":"struct VaultActions.OutputReference[]","name":"outputReferences","type":"tuple[]"}],"name":"manageUserBalance","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"ref","type":"uint256"}],"name":"peekChainedReferenceValue","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"reliquaryCreateRelicAndDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"relicId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"reliquaryDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"relicIds","type":"uint256[]"},{"internalType":"address","name":"recipient","type":"address"}],"name":"reliquaryHarvestAll","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"relicId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"reliquaryWithdrawAndHarvest","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"relayer","type":"address"},{"internalType":"bool","name":"approved","type":"bool"},{"internalType":"bytes","name":"authorisation","type":"bytes"}],"name":"setRelayerApproval","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"stakeETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"stakeETHAndWrap","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"enum IVault.SwapKind","name":"kind","type":"uint8"},{"internalType":"contract IAsset","name":"assetIn","type":"address"},{"internalType":"contract IAsset","name":"assetOut","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"}],"internalType":"struct IVault.SingleSwap","name":"singleSwap","type":"tuple"},{"components":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"bool","name":"fromInternalBalance","type":"bool"},{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"bool","name":"toInternalBalance","type":"bool"}],"internalType":"struct IVault.FundManagement","name":"funds","type":"tuple"},{"internalType":"uint256","name":"limit","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"swap","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"unwrapWstETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20Permit","name":"token","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"vaultPermit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20PermitDAI","name":"token","type":"address"},{"internalType":"address","name":"holder","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"bool","name":"allowed","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"vaultPermitDAI","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"outputReference","type":"uint256"}],"name":"wrapStETH","outputs":[],"stateMutability":"payable","type":"function"}]

6101c06040527fae1dc54057af8e8e5ce068cdd4383149c7efcb30e8fb95b592ee1594367fb50960c0523480156200003657600080fd5b506040516200910b3803806200910b83398101604081905262000059916200028f565b80858585898681806001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156200009a57600080fd5b505afa158015620000af573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000d591906200039f565b6001600160601b0319606091821b811660805291811b821660a05283901b1660e05260405160009083906200010a9062000260565b620001169190620003c5565b604051809103906000f08015801562000133573d6000803e3d6000fd5b5090508230828460405162000148906200026e565b620001579493929190620003d9565b604051809103906000f08015801562000174573d6000803e3d6000fd5b506001600160601b0319606091821b81166101005295901b909416610120525050151560f81b61014052506001600160a01b038116620001b65760006200022d565b806001600160a01b031663c1fe3e486040518163ffffffff1660e01b8152600401602060405180830381600087803b158015620001f257600080fd5b505af115801562000207573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200022d91906200039f565b6001600160601b0319606091821b81166101605291811b8216610180529190911b166101a052506200047d945050505050565b612e85806200569f83390190565b610be7806200852483390190565b8051620002898162000464565b92915050565b60008060008060008060c08789031215620002a8578182fd5b8651620002b58162000464565b6020880151909650620002c88162000464565b6040880151909550620002db8162000464565b60608801519094508015158114620002f1578283fd5b60808801519093506001600160401b03808211156200030e578384fd5b818901915089601f83011262000322578384fd5b81518181111562000331578485fd5b604051601f8201601f19168101602001838111828210171562000352578687fd5b6040528181528382016020018c10156200036a578586fd5b6200037d82602083016020870162000431565b80955050505050620003938860a089016200027c565b90509295509295509295565b600060208284031215620003b1578081fd5b8151620003be8162000464565b9392505050565b6001600160a01b0391909116815260200190565b600060018060a01b03808716835280861660208401528085166040840152506080606083015282518060808401526200041a8160a085016020870162000431565b601f01601f19169190910160a00195945050505050565b60005b838110156200044e57818101518382015260200162000434565b838111156200045e576000848401525b50505050565b6001600160a01b03811681146200047a57600080fd5b50565b60805160601c60a05160601c60c05160e05160601c6101005160601c6101205160601c6101405160f81c6101605160601c6101805160601c6101a05160601c6151226200057d60003980610d2d5280610e0c5280610fd3528061111352806111c052806119215280611a0e5280611a995280611b6a5280611d565280611de95280611f2d5280611fda5250806104a1528061054a528061057552806107f0528061081c52806108bf528061262852806126545250806107cf52806108fc52806109a052806126f752508061059e5280610bbd525080610b24528061159452508061126e52508061136e525080612f2b52508061168b5250506151226000f3fe6080604052600436106101ac5760003560e01c80637fd0e5d5116100ec5780639072d9fe1161008a578063b6d2473711610064578063b6d24737146103ab578063d80952d5146103be578063db4c0e91146103d1578063f3cab685146103e4576101ac565b80639072d9fe14610372578063959fc17a14610385578063a7faf77f14610398576101ac565b80638c57198b116100c65780638c57198b146103245780638d64cfbc146103375780638d928af81461034a5780638fe4624f1461035f576101ac565b80637fd0e5d5146102dc57806380db15bd146102fe578063837f9bcb14610311576101ac565b80632e6272ea1161015957806365ca48041161013357806365ca48041461029057806379e7433e146102a35780637bc008f5146102b65780637ec783bb146102c9576101ac565b80632e6272ea1461024a5780633f85d3901461026a57806348699d581461027d576101ac565b8063183694461161018a57806318369446146102045780631c982441146102245780632cbec84e14610237576101ac565b80630e248fea146101b15780631089e5e3146101c657806310f3aaff146101d9575b600080fd5b6101c46101bf366004613daa565b6103f7565b005b6101c46101d4366004613cf2565b610492565b3480156101e557600080fd5b506101ee61059c565b6040516101fb9190614c1d565b60405180910390f35b610217610212366004614440565b6105c0565b6040516101fb9190614b43565b6101c4610232366004613b7d565b6107ca565b6101c4610245366004613cf2565b6108ed565b61025d610258366004614597565b6109c7565b6040516101fb9190614fa2565b6101c4610278366004613d60565b610af1565b6101c461028b366004613bc2565b610bbb565b6101c461029e3660046142fd565b610c01565b6101c46102b1366004613fd7565b610d1f565b6101c46102c43660046142fd565b610ea9565b6101c46102d7366004613b19565b610fad565b3480156102e857600080fd5b506102f161126c565b6040516101fb9190614913565b6101c461030c366004613c15565b611290565b6101c461031f366004613e7a565b611394565b6101c4610332366004614043565b611564565b6101c4610345366004614262565b61160f565b34801561035657600080fd5b506102f1611689565b6101c461036d366004614150565b6116ad565b6101c4610380366004613d26565b6118d7565b6101c46103933660046141e0565b611c87565b6101c46103a6366004613ca2565b611d04565b6101c46103b93660046142d2565b61205b565b6101c46103cc3660046140a7565b612095565b6101c46103df366004613b7d565b612623565b61025d6103f2366004614685565b61271e565b8060005b8181101561048c5783838281811061040f57fe5b90506020020160208101906104249190613ae1565b6001600160a01b03166384e9bd7e336040518263ffffffff1660e01b815260040161044f9190614913565b600060405180830381600087803b15801561046957600080fd5b505af115801561047d573d6000803e3d6000fd5b505050508060010190506103fb565b50505050565b61049b82612730565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b0e38900846040518263ffffffff1660e01b81526004016104eb9190614fa2565b60206040518083038186803b15801561050357600080fd5b505afa158015610517573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061053b919061469d565b90506105706001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684612756565b61048c7f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b7f000000000000000000000000000000000000000000000000000000000000000090565b6060336105d060208a018a613ae1565b6001600160a01b031614806105f95750306105ee60208a018a613ae1565b6001600160a01b0316145b61061e5760405162461bcd60e51b815260040161061590614dcd565b60405180910390fd5b60005b8b518110156106835760008c828151811061063857fe5b602002602001015160600151905061064f816127fe565b1561067a5761065d81612845565b8d838151811061066957fe5b602002602001015160600181815250505b50600101610621565b5061068c611689565b6001600160a01b031663945bcec9858e8e8e8e8e8e8e8e6040518a63ffffffff1660e01b81526004016106c6989796959493929190614cc4565b6000604051808303818588803b1580156106df57600080fd5b505af11580156106f3573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f1916820160405261071c9190810190613dea565b905060005b828110156107ba5761074784848381811061073857fe5b905060400201602001356127fe565b6107635760405162461bcd60e51b815260040161061590614ee0565b6107b284848381811061077257fe5b905060400201602001356107ad8487878681811061078c57fe5b90506040020160000135815181106107a057fe5b6020026020010151612870565b61287c565b600101610721565b509b9a5050505050505050505050565b6108167f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000848761288f565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ea598cb0846040518263ffffffff1660e01b81526004016108669190614fa2565b602060405180830381600087803b15801561088057600080fd5b505af1158015610894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108b8919061469d565b90506108e67f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b5050505050565b6108f682612730565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a1903eab84306040518363ffffffff1660e01b81526004016109479190614913565b6020604051808303818588803b15801561096057600080fd5b505af1158015610974573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610999919061469d565b905061048c7f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b6000336109d76020880188613ae1565b6001600160a01b03161480610a005750306109f56020880188613ae1565b6001600160a01b0316145b610a1c5760405162461bcd60e51b815260040161061590614dcd565b610a2987608001516127fe565b15610a4157610a3b8760800151612845565b60808801525b610a49611689565b6001600160a01b03166352bbbe2984898989896040518663ffffffff1660e01b8152600401610a7b9493929190614f17565b6020604051808303818588803b158015610a9457600080fd5b505af1158015610aa8573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610acd919061469d565b9050610ad8826127fe565b15610ae757610ae7828261287c565b9695505050505050565b6040517f3b9f73840000000000000000000000000000000000000000000000000000000081526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690633b9f738490610b5d90879087903390600401614ae3565b602060405180830381600087803b158015610b7757600080fd5b505af1158015610b8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610baf919061469d565b905061048c82826128ba565b7f000000000000000000000000000000000000000000000000000000000000000015610bf157610bec8383836128d2565b610bfc565b610bfc838383612985565b505050565b610c0c848285612a9f565b6040517f2e1a7d4d0000000000000000000000000000000000000000000000000000000081529091506001600160a01b03851690632e1a7d4d90610c54908490600401614fa2565b600060405180830381600087803b158015610c6e57600080fd5b505af1158015610c82573d6000803e3d6000fd5b505050506001600160a01b038216301461048c576000846001600160a01b03166382c630666040518163ffffffff1660e01b815260040160206040518083038186803b158015610cd157600080fd5b505afa158015610ce5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d099190613afd565b90506108e66001600160a01b0382168484612aef565b60005b8251811015610bfc577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636352211e848381518110610d6657fe5b60200260200101516040518263ffffffff1660e01b8152600401610d8a9190614fa2565b60206040518083038186803b158015610da257600080fd5b505afa158015610db6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dda9190613afd565b6001600160a01b0316336001600160a01b031614610e0a5760405162461bcd60e51b815260040161061590614e3b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318fccc76848381518110610e4557fe5b6020026020010151846040518363ffffffff1660e01b8152600401610e6b929190614fab565b600060405180830381600087803b158015610e8557600080fd5b505af1158015610e99573d6000803e3d6000fd5b505060019092019150610d229050565b6000846001600160a01b03166382c630666040518163ffffffff1660e01b815260040160206040518083038186803b158015610ee457600080fd5b505afa158015610ef8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1c9190613afd565b9050610f2a8186848761288f565b6040517f6e553f650000000000000000000000000000000000000000000000000000000081529092506001600160a01b03861690636e553f6590610f749085908790600401614fab565b600060405180830381600087803b158015610f8e57600080fd5b505af1158015610fa2573d6000803e3d6000fd5b505050505050505050565b610fb6826127fe565b15610fc757610fc482612845565b91505b836001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636e7d4019856040518263ffffffff1660e01b815260040161101d9190614fa2565b60206040518083038186803b15801561103557600080fd5b505afa158015611049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061106d9190613afd565b6001600160a01b0316146110935760405162461bcd60e51b815260040161061590614e04565b6001600160a01b03861630146110d6576001600160a01b03861633146110cb5760405162461bcd60e51b815260040161061590614dcd565b6110d6868584612b72565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063095ea7b39061113d907f0000000000000000000000000000000000000000000000000000000000000000908690600401614aa9565b602060405180830381600087803b15801561115757600080fd5b505af115801561116b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118f9190614027565b506040517f6705fcf30000000000000000000000000000000000000000000000000000000081526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636705fcf3906111f990889087908790600401614ac2565b602060405180830381600087803b15801561121357600080fd5b505af1158015611227573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061124b919061469d565b50611255816127fe565b1561126457611264818361287c565b505050505050565b7f000000000000000000000000000000000000000000000000000000000000000090565b6001600160a01b0384163014806112a5575082155b6112c15760405162461bcd60e51b815260040161061590614e72565b606063fa6e671d60e01b3386866040516024016112e093929190614927565b60408051601f19818403018152918152602080830180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909516949094179093525161134f9286918691016148e0565b60408051601f1981840301815291905290506112646001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001682612c0e565b60005b845181101561147457336001600160a01b03168582815181106113b657fe5b6020026020010151606001516001600160a01b031614806113ff5750306001600160a01b03168582815181106113e857fe5b6020026020010151606001516001600160a01b0316145b61141b5760405162461bcd60e51b815260040161061590614dcd565b600085828151811061142957fe5b6020026020010151604001519050611440816127fe565b1561146b5761144e81612845565b86838151811061145a57fe5b602002602001015160400181815250505b50600101611397565b5061147d611689565b6001600160a01b0316630e8e3e8484866040518363ffffffff1660e01b81526004016114a99190614b87565b6000604051808303818588803b1580156114c257600080fd5b505af11580156114d6573d6000803e3d6000fd5b505050505060005b818110156108e6576114f583838381811061073857fe5b6115115760405162461bcd60e51b815260040161061590614ee0565b61155c83838381811061152057fe5b905060400201602001358685858581811061153757fe5b905060400201600001358151811061154b57fe5b60200260200101516040015161287c565b6001016114de565b6040517fc65427940000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c6542794906115d59030908a908a908a908a908a908a90600401614a49565b600060405180830381600087803b1580156115ef57600080fd5b505af1158015611603573d6000803e3d6000fd5b50505050505050505050565b866001600160a01b031663d505accf87611627611689565b88888888886040518863ffffffff1660e01b815260040161164e9796959493929190614a08565b600060405180830381600087803b15801561166857600080fd5b505af115801561167c573d6000803e3d6000fd5b5050505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000090565b6001600160a01b0385163314806116cc57506001600160a01b03851630145b6116e85760405162461bcd60e51b815260040161061590614dcd565b60006116f388612c88565b90506000611700836127fe565b61170b5760006117a0565b6040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b038316906370a0823190611750908990600401614913565b60206040518083038186803b15801561176857600080fd5b505afa15801561177c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a0919061469d565b90506117b0888660400151612c8e565b60408601526117bd611689565b6001600160a01b031663b95cac28858b8a8a8a6040518663ffffffff1660e01b81526004016117ef9493929190614c28565b6000604051808303818588803b15801561180857600080fd5b505af115801561181c573d6000803e3d6000fd5b505050505061182a836127fe565b15610fa2576040517f70a082310000000000000000000000000000000000000000000000000000000081526000906001600160a01b038416906370a0823190611877908a90600401614913565b60206040518083038186803b15801561188f57600080fd5b505afa1580156118a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c7919061469d565b9050611603846107ad8385612d15565b6118e0826127fe565b156118f1576118ee82612845565b91505b6040517f6352211e0000000000000000000000000000000000000000000000000000000081526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636352211e90611956908690600401614fa2565b60206040518083038186803b15801561196e57600080fd5b505afa158015611982573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119a69190613afd565b6001600160a01b0316336001600160a01b0316146119d65760405162461bcd60e51b815260040161061590614e3b565b6119de6136a4565b6040517fe48dc1350000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e48dc13590611a43908790600401614fa2565b60c06040518083038186803b158015611a5b57600080fd5b505afa158015611a6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a93919061453c565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636e7d401983608001516040518263ffffffff1660e01b8152600401611ae79190614fa2565b60206040518083038186803b158015611aff57600080fd5b505afa158015611b13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b379190613afd565b6040517fd1abb9070000000000000000000000000000000000000000000000000000000081529091506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063d1abb90790611ba390879089908b90600401614fc2565b600060405180830381600087803b158015611bbd57600080fd5b505af1158015611bd1573d6000803e3d6000fd5b50506040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038416925063a9059cbb9150611c1c9089908890600401614aa9565b602060405180830381600087803b158015611c3657600080fd5b505af1158015611c4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c6e9190614027565b50611c78836127fe565b1561126457611264838561287c565b876001600160a01b0316638fcbaf0c88611c9f611689565b8989898989896040518963ffffffff1660e01b8152600401611cc89897969594939291906149bf565b600060405180830381600087803b158015611ce257600080fd5b505af1158015611cf6573d6000803e3d6000fd5b505050505050505050505050565b611d0d826127fe565b15611d1e57611d1b82612845565b91505b611d266136a4565b6040517fe48dc1350000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e48dc13590611d8b908790600401614fa2565b60c06040518083038186803b158015611da357600080fd5b505afa158015611db7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ddb919061453c565b9050846001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636e7d401983608001516040518263ffffffff1660e01b8152600401611e379190614fa2565b60206040518083038186803b158015611e4f57600080fd5b505afa158015611e63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e879190613afd565b6001600160a01b031614611ead5760405162461bcd60e51b815260040161061590614e04565b6001600160a01b0386163014611ef0576001600160a01b0386163314611ee55760405162461bcd60e51b815260040161061590614dcd565b611ef0868685612b72565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0386169063095ea7b390611f57907f0000000000000000000000000000000000000000000000000000000000000000908790600401614aa9565b602060405180830381600087803b158015611f7157600080fd5b505af1158015611f85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fa99190614027565b506040517fe2bbb1580000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e2bbb158906120119086908890600401614905565b600060405180830381600087803b15801561202b57600080fd5b505af115801561203f573d6000803e3d6000fd5b5050505061204c826127fe565b1561126457611264828461287c565b612064816127fe565b156120755761207281612845565b90505b612091612080611689565b6001600160a01b0384169083612d2b565b5050565b6001600160a01b0385163314806120b457506001600160a01b03851630145b6120d05760405162461bcd60e51b815260040161061590614dcd565b60608167ffffffffffffffff811180156120e957600080fd5b50604051908082528060200260200182016040528015612113578160200160208202803683370190505b50905060608267ffffffffffffffff8111801561212f57600080fd5b50604051908082528060200260200182016040528015612159578160200160208202803683370190505b50905060005b838110156122c95761217685858381811061073857fe5b6121925760405162461bcd60e51b815260040161061590614ee0565b85516000908686848181106121a357fe5b90506040020160000135815181106121b757fe5b60200260200101519050866060015115612205576121d481612e13565b8483815181106121e057fe5b60200260200101906001600160a01b031690816001600160a01b0316815250506122c0565b61220e81612e16565b61229b5761221b81612e13565b6001600160a01b03166370a08231896040518263ffffffff1660e01b81526004016122469190614913565b60206040518083038186803b15801561225e57600080fd5b505afa158015612272573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612296919061469d565b6122a7565b876001600160a01b0316315b8383815181106122b357fe5b6020026020010181815250505b5060010161215f565b50846060015115612360576122dc611689565b6001600160a01b0316630f5a6efa87846040518363ffffffff1660e01b815260040161230992919061494b565b60006040518083038186803b15801561232157600080fd5b505afa158015612335573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261235d9190810190613fa4565b90505b61236e888660400151612e23565b604086015261237b611689565b6001600160a01b0316638bdb39138a8989896040518563ffffffff1660e01b81526004016123ac9493929190614c28565b600060405180830381600087803b1580156123c657600080fd5b505af11580156123da573d6000803e3d6000fd5b50606092508591505067ffffffffffffffff811180156123f957600080fd5b50604051908082528060200260200182016040528015612423578160200160208202803683370190505b5090508560600151156124c057612438611689565b6001600160a01b0316630f5a6efa88856040518363ffffffff1660e01b815260040161246592919061494b565b60006040518083038186803b15801561247d57600080fd5b505afa158015612491573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526124b99190810190613fa4565b90506125be565b60005b848110156125bc5786516000908787848181106124dc57fe5b90506040020160000135815181106124f057fe5b6020026020010151905061250381612e16565b6125905761251081612e13565b6001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040161253b9190614913565b60206040518083038186803b15801561255357600080fd5b505afa158015612567573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061258b919061469d565b61259c565b886001600160a01b0316315b8383815181106125a857fe5b6020908102919091010152506001016124c3565b505b60005b8481101561167c5761261b8686838181106125d857fe5b905060400201602001356107ad8584815181106125f157fe5b602002602001015185858151811061260557fe5b6020026020010151612d1590919063ffffffff16565b6001016125c1565b61264e7f00000000000000000000000000000000000000000000000000000000000000008386612a9f565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663de0e9a3e846040518263ffffffff1660e01b815260040161269e9190614fa2565b602060405180830381600087803b1580156126b857600080fd5b505af11580156126cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126f0919061469d565b90506108e67f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b600061272982612eb0565b9392505050565b600061273b826127fe565b612745578161274e565b61274e82612845565b90505b919050565b612765814710156101a3612ec7565b6000826001600160a01b03168260405161277e90612e13565b60006040518083038185875af1925050503d80600081146127bb576040519150601f19603f3d011682016040523d82523d6000602084013e6127c0565b606091505b50509050610bfc816101a4612ec7565b6001600160a01b03831630146127f4576127f46001600160a01b0385168484612aef565b61048c81836128ba565b7ffff0000000000000000000000000000000000000000000000000000000000000167fba100000000000000000000000000000000000000000000000000000000000001490565b600080600061285384612eb0565b9150915061286084612ed5565b1561272957600082559392505050565b60ff81901d9081180390565b600061288783612f1c565b919091555050565b600061289c858484612a9f565b90506128b26001600160a01b0386168583612d2b565b949350505050565b6128c3826127fe565b1561209157612091828261287c565b8060005b818110156108e6578383828181106128ea57fe5b90506020020160208101906128ff9190613ae1565b6001600160a01b0316634b820093866040518263ffffffff1660e01b815260040161292a9190614913565b602060405180830381600087803b15801561294457600080fd5b505af1158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614027565b506001016128d6565b8060608167ffffffffffffffff8111801561299f57600080fd5b506040519080825280602002602001820160405280156129d957816020015b6129c66136da565b8152602001906001900390816129be5790505b50905060005b82811015612a6b576040805160a081019091528060038152602001868684818110612a0657fe5b9050602002016020810190612a1b9190613ae1565b6001600160a01b0316815260200160018152602001876001600160a01b03168152602001876001600160a01b0316815250828281518110612a5857fe5b60209081029190910101526001016129df565b50612a74611689565b6001600160a01b0316630e8e3e84826040518263ffffffff1660e01b8152600401610f749190614b87565b6000612aaa83612730565b90506001600160a01b0382163014612729576001600160a01b0382163314612ae45760405162461bcd60e51b815260040161061590614dcd565b612729828583612b72565b610bfc8363a9059cbb60e01b8484604051602401612b0e929190614aa9565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152612f7a565b80612b7c57610bfc565b604080516001808252818301909252606091602080830190803683370190505090508281600081518110612bac57fe5b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526060918160200160208202803683370190505090508281600081518110612bf757fe5b6020026020010181815250506108e685838361301a565b606060006060846001600160a01b031684604051612c2c91906148c4565b6000604051808303816000865af19150503d8060008114612c69576040519150601f19603f3d011682016040523d82523d6000602084013e612c6e565b606091505b5091509150612c7d8282613172565b925050505b92915050565b60601c90565b60606000836003811115612c9e57fe5b1415612cb457612cad8261319c565b9050612c82565b6001836003811115612cc257fe5b1480612cd957506002836003811115612cd757fe5b145b80612cef57506003836003811115612ced57fe5b145b15612cfd57612cad8261319c565b60405162461bcd60e51b815260040161061590614ea9565b6000612d25838311156001612ec7565b50900390565b8015801590612dcf57506040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081526001600160a01b0384169063dd62ed3e90612d7c90309086906004016149a5565b60206040518083038186803b158015612d9457600080fd5b505afa158015612da8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dcc919061469d565b15155b15612df457612df48363095ea7b360e01b846000604051602401612b0e929190614a8d565b610bfc8363095ea7b360e01b8484604051602401612b0e929190614aa9565b90565b6001600160a01b03161590565b6060612e2e826131d9565b15612e3c57612cad82613208565b6000836003811115612e4a57fe5b1415612e5957612cad8261325b565b6001836003811115612e6757fe5b1415612e7657612cad826132a4565b6002836003811115612e8457fe5b1415612e9357612cad826132ea565b6003836003811115612ea157fe5b1415612cfd57612cad82613316565b600080612ebc83612f1c565b915081549050915091565b816120915761209181613349565b7fffff000000000000000000000000000000000000000000000000000000000000167fba100000000000000000000000000000000000000000000000000000000000001490565b60006001612f2983613376565b7f0000000000000000000000000000000000000000000000000000000000000000604051602001612f5b929190614905565b60408051808303601f1901815291905280516020909101200392915050565b60006060836001600160a01b031683604051612f9691906148c4565b6000604051808303816000865af19150503d8060008114612fd3576040519150601f19603f3d011682016040523d82523d6000602084013e612fd8565b606091505b50915091506000821415612ff0573d6000803e3d6000fd5b61048c8151600014806130125750818060200190518101906130129190614027565b6101a2612ec7565b6060825167ffffffffffffffff8111801561303457600080fd5b5060405190808252806020026020018201604052801561306e57816020015b61305b6136da565b8152602001906001900390816130535790505b50905060005b8351811015613106576040805160a08101909152806003815260200185838151811061309c57fe5b60200260200101516001600160a01b031681526020018483815181106130be57fe5b60200260200101518152602001866001600160a01b03168152602001306001600160a01b03168152508282815181106130f357fe5b6020908102919091010152600101613074565b5061310f611689565b6001600160a01b0316630e8e3e84826040518263ffffffff1660e01b815260040161313a9190614b87565b600060405180830381600087803b15801561315457600080fd5b505af1158015613168573d6000803e3d6000fd5b5050505050505050565b60608215613181575080612c82565b8151156131915781518083602001fd5b612c826101ae613349565b606060006131a983613399565b905060018160038111156131b957fe5b14156131d0576131c8836133af565b915050612751565b82915050612751565b600080825111801561274e575060ff8016828060200190518101906131fe91906146b5565b60ff161492915050565b6060600061321583613401565b9050613220816127fe565b156131d05761322e81612845565b905060ff81604051602001613244929190614fe1565b604051602081830303815290604052915050612751565b6060600061326883613417565b9050600081600281111561327857fe5b1415613287576131c88361342d565b600181600281111561329557fe5b14156131d0576131c883613490565b606060006132b183613417565b60028111156132bc57fe5b905060ff81166132d0576131c883826134cc565b60015b60ff168160ff1614156131d0576131c8838261352e565b606060006132f783613417565b600281111561330257fe5b905060ff81166131d0576131c883826134cc565b6060600061332383613417565b600281111561332e57fe5b905060ff8116613342576131c883826134cc565b60026132d3565b613373817f42414c0000000000000000000000000000000000000000000000000000000000613589565b50565b7dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1690565b60008180602001905181019061274e91906143cc565b60608060006133bd846135ea565b915091506133ca8261360d565b6133d457836128b2565b600182826040516020016133ea93929190614c92565b604051602081830303815290604052949350505050565b60008180602001905181019061272991906146d1565b60008180602001905181019061274e919061434d565b606060008061343b84613677565b91509150613448826127fe565b156134865761345682612845565b91506000828260405160200161346e93929190614c71565b60405160208183030381529060405292505050612751565b8392505050612751565b6060600061349d8361368e565b90506134a8816127fe565b156131d0576134b681612845565b9050600181604051602001613244929190614c5a565b60606000806134da85613677565b915091506134e7826127fe565b15613524576134f582612845565b915083828260405160200161350c93929190614ff4565b60405160208183030381529060405292505050612c82565b8492505050612c82565b6060600061353b8461368e565b9050613546816127fe565b156135805761355481612845565b90508281604051602001613569929190614fe1565b604051602081830303815290604052915050612c82565b83915050612c82565b62461bcd60e51b600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b60445260e882901c90606490fd5b606060008280602001905181019061360291906143e8565b909590945092505050565b600080805b835181101561367057600084828151811061362957fe5b6020026020010151905061363c816127fe565b156136675761364a81612845565b85838151811061365657fe5b602002602001018181525050600192505b50600101613612565b5092915050565b600080828060200190518101906136029190614396565b6000818060200190518101906127299190614369565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805160a081019091528060008152600060208201819052604082018190526060820181905260809091015290565b8035612c82816150a0565b60008083601f840112613726578182fd5b50813567ffffffffffffffff81111561373d578182fd5b602083019150836020808302850101111561375757600080fd5b9250929050565b600082601f83011261376e578081fd5b813561378161377c82615036565b61500f565b8181529150602080830190848101818402860182018710156137a257600080fd5b60005b848110156137ca5781356137b8816150a0565b845292820192908201906001016137a5565b505050505092915050565b600082601f8301126137e5578081fd5b81356137f361377c82615036565b818152915060208083019084810160005b848110156137ca578135870160a080601f19838c0301121561382557600080fd5b61382e8161500f565b85830135815260408084013587830152606080850135828401526080915081850135818401525082840135925067ffffffffffffffff83111561387057600080fd5b61387e8c88858701016139a0565b90820152865250509282019290820190600101613804565b60008083601f8401126138a7578182fd5b50813567ffffffffffffffff8111156138be578182fd5b60208301915083602060408302850101111561375757600080fd5b600082601f8301126138e9578081fd5b81356138f761377c82615036565b81815291506020808301908481018184028601820187101561391857600080fd5b60005b848110156137ca5781358452928201929082019060010161391b565b600082601f830112613947578081fd5b815161395561377c82615036565b81815291506020808301908481018184028601820187101561397657600080fd5b60005b848110156137ca57815184529282019290820190600101613979565b8035612c82816150b5565b600082601f8301126139b0578081fd5b813567ffffffffffffffff8111156139c6578182fd5b6139d96020601f19601f8401160161500f565b91508082528360208285010111156139f057600080fd5b8060208401602084013760009082016020015292915050565b8035612c82816150d0565b803560028110612c8257600080fd5b600060808284031215613a34578081fd5b613a3e608061500f565b9050813567ffffffffffffffff80821115613a5857600080fd5b613a648583860161375e565b83526020840135915080821115613a7a57600080fd5b613a86858386016138d9565b60208401526040840135915080821115613a9f57600080fd5b50613aac848285016139a0565b604083015250613abf8360608401613995565b606082015292915050565b600060808284031215613adb578081fd5b50919050565b600060208284031215613af2578081fd5b8135612729816150a0565b600060208284031215613b0e578081fd5b8151612729816150a0565b60008060008060008060c08789031215613b31578182fd5b8635613b3c816150a0565b95506020870135613b4c816150a0565b94506040870135613b5c816150a0565b959894975094956060810135955060808101359460a0909101359350915050565b60008060008060808587031215613b92578182fd5b8435613b9d816150a0565b93506020850135613bad816150a0565b93969395505050506040820135916060013590565b600080600060408486031215613bd6578081fd5b8335613be1816150a0565b9250602084013567ffffffffffffffff811115613bfc578182fd5b613c0886828701613715565b9497909650939450505050565b60008060008060608587031215613c2a578182fd5b8435613c35816150a0565b93506020850135613c45816150b5565b9250604085013567ffffffffffffffff80821115613c61578384fd5b818701915087601f830112613c74578384fd5b813581811115613c82578485fd5b886020828501011115613c93578485fd5b95989497505060200194505050565b600080600080600060a08688031215613cb9578283fd5b8535613cc4816150a0565b94506020860135613cd4816150a0565b94979496505050506040830135926060810135926080909101359150565b600080600060608486031215613d06578081fd5b8335613d11816150a0565b95602085013595506040909401359392505050565b60008060008060808587031215613d3b578182fd5b8435613d46816150a0565b966020860135965060408601359560600135945092505050565b600080600060408486031215613d74578081fd5b833567ffffffffffffffff811115613d8a578182fd5b613d9686828701613715565b909790965060209590950135949350505050565b60008060208385031215613dbc578182fd5b823567ffffffffffffffff811115613dd2578283fd5b613dde85828601613715565b90969095509350505050565b60006020808385031215613dfc578182fd5b825167ffffffffffffffff811115613e12578283fd5b8301601f81018513613e22578283fd5b8051613e3061377c82615036565b8181528381019083850185840285018601891015613e4c578687fd5b8694505b83851015613e6e578051835260019490940193918501918501613e50565b50979650505050505050565b60008060008060608587031215613e8f578182fd5b843567ffffffffffffffff80821115613ea6578384fd5b818701915087601f830112613eb9578384fd5b8135613ec761377c82615036565b808282526020808301925080860160a08d838288028a01011115613ee957898afd5b8997505b85881015613f6c5780828f031215613f0357898afd5b613f0c8161500f565b613f168f84613a09565b8152613f248f85850161370a565b8482015260408301356040820152613f3f8f6060850161370a565b6060820152613f518f6080850161370a565b60808201528552600197909701969382019390810190613eed565b509199508a013597505050604088013592505080821115613f8b578384fd5b50613f9887828801613896565b95989497509550505050565b600060208284031215613fb5578081fd5b815167ffffffffffffffff811115613fcb578182fd5b6128b284828501613937565b60008060408385031215613fe9578182fd5b823567ffffffffffffffff811115613fff578283fd5b61400b858286016138d9565b925050602083013561401c816150a0565b809150509250929050565b600060208284031215614038578081fd5b8151612729816150b5565b60008060008060008060c0878903121561405b578384fd5b8635614066816150b5565b95506020870135614076816150a0565b945060408701359350606087013561408d816150dd565b9598949750929560808101359460a0909101359350915050565b600080600080600080600060c0888a0312156140c1578485fd5b8735965060208801356140d3816150d0565b955060408801356140e3816150a0565b945060608801356140f3816150a0565b9350608088013567ffffffffffffffff8082111561410f578283fd5b61411b8b838c01613a23565b945060a08a0135915080821115614130578283fd5b5061413d8a828b01613896565b989b979a50959850939692959293505050565b600080600080600080600060e0888a03121561416a578081fd5b87359650602088013561417c816150d0565b9550604088013561418c816150a0565b9450606088013561419c816150a0565b9350608088013567ffffffffffffffff8111156141b7578182fd5b6141c38a828b01613a23565b93505060a0880135915060c0880135905092959891949750929550565b600080600080600080600080610100898b0312156141fc578182fd5b8835614207816150a0565b97506020890135614217816150a0565b965060408901359550606089013594506080890135614235816150b5565b935060a0890135614245816150dd565b979a969950949793969295929450505060c08201359160e0013590565b600080600080600080600060e0888a03121561427c578081fd5b8735614287816150a0565b96506020880135614297816150a0565b9550604088013594506060880135935060808801356142b5816150dd565b9699959850939692959460a0840135945060c09093013592915050565b600080604083850312156142e4578182fd5b82356142ef816150a0565b946020939093013593505050565b60008060008060808587031215614312578182fd5b843561431d816150a0565b9350602085013561432d816150a0565b9250604085013561433d816150a0565b9396929550929360600135925050565b60006020828403121561435e578081fd5b8151612729816150c3565b6000806040838503121561437b578182fd5b8251614386816150c3565b6020939093015192949293505050565b6000806000606084860312156143aa578081fd5b83516143b5816150c3565b602085015160409095015190969495509392505050565b6000602082840312156143dd578081fd5b8151612729816150d0565b6000806000606084860312156143fc578081fd5b8351614407816150d0565b602085015190935067ffffffffffffffff811115614423578182fd5b61442f86828701613937565b925050604084015190509250925092565b60008060008060008060008060008060006101608c8e031215614461578485fd5b61446b8d8d613a14565b9a5067ffffffffffffffff8060208e01351115614486578586fd5b6144968e60208f01358f016137d5565b9a508060408e013511156144a8578586fd5b6144b88e60408f01358f01613715565b909a5098506144ca8e60608f01613aca565b97508060e08e013511156144dc578586fd5b6144ec8e60e08f01358f01613715565b90975095506101008d013594506101208d013593506101408d0135811015614512578283fd5b506145248d6101408e01358e01613896565b81935080925050509295989b509295989b9093969950565b600060c0828403121561454d578081fd5b61455760c061500f565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a08201528091505092915050565b60008060008060008061012087890312156145b0578384fd5b863567ffffffffffffffff808211156145c7578586fd5b9088019060c0828b0312156145da578586fd5b6145e460c061500f565b823581526145f58b60208501613a14565b60208201526040830135614608816150a0565b604082015261461a8b6060850161370a565b60608201526080830135608082015260a08301358281111561463a578788fd5b6146468c8286016139a0565b60a08301525080985050505061465f8860208901613aca565b959895975050505060a08401359360c08101359360e08201359350610100909101359150565b600060208284031215614696578081fd5b5035919050565b6000602082840312156146ae578081fd5b5051919050565b6000602082840312156146c6578081fd5b8151612729816150dd565b600080604083850312156146e3578182fd5b8251614386816150dd565b6001600160a01b03169052565b60008284526020808501945082825b8581101561473857813561471d816150a0565b6001600160a01b03168752958201959082019060010161470a565b509495945050505050565b60008284526020808501945082825b8581101561473857813587529582019590820190600101614752565b6000815180845260208085019450808401835b8381101561473857815187529582019590820190600101614781565b15159052565b600081518084526147bb816020860160208601615056565b601f01601f19169290920160200192915050565b8051608080845281519084018190526000916020919082019060a0860190845b818110156148145783516001600160a01b0316835292840192918401916001016147ef565b50508285015191508581038387015261482d818361476e565b925050506040830151848203604086015261484882826147a3565b915050606083015161485d606086018261479d565b509392505050565b8035614870816150a0565b6001600160a01b03908116835260208201359061488c826150b5565b90151560208401526040820135906148a3826150a0565b16604083015260608101356148b7816150b5565b8015156060840152505050565b600082516148d6818460208701615056565b9190910192915050565b600084516148f2818460208901615056565b8201838582379092019182525092915050565b918252602082015260400190565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6000604082016001600160a01b03808616845260206040818601528286518085526060870191508288019450855b81811015614997578551851683529483019491830191600101614979565b509098975050505050505050565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039889168152969097166020870152604086019490945260608501929092521515608084015260ff1660a083015260c082015260e08101919091526101000190565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6001600160a01b0397881681529515156020870152939095166040850152606084019190915260ff16608083015260a082019290925260c081019190915260e00190565b6001600160a01b0392909216825260ff16602082015260400190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039390931683526020830191909152604082015260600190565b6040808252810183905260008460608301825b86811015614b265760208335614b0b816150a0565b6001600160a01b031683529283019290910190600101614af6565b5080925050506001600160a01b0383166020830152949350505050565b6020808252825182820181905260009190848201906040850190845b81811015614b7b57835183529284019291840191600101614b5f565b50909695505050505050565b602080825282518282018190526000919060409081850190868401855b82811015614c105781518051614bb98161508c565b8552808701516001600160a01b0316878601528581015186860152606080820151614be6828801826146ee565b505060809081015190614bfb868201836146ee565b505060a0939093019290850190600101614ba4565b5091979650505050505050565b901515815260200190565b60008582526001600160a01b03808616602084015280851660408401525060806060830152610ae760808301846147cf565b60408101614c6784615082565b9281526020015290565b60608101614c7e85615082565b938152602081019290925260409091015290565b6000614c9d8561508c565b84825260606020830152614cb4606083018561476e565b9050826040830152949350505050565b6000610120808301614cd58c615096565b8b84526020808501929092528a5190819052610140808501928281028601909101918c8201855b82811015614d7c578785037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec00186528151805186528481015185870152604080820151908701526060808201519087015260809081015160a091870182905290614d68818801836147a3565b978601979650505090830190600101614cfc565b505050508381036040850152614d93818a8c6146fb565b915050614da36060840188614865565b82810360e0840152614db6818688614743565b915050826101008301529998505050505050505050565b60208082526010908201527f496e636f72726563742073656e64657200000000000000000000000000000000604082015260600190565b60208082526017908201527f496e636f727265637420746f6b656e20666f7220706964000000000000000000604082015260600190565b60208082526019908201527f53656e646572206e6f74206f776e6572206f662072656c696300000000000000604082015260600190565b6020808252601f908201527f52656c617965722063616e206f6e6c7920617070726f766520697473656c6600604082015260600190565b60208082526013908201527f554e48414e444c45445f504f4f4c5f4b494e4400000000000000000000000000604082015260600190565b60208082526019908201527f696e76616c696420636861696e6564207265666572656e636500000000000000604082015260600190565b600060e08252855160e08301526020860151614f3281615096565b61010083015260408601516001600160a01b03908116610120840152606087015116610140830152608086015161016083015260a086015160c0610180840152614f806101a08401826147a3565b915050614f906020830186614865565b60a082019390935260c0015292915050565b90815260200190565b9182526001600160a01b0316602082015260400190565b92835260208301919091526001600160a01b0316604082015260600190565b60ff929092168252602082015260400190565b60ff9390931683526020830191909152604082015260600190565b60405181810167ffffffffffffffff8111828210171561502e57600080fd5b604052919050565b600067ffffffffffffffff82111561504c578081fd5b5060209081020190565b60005b83811015615071578181015183820152602001615059565b8381111561048c5750506000910152565b6003811061337357fe5b6004811061337357fe5b6002811061337357fe5b6001600160a01b038116811461337357600080fd5b801515811461337357600080fd5b6003811061337357600080fd5b6004811061337357600080fd5b60ff8116811461337357600080fdfea26469706673582212201116b3dc300af81974d4880ecb3f740ae6e3b2bae1c2987e4b535ba4c4a7a69464736f6c6343000701003360e06040527fae1dc54057af8e8e5ce068cdd4383149c7efcb30e8fb95b592ee1594367fb50960c0523480156200003557600080fd5b5060405162002e8538038062002e858339810160408190526200005891620000ef565b80806001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156200009357600080fd5b505afa158015620000a8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000ce9190620000ef565b6001600160601b0319606091821b811660805291901b1660a052506200012e565b60006020828403121562000101578081fd5b81516200010e8162000115565b9392505050565b6001600160a01b03811681146200012b57600080fd5b50565b60805160601c60a05160601c60c051612d24620001616000398061120552508061050b525080611a325250612d246000f3fe60806040526004361061007b5760003560e01c80638fe4624f1161004e5780638fe4624f14610100578063b6d2473714610113578063d80952d514610126578063f3cab685146101395761007b565b806318369446146100805780632e6272ea146100a9578063837f9bcb146100c95780638d928af8146100de575b600080fd5b61009361008e3660046123c7565b61014c565b6040516100a09190612862565b60405180910390f35b6100bc6100b736600461252b565b6103de565b6040516100a091906128a6565b6100dc6100d736600461201f565b6104f8565b005b3480156100ea57600080fd5b506100f3610509565b6040516100a0919061290c565b6100dc61010e36600461220e565b61052d565b6100dc61012136600461229e565b6105e1565b6100dc610134366004612165565b610628565b6100bc610147366004612619565b61071f565b60603361015c60208a018a611e6e565b73ffffffffffffffffffffffffffffffffffffffff16148061019f57503061018760208a018a611e6e565b73ffffffffffffffffffffffffffffffffffffffff16145b6101de576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d590612b40565b60405180910390fd5b60005b8b518110156102435760008c82815181106101f857fe5b602002602001015160600151905061020f81610731565b1561023a5761021d8161077c565b8d838151811061022957fe5b602002602001015160600181815250505b506001016101e1565b5061024c610509565b73ffffffffffffffffffffffffffffffffffffffff1663f84d066e8d8d8d8d8d6040518663ffffffff1660e01b815260040161028c959493929190612997565b600060405180830381600087803b1580156102a657600080fd5b505af11580156102ba573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526102e29190810190611f8f565b905060005b828110156103ce5761030d8484838181106102fe57fe5b90506040020160200135610731565b610343576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d590612bae565b61037788888381811061035257fe5b9050602002013583838151811061036557fe5b602002602001015113156101fb6107a7565b6103c684848381811061038657fe5b905060400201602001356103c1848787868181106103a057fe5b90506040020160000135815181106103b457fe5b60200260200101516107b5565b6107c1565b6001016102e7565b509b9a5050505050505050505050565b6000336103ee6020880188611e6e565b73ffffffffffffffffffffffffffffffffffffffff1614806104315750306104196020880188611e6e565b73ffffffffffffffffffffffffffffffffffffffff16145b610467576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d590612b40565b6104748760800151610731565b1561048c57610486876080015161077c565b60808801525b6104a48761049f368990038901896124c3565b6107d4565b90506104d66000886020015160018111156104bb57fe5b146104c957858211156104ce565b858210155b6101fb6107a7565b6104df82610731565b156104ee576104ee82826107c1565b9695505050505050565b6105036103e6610a22565b50505050565b7f000000000000000000000000000000000000000000000000000000000000000090565b73ffffffffffffffffffffffffffffffffffffffff8516331480610566575073ffffffffffffffffffffffffffffffffffffffff851630145b61059c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d590612b40565b6105aa868460400151610a4f565b604084015260006105bd88878787610af0565b90506105c882610731565b156105d7576105d782826107c1565b5050505050505050565b6105ea81610731565b156105fb576105f88161077c565b90505b610624610606610509565b73ffffffffffffffffffffffffffffffffffffffff84169083610d4e565b5050565b73ffffffffffffffffffffffffffffffffffffffff8516331480610661575073ffffffffffffffffffffffffffffffffffffffff851630145b610697576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d590612b40565b6106a5868460400151610eac565b604084015260606106b888878787610f39565b905060005b828110156107145761070c8484838181106106d457fe5b90506040020160200135838686858181106106eb57fe5b90506040020160000135815181106106ff57fe5b60200260200101516107c1565b6001016106bd565b505050505050505050565b600061072a82611198565b9392505050565b7fba100000000000000000000000000000000000000000000000000000000000007ffff00000000000000000000000000000000000000000000000000000000000008216145b919050565b600080600061078a84611198565b91509150610797846111af565b1561072a57600082559392505050565b816106245761062481610a22565b60ff81901d9081180390565b60006107cc836111f6565b919091555050565b604080516002808252606080830184526000939092919060208301908036833701905050905083604001518160008151811061080c57fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083606001518160018151811061085857fe5b73ffffffffffffffffffffffffffffffffffffffff9290921660209283029190910190910152604080516001808252818301909252606091816020015b61089d611a54565b8152602001906001900390816108955790505090506040518060a00160405280866000015181526020016000815260200160018152602001866080015181526020018660a00151815250816000815181106108f457fe5b60200260200101819052506060610909610509565b73ffffffffffffffffffffffffffffffffffffffff1663f84d066e87602001518486896040518563ffffffff1660e01b815260040161094b9493929190612a82565b600060405180830381600087803b15801561096557600080fd5b505af1158015610979573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526109a19190810190611f8f565b90506000866020015160018111156109b557fe5b1415610a01576109df6000826001815181106109cd57fe5b602002602001015113156103e76107a7565b806001815181106109ec57fe5b60200260200101516000039350505050610a1c565b80600081518110610a0e57fe5b602002602001015193505050505b92915050565b610a4c817f42414c0000000000000000000000000000000000000000000000000000000000611254565b50565b60606000836003811115610a5f57fe5b1415610a7557610a6e826112cf565b9050610a1c565b6001836003811115610a8357fe5b1480610a9a57506002836003811115610a9857fe5b145b80610ab057506003836003811115610aae57fe5b145b15610abe57610a6e826112cf565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d590612b77565b600080610afb610509565b73ffffffffffffffffffffffffffffffffffffffff1663f6c00927876040518263ffffffff1660e01b8152600401610b3391906128a6565b604080518083038186803b158015610b4a57600080fd5b505afa158015610b5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b829190611e8a565b50905060606000610b9788866000015161130c565b915091506000610ba5610509565b73ffffffffffffffffffffffffffffffffffffffff1663d2946c2b6040518163ffffffff1660e01b815260040160206040518083038186803b158015610bea57600080fd5b505afa158015610bfe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2291906122c9565b90508373ffffffffffffffffffffffffffffffffffffffff166387ec68178a8a8a87878773ffffffffffffffffffffffffffffffffffffffff166355c676286040518163ffffffff1660e01b815260040160206040518083038186803b158015610c8b57600080fd5b505afa158015610c9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc39190612631565b8d604001516040518863ffffffff1660e01b8152600401610cea97969594939291906128af565b600060405180830381600087803b158015610d0457600080fd5b505af1158015610d18573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d409190810190612649565b509998505050505050505050565b8015801590610dff57506040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84169063dd62ed3e90610dac90309086906004016127ec565b60206040518083038186803b158015610dc457600080fd5b505afa158015610dd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dfc9190612631565b15155b15610e8857610e888363095ea7b360e01b846000604051602401610e24929190612813565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915261144d565b610ea78363095ea7b360e01b8484604051602401610e2492919061283c565b505050565b6060610eb7826114fa565b15610ec557610a6e82611529565b6000836003811115610ed357fe5b1415610ee257610a6e8261157c565b6001836003811115610ef057fe5b1415610eff57610a6e826115c5565b6002836003811115610f0d57fe5b1415610f1c57610a6e8261160b565b6003836003811115610f2a57fe5b1415610abe57610a6e82611637565b60606000610f45610509565b73ffffffffffffffffffffffffffffffffffffffff1663f6c00927876040518263ffffffff1660e01b8152600401610f7d91906128a6565b604080518083038186803b158015610f9457600080fd5b505afa158015610fa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fcc9190611e8a565b50905060606000610fe188866000015161130c565b915091506000610fef610509565b73ffffffffffffffffffffffffffffffffffffffff1663d2946c2b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561103457600080fd5b505afa158015611048573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061106c91906122c9565b90508373ffffffffffffffffffffffffffffffffffffffff16636028bfd48a8a8a87878773ffffffffffffffffffffffffffffffffffffffff166355c676286040518163ffffffff1660e01b815260040160206040518083038186803b1580156110d557600080fd5b505afa1580156110e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110d9190612631565b8d604001516040518863ffffffff1660e01b815260040161113497969594939291906128af565b600060405180830381600087803b15801561114e57600080fd5b505af1158015611162573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261118a9190810190612649565b9a9950505050505050505050565b6000806111a4836111f6565b915081549050915091565b7fffff000000000000000000000000000000000000000000000000000000000000167fba100000000000000000000000000000000000000000000000000000000000001490565b600060016112038361166a565b7f00000000000000000000000000000000000000000000000000000000000000006040516020016112359291906127de565b60408051808303601f1901815291905280516020909101200392915050565b7f08c379a000000000000000000000000000000000000000000000000000000000600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b60445260e882901c90606490fd5b606060006112dc8361168d565b905060018160038111156112ec57fe5b1415611303576112fb836116a3565b915050610777565b82915050610777565b6060600060608061131c856116f6565b9050611326610509565b73ffffffffffffffffffffffffffffffffffffffff1663f94d4668876040518263ffffffff1660e01b815260040161135e91906128a6565b60006040518083038186803b15801561137657600080fd5b505afa15801561138a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526113b29190810190611ec3565b825184519297509095509193506113c991906117a6565b60005b82518110156114435760008382815181106113e357fe5b6020026020010151905061143a8383815181106113fc57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16146102086107a7565b506001016113cc565b5050509250929050565b600060608373ffffffffffffffffffffffffffffffffffffffff168360405161147691906127c2565b6000604051808303816000865af19150503d80600081146114b3576040519150601f19603f3d011682016040523d82523d6000602084013e6114b8565b606091505b509150915060008214156114d0573d6000803e3d6000fd5b6105038151600014806114f25750818060200190518101906114f29190612149565b6101a26107a7565b6000808251118015610a1c575060ff80168280602001905181019061151f919061268e565b60ff161492915050565b60606000611536836117b3565b905061154181610731565b156113035761154f8161077c565b905060ff81604051602001611565929190612be5565b604051602081830303815290604052915050610777565b60606000611589836117c9565b9050600081600281111561159957fe5b14156115a8576112fb836117df565b60018160028111156115b657fe5b1415611303576112fb83611842565b606060006115d2836117c9565b60028111156115dd57fe5b905060ff81166115f1576112fb838261187e565b60015b60ff168160ff161415611303576112fb83826118e0565b60606000611618836117c9565b600281111561162357fe5b905060ff8116611303576112fb838261187e565b60606000611644836117c9565b600281111561164f57fe5b905060ff8116611663576112fb838261187e565b60026115f4565b7dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1690565b600081806020019051810190610a1c9190612364565b60608060006116b18461193b565b915091506116be8261195e565b6116c857836116ee565b600182826040516020016116de93929190612965565b6040516020818303038152906040525b949350505050565b606080825167ffffffffffffffff8111801561171157600080fd5b5060405190808252806020026020018201604052801561173b578160200160208202803683370190505b50905060005b835181101561179f5761176684828151811061175957fe5b60200260200101516119c1565b82828151811061177257fe5b73ffffffffffffffffffffffffffffffffffffffff90921660209283029190910190910152600101611741565b5092915050565b61062481831460676107a7565b60008180602001905181019061072a91906126a9565b600081806020019051810190610a1c91906122e5565b60606000806117ed846119e6565b915091506117fa82610731565b15611838576118088261077c565b91506000828260405160200161182093929190612944565b60405160208183030381529060405292505050610777565b8392505050610777565b6060600061184f836119fd565b905061185a81610731565b15611303576118688161077c565b905060018160405160200161156592919061292d565b606060008061188c856119e6565b9150915061189982610731565b156118d6576118a78261077c565b91508382826040516020016118be93929190612bf8565b60405160208183030381529060405292505050610a1c565b8492505050610a1c565b606060006118ed846119fd565b90506118f881610731565b15611932576119068161077c565b9050828160405160200161191b929190612be5565b604051602081830303815290604052915050610a1c565b83915050610a1c565b60606000828060200190518101906119539190612380565b909590945092505050565b600080805b835181101561179f57600084828151811061197a57fe5b6020026020010151905061198d81610731565b156119b85761199b8161077c565b8583815181106119a757fe5b602002602001018181525050600192505b50600101611963565b60006119cc82611a13565b6119de576119d982611a2d565b610a1c565b610a1c611a30565b60008082806020019051810190611953919061232e565b60008180602001905181019061072a9190612301565b73ffffffffffffffffffffffffffffffffffffffff161590565b90565b7f000000000000000000000000000000000000000000000000000000000000000090565b6040518060a0016040528060008019168152602001600081526020016000815260200160008152602001606081525090565b8035610a1c81612ca4565b60008083601f840112611aa2578182fd5b50813567ffffffffffffffff811115611ab9578182fd5b6020830191508360208083028501011115611ad357600080fd5b9250929050565b600082601f830112611aea578081fd5b8135611afd611af882612c3a565b612c13565b818152915060208083019084810181840286018201871015611b1e57600080fd5b60005b84811015611b46578135611b3481612ca4565b84529282019290820190600101611b21565b505050505092915050565b600082601f830112611b61578081fd5b8135611b6f611af882612c3a565b818152915060208083019084810160005b84811015611b46578135870160a080601f19838c03011215611ba157600080fd5b611baa81612c13565b85830135815260408084013587830152606080850135828401526080915081850135818401525082840135925067ffffffffffffffff831115611bec57600080fd5b611bfa8c8885870101611d1c565b90820152865250509282019290820190600101611b80565b60008083601f840112611c23578182fd5b50813567ffffffffffffffff811115611c3a578182fd5b602083019150836020604083028501011115611ad357600080fd5b600082601f830112611c65578081fd5b8135611c73611af882612c3a565b818152915060208083019084810181840286018201871015611c9457600080fd5b60005b84811015611b4657813584529282019290820190600101611c97565b600082601f830112611cc3578081fd5b8151611cd1611af882612c3a565b818152915060208083019084810181840286018201871015611cf257600080fd5b60005b84811015611b4657815184529282019290820190600101611cf5565b8035610a1c81612cc6565b600082601f830112611d2c578081fd5b813567ffffffffffffffff811115611d42578182fd5b611d556020601f19601f84011601612c13565b9150808252836020828501011115611d6c57600080fd5b8060208401602084013760009082016020015292915050565b8035610a1c81612ce1565b803560028110610a1c57600080fd5b600060808284031215611db0578081fd5b611dba6080612c13565b9050813567ffffffffffffffff80821115611dd457600080fd5b611de085838601611ada565b83526020840135915080821115611df657600080fd5b611e0285838601611c55565b60208401526040840135915080821115611e1b57600080fd5b50611e2884828501611d1c565b604083015250611e3b8360608401611d11565b606082015292915050565b600060808284031215611e57578081fd5b50919050565b805160ff81168114610a1c57600080fd5b600060208284031215611e7f578081fd5b813561072a81612ca4565b60008060408385031215611e9c578081fd5b8251611ea781612ca4565b6020840151909250611eb881612cd4565b809150509250929050565b600080600060608486031215611ed7578081fd5b835167ffffffffffffffff80821115611eee578283fd5b818601915086601f830112611f01578283fd5b8151611f0f611af882612c3a565b80828252602080830192508086018b828387028901011115611f2f578788fd5b8796505b84871015611f5a578051611f4681612ca4565b845260019690960195928101928101611f33565b508901519097509350505080821115611f71578283fd5b50611f7e86828701611cb3565b925050604084015190509250925092565b60006020808385031215611fa1578182fd5b825167ffffffffffffffff811115611fb7578283fd5b8301601f81018513611fc7578283fd5b8051611fd5611af882612c3a565b8181528381019083850185840285018601891015611ff1578687fd5b8694505b83851015612013578051835260019490940193918501918501611ff5565b50979650505050505050565b60008060008060608587031215612034578182fd5b843567ffffffffffffffff8082111561204b578384fd5b818701915087601f83011261205e578384fd5b813561206c611af882612c3a565b808282526020808301925080860160a08d838288028a0101111561208e57898afd5b8997505b858810156121115780828f0312156120a857898afd5b6120b181612c13565b6120bb8f84611d85565b81526120c98f858501611a86565b84820152604083013560408201526120e48f60608501611a86565b60608201526120f68f60808501611a86565b60808201528552600197909701969382019390810190612092565b509199508a013597505050604088013592505080821115612130578384fd5b5061213d87828801611c12565b95989497509550505050565b60006020828403121561215a578081fd5b815161072a81612cc6565b600080600080600080600060c0888a03121561217f578485fd5b87359650602088013561219181612ce1565b955060408801356121a181612ca4565b945060608801356121b181612ca4565b9350608088013567ffffffffffffffff808211156121cd578485fd5b6121d98b838c01611d9f565b945060a08a01359150808211156121ee578384fd5b506121fb8a828b01611c12565b989b979a50959850939692959293505050565b600080600080600080600060e0888a031215612228578081fd5b87359650602088013561223a81612ce1565b9550604088013561224a81612ca4565b9450606088013561225a81612ca4565b9350608088013567ffffffffffffffff811115612275578182fd5b6122818a828b01611d9f565b93505060a0880135915060c0880135905092959891949750929550565b600080604083850312156122b0578182fd5b82356122bb81612ca4565b946020939093013593505050565b6000602082840312156122da578081fd5b815161072a81612ca4565b6000602082840312156122f6578081fd5b815161072a81612cd4565b60008060408385031215612313578182fd5b825161231e81612cd4565b6020939093015192949293505050565b600080600060608486031215612342578081fd5b835161234d81612cd4565b602085015160409095015190969495509392505050565b600060208284031215612375578081fd5b815161072a81612ce1565b600080600060608486031215612394578081fd5b835161239f81612ce1565b602085015190935067ffffffffffffffff8111156123bb578182fd5b611f7e86828701611cb3565b60008060008060008060008060008060006101608c8e0312156123e8578485fd5b6123f28d8d611d90565b9a5067ffffffffffffffff8060208e0135111561240d578586fd5b61241d8e60208f01358f01611b51565b9a508060408e0135111561242f578586fd5b61243f8e60408f01358f01611a91565b909a5098506124518e60608f01611e46565b97508060e08e01351115612463578586fd5b6124738e60e08f01358f01611a91565b90975095506101008d013594506101208d013593506101408d0135811015612499578283fd5b506124ab8d6101408e01358e01611c12565b81935080925050509295989b509295989b9093969950565b6000608082840312156124d4578081fd5b6124de6080612c13565b82356124e981612ca4565b815260208301356124f981612cc6565b6020820152604083013561250c81612ca4565b6040820152606083013561251f81612cc6565b60608201529392505050565b6000806000806000806101208789031215612544578384fd5b863567ffffffffffffffff8082111561255b578586fd5b9088019060c0828b03121561256e578586fd5b61257860c0612c13565b823581526125898b60208501611d90565b6020820152604083013561259c81612ca4565b60408201526125ae8b60608501611a86565b60608201526080830135608082015260a0830135828111156125ce578788fd5b6125da8c828601611d1c565b60a0830152508098505050506125f38860208901611e46565b959895975050505060a08401359360c08101359360e08201359350610100909101359150565b60006020828403121561262a578081fd5b5035919050565b600060208284031215612642578081fd5b5051919050565b6000806040838503121561265b578182fd5b82519150602083015167ffffffffffffffff811115612678578182fd5b61268485828601611cb3565b9150509250929050565b60006020828403121561269f578081fd5b61072a8383611e5d565b600080604083850312156126bb578182fd5b6126c58484611e5d565b9150602083015190509250929050565b6000815180845260208085018081965082840281019150828601855b8581101561274f5782840389528151805185528581015186860152604080820151908601526060808201519086015260809081015160a09186018290529061273b81870183612796565b9a87019a95505050908401906001016126f1565b5091979650505050505050565b6000815180845260208085019450808401835b8381101561278b5781518752958201959082019060010161276f565b509495945050505050565b600081518084526127ae816020860160208601612c5a565b601f01601f19169290920160200192915050565b600082516127d4818460208701612c5a565b9190910192915050565b918252602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff92909216825260ff16602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b6020808252825182820181905260009190848201906040850190845b8181101561289a5783518352928401929184019160010161287e565b50909695505050505050565b90815260200190565b600088825273ffffffffffffffffffffffffffffffffffffffff808916602084015280881660408401525060e060608301526128ee60e083018761275c565b8560808401528460a084015282810360c084015261118a8185612796565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b6040810161293a84612c86565b9281526020015290565b6060810161295185612c86565b938152602081019290925260409091015290565b600061297085612c90565b84825260606020830152612987606083018561275c565b9050826040830152949350505050565b60006129a287612c9a565b868252602060e0818401526129ba60e08401886126d5565b838103604085015285815286908201835b87811015612a065782356129de81612ca4565b73ffffffffffffffffffffffffffffffffffffffff16825291830191908301906001016129cb565b509250508335612a1581612ca4565b73ffffffffffffffffffffffffffffffffffffffff81811660608601529185013591612a4083612cc6565b9115156080850152604085013591612a5783612ca4565b9190911660a0840152506060830135612a6f81612cc6565b80151560c0840152509695505050505050565b6000612a8d86612c9a565b858252602060e081840152612aa560e08401876126d5565b8381036040850152855180825282870191830190845b81811015612aed57835173ffffffffffffffffffffffffffffffffffffffff1683529284019291840191600101612abb565b5050809350505073ffffffffffffffffffffffffffffffffffffffff80855116606085015281850151151560808501528060408601511660a085015250506060830151151560c083015295945050505050565b60208082526010908201527f496e636f72726563742073656e64657200000000000000000000000000000000604082015260600190565b60208082526013908201527f554e48414e444c45445f504f4f4c5f4b494e4400000000000000000000000000604082015260600190565b60208082526019908201527f696e76616c696420636861696e6564207265666572656e636500000000000000604082015260600190565b60ff929092168252602082015260400190565b60ff9390931683526020830191909152604082015260600190565b60405181810167ffffffffffffffff81118282101715612c3257600080fd5b604052919050565b600067ffffffffffffffff821115612c50578081fd5b5060209081020190565b60005b83811015612c75578181015183820152602001612c5d565b838111156105035750506000910152565b60038110610a4c57fe5b60048110610a4c57fe5b60028110610a4c57fe5b73ffffffffffffffffffffffffffffffffffffffff81168114610a4c57600080fd5b8015158114610a4c57600080fd5b60038110610a4c57600080fd5b60048110610a4c57600080fdfea2646970667358221220135a367e50b7c25c8d0d702b0b66d406f61597400ad427360488d6b80e10f26d64736f6c6343000701003360e06040523480156200001157600080fd5b5060405162000be738038062000be7833981016040819052620000349162000123565b8062000040816200006e565b5050600180556001600160601b0319606093841b811660805291831b821660a05290911b1660c05262000241565b80516200008390600090602084019062000087565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620000ca57805160ff1916838001178555620000fa565b82800160010185558215620000fa579182015b82811115620000fa578251825591602001919060010190620000dd565b50620001089291506200010c565b5090565b5b808211156200010857600081556001016200010d565b6000806000806080858703121562000139578384fd5b8451620001468162000228565b809450506020808601516200015b8162000228565b60408701519094506200016e8162000228565b60608701519093506001600160401b03808211156200018b578384fd5b818801915088601f8301126200019f578384fd5b815181811115620001ae578485fd5b604051601f8201601f1916810185018381118282101715620001ce578687fd5b60405281815283820185018b1015620001e5578586fd5b8592505b81831015620002085783830185015181840186015291840191620001e9565b818311156200021957858583830101525b979a9699509497505050505050565b6001600160a01b03811681146200023e57600080fd5b50565b60805160601c60a05160601c60c05160601c6109626200028560003980610184528061034c52508061025c5280610496525080608952806103a652506109626000f3fe6080604052600436106100695760003560e01c80637887b7c0116100435780637887b7c01461011b5780638d928af814610148578063ac9650d81461015d576100b4565b806328431ac1146100b957806354fd4d50146100e45780637678922e14610106576100b4565b366100b4576100b23373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610206610170565b005b600080fd5b3480156100c557600080fd5b506100ce610182565b6040516100db91906107d9565b60405180910390f35b3480156100f057600080fd5b506100f96101a6565b6040516100db9190610878565b34801561011257600080fd5b506100ce61025a565b34801561012757600080fd5b5061013b610136366004610701565b61027e565b6040516100db91906107fa565b34801561015457600080fd5b506100ce6103a4565b61013b61016b366004610701565b6103c8565b8161017e5761017e816104f0565b5050565b7f000000000000000000000000000000000000000000000000000000000000000090565b60008054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156102505780601f1061022557610100808354040283529160200191610250565b820191906000526020600020905b81548152906001019060200180831161023357829003601f168201915b5050505050905090565b7f000000000000000000000000000000000000000000000000000000000000000090565b606061028861051d565b818067ffffffffffffffff811180156102a057600080fd5b506040519080825280602002602001820160405280156102d457816020015b60608152602001906001900390816102bf5790505b50915060005b81811015610394576103758585838181106102f157fe5b90506020028101906103039190610892565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001692915050610536565b83828151811061038157fe5b60209081029190910101526001016102da565b505061039e6105b9565b92915050565b7f000000000000000000000000000000000000000000000000000000000000000090565b60606103d261051d565b818067ffffffffffffffff811180156103ea57600080fd5b5060405190808252806020026020018201604052801561041e57816020015b60608152602001906001900390816104095790505b50915060005b818110156104de576104bf85858381811061043b57fe5b905060200281019061044d9190610892565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001692915050610536565b8382815181106104cb57fe5b6020908102919091010152600101610424565b506104e76105bf565b5061039e6105b9565b61051a817f42414c00000000000000000000000000000000000000000000000000000000006105d0565b50565b61052f60026001541415610190610170565b6002600155565b6060600060608473ffffffffffffffffffffffffffffffffffffffff168460405161056191906107ba565b600060405180830381855af49150503d806000811461059c576040519150601f19603f3d011682016040523d82523d6000602084013e6105a1565b606091505b50915091506105b0828261064b565b95945050505050565b60018055565b47801561051a5761051a3382610675565b7f08c379a000000000000000000000000000000000000000000000000000000000600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b60445260e882901c90606490fd5b6060821561065a57508061039e565b81511561066a5781518083602001fd5b61039e6101ae6104f0565b610684814710156101a3610170565b60008273ffffffffffffffffffffffffffffffffffffffff16826040516106aa906107d6565b60006040518083038185875af1925050503d80600081146106e7576040519150601f19603f3d011682016040523d82523d6000602084013e6106ec565b606091505b505090506106fc816101a4610170565b505050565b60008060208385031215610713578182fd5b823567ffffffffffffffff8082111561072a578384fd5b818501915085601f83011261073d578384fd5b81358181111561074b578485fd5b866020808302850101111561075e578485fd5b60209290920196919550909350505050565b600081518084526107888160208601602086016108fc565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600082516107cc8184602087016108fc565b9190910192915050565b90565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b6000602080830181845280855180835260408601915060408482028701019250838701855b8281101561086b577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0888603018452610859858351610770565b9450928501929085019060010161081f565b5092979650505050505050565b60006020825261088b6020830184610770565b9392505050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181126108c6578283fd5b83018035915067ffffffffffffffff8211156108e0578283fd5b6020019150368190038213156108f557600080fd5b9250929050565b60005b838110156109175781810151838201526020016108ff565b83811115610926576000848401525b5050505056fea2646970667358221220ffc0bb48682e6ff581e6ea0ebcc8c357487771bb5742061794875a4eddec17d064736f6c63430007010033000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684000000000000000000000000000000000000000000000000000000000000004e7b226e616d65223a22426174636852656c61796572222c2276657273696f6e223a2236222c226465706c6f796d656e74223a2232303233313033312d62617463682d72656c617965722d7636227d000000000000000000000000000000000000

Deployed Bytecode

0x6080604052600436106101ac5760003560e01c80637fd0e5d5116100ec5780639072d9fe1161008a578063b6d2473711610064578063b6d24737146103ab578063d80952d5146103be578063db4c0e91146103d1578063f3cab685146103e4576101ac565b80639072d9fe14610372578063959fc17a14610385578063a7faf77f14610398576101ac565b80638c57198b116100c65780638c57198b146103245780638d64cfbc146103375780638d928af81461034a5780638fe4624f1461035f576101ac565b80637fd0e5d5146102dc57806380db15bd146102fe578063837f9bcb14610311576101ac565b80632e6272ea1161015957806365ca48041161013357806365ca48041461029057806379e7433e146102a35780637bc008f5146102b65780637ec783bb146102c9576101ac565b80632e6272ea1461024a5780633f85d3901461026a57806348699d581461027d576101ac565b8063183694461161018a57806318369446146102045780631c982441146102245780632cbec84e14610237576101ac565b80630e248fea146101b15780631089e5e3146101c657806310f3aaff146101d9575b600080fd5b6101c46101bf366004613daa565b6103f7565b005b6101c46101d4366004613cf2565b610492565b3480156101e557600080fd5b506101ee61059c565b6040516101fb9190614c1d565b60405180910390f35b610217610212366004614440565b6105c0565b6040516101fb9190614b43565b6101c4610232366004613b7d565b6107ca565b6101c4610245366004613cf2565b6108ed565b61025d610258366004614597565b6109c7565b6040516101fb9190614fa2565b6101c4610278366004613d60565b610af1565b6101c461028b366004613bc2565b610bbb565b6101c461029e3660046142fd565b610c01565b6101c46102b1366004613fd7565b610d1f565b6101c46102c43660046142fd565b610ea9565b6101c46102d7366004613b19565b610fad565b3480156102e857600080fd5b506102f161126c565b6040516101fb9190614913565b6101c461030c366004613c15565b611290565b6101c461031f366004613e7a565b611394565b6101c4610332366004614043565b611564565b6101c4610345366004614262565b61160f565b34801561035657600080fd5b506102f1611689565b6101c461036d366004614150565b6116ad565b6101c4610380366004613d26565b6118d7565b6101c46103933660046141e0565b611c87565b6101c46103a6366004613ca2565b611d04565b6101c46103b93660046142d2565b61205b565b6101c46103cc3660046140a7565b612095565b6101c46103df366004613b7d565b612623565b61025d6103f2366004614685565b61271e565b8060005b8181101561048c5783838281811061040f57fe5b90506020020160208101906104249190613ae1565b6001600160a01b03166384e9bd7e336040518263ffffffff1660e01b815260040161044f9190614913565b600060405180830381600087803b15801561046957600080fd5b505af115801561047d573d6000803e3d6000fd5b505050508060010190506103fb565b50505050565b61049b82612730565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b0e38900846040518263ffffffff1660e01b81526004016104eb9190614fa2565b60206040518083038186803b15801561050357600080fd5b505afa158015610517573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061053b919061469d565b90506105706001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684612756565b61048c7f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b7f000000000000000000000000000000000000000000000000000000000000000190565b6060336105d060208a018a613ae1565b6001600160a01b031614806105f95750306105ee60208a018a613ae1565b6001600160a01b0316145b61061e5760405162461bcd60e51b815260040161061590614dcd565b60405180910390fd5b60005b8b518110156106835760008c828151811061063857fe5b602002602001015160600151905061064f816127fe565b1561067a5761065d81612845565b8d838151811061066957fe5b602002602001015160600181815250505b50600101610621565b5061068c611689565b6001600160a01b031663945bcec9858e8e8e8e8e8e8e8e6040518a63ffffffff1660e01b81526004016106c6989796959493929190614cc4565b6000604051808303818588803b1580156106df57600080fd5b505af11580156106f3573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f1916820160405261071c9190810190613dea565b905060005b828110156107ba5761074784848381811061073857fe5b905060400201602001356127fe565b6107635760405162461bcd60e51b815260040161061590614ee0565b6107b284848381811061077257fe5b905060400201602001356107ad8487878681811061078c57fe5b90506040020160000135815181106107a057fe5b6020026020010151612870565b61287c565b600101610721565b509b9a5050505050505050505050565b6108167f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000848761288f565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ea598cb0846040518263ffffffff1660e01b81526004016108669190614fa2565b602060405180830381600087803b15801561088057600080fd5b505af1158015610894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108b8919061469d565b90506108e67f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b5050505050565b6108f682612730565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a1903eab84306040518363ffffffff1660e01b81526004016109479190614913565b6020604051808303818588803b15801561096057600080fd5b505af1158015610974573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610999919061469d565b905061048c7f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b6000336109d76020880188613ae1565b6001600160a01b03161480610a005750306109f56020880188613ae1565b6001600160a01b0316145b610a1c5760405162461bcd60e51b815260040161061590614dcd565b610a2987608001516127fe565b15610a4157610a3b8760800151612845565b60808801525b610a49611689565b6001600160a01b03166352bbbe2984898989896040518663ffffffff1660e01b8152600401610a7b9493929190614f17565b6020604051808303818588803b158015610a9457600080fd5b505af1158015610aa8573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610acd919061469d565b9050610ad8826127fe565b15610ae757610ae7828261287c565b9695505050505050565b6040517f3b9f73840000000000000000000000000000000000000000000000000000000081526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690633b9f738490610b5d90879087903390600401614ae3565b602060405180830381600087803b158015610b7757600080fd5b505af1158015610b8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610baf919061469d565b905061048c82826128ba565b7f000000000000000000000000000000000000000000000000000000000000000115610bf157610bec8383836128d2565b610bfc565b610bfc838383612985565b505050565b610c0c848285612a9f565b6040517f2e1a7d4d0000000000000000000000000000000000000000000000000000000081529091506001600160a01b03851690632e1a7d4d90610c54908490600401614fa2565b600060405180830381600087803b158015610c6e57600080fd5b505af1158015610c82573d6000803e3d6000fd5b505050506001600160a01b038216301461048c576000846001600160a01b03166382c630666040518163ffffffff1660e01b815260040160206040518083038186803b158015610cd157600080fd5b505afa158015610ce5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d099190613afd565b90506108e66001600160a01b0382168484612aef565b60005b8251811015610bfc577f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a9416846001600160a01b0316636352211e848381518110610d6657fe5b60200260200101516040518263ffffffff1660e01b8152600401610d8a9190614fa2565b60206040518083038186803b158015610da257600080fd5b505afa158015610db6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dda9190613afd565b6001600160a01b0316336001600160a01b031614610e0a5760405162461bcd60e51b815260040161061590614e3b565b7f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a9416846001600160a01b03166318fccc76848381518110610e4557fe5b6020026020010151846040518363ffffffff1660e01b8152600401610e6b929190614fab565b600060405180830381600087803b158015610e8557600080fd5b505af1158015610e99573d6000803e3d6000fd5b505060019092019150610d229050565b6000846001600160a01b03166382c630666040518163ffffffff1660e01b815260040160206040518083038186803b158015610ee457600080fd5b505afa158015610ef8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1c9190613afd565b9050610f2a8186848761288f565b6040517f6e553f650000000000000000000000000000000000000000000000000000000081529092506001600160a01b03861690636e553f6590610f749085908790600401614fab565b600060405180830381600087803b158015610f8e57600080fd5b505af1158015610fa2573d6000803e3d6000fd5b505050505050505050565b610fb6826127fe565b15610fc757610fc482612845565b91505b836001600160a01b03167f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a9416846001600160a01b0316636e7d4019856040518263ffffffff1660e01b815260040161101d9190614fa2565b60206040518083038186803b15801561103557600080fd5b505afa158015611049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061106d9190613afd565b6001600160a01b0316146110935760405162461bcd60e51b815260040161061590614e04565b6001600160a01b03861630146110d6576001600160a01b03861633146110cb5760405162461bcd60e51b815260040161061590614dcd565b6110d6868584612b72565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063095ea7b39061113d907f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684908690600401614aa9565b602060405180830381600087803b15801561115757600080fd5b505af115801561116b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118f9190614027565b506040517f6705fcf30000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a9416841690636705fcf3906111f990889087908790600401614ac2565b602060405180830381600087803b15801561121357600080fd5b505af1158015611227573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061124b919061469d565b50611255816127fe565b1561126457611264818361287c565b505050505050565b7f0000000000000000000000007b52d5ef006e59e3227629f97f182d6442380bb690565b6001600160a01b0384163014806112a5575082155b6112c15760405162461bcd60e51b815260040161061590614e72565b606063fa6e671d60e01b3386866040516024016112e093929190614927565b60408051601f19818403018152918152602080830180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909516949094179093525161134f9286918691016148e0565b60408051601f1981840301815291905290506112646001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c81682612c0e565b60005b845181101561147457336001600160a01b03168582815181106113b657fe5b6020026020010151606001516001600160a01b031614806113ff5750306001600160a01b03168582815181106113e857fe5b6020026020010151606001516001600160a01b0316145b61141b5760405162461bcd60e51b815260040161061590614dcd565b600085828151811061142957fe5b6020026020010151604001519050611440816127fe565b1561146b5761144e81612845565b86838151811061145a57fe5b602002602001015160400181815250505b50600101611397565b5061147d611689565b6001600160a01b0316630e8e3e8484866040518363ffffffff1660e01b81526004016114a99190614b87565b6000604051808303818588803b1580156114c257600080fd5b505af11580156114d6573d6000803e3d6000fd5b505050505060005b818110156108e6576114f583838381811061073857fe5b6115115760405162461bcd60e51b815260040161061590614ee0565b61155c83838381811061152057fe5b905060400201602001358685858581811061153757fe5b905060400201600001358151811061154b57fe5b60200260200101516040015161287c565b6001016114de565b6040517fc65427940000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c6542794906115d59030908a908a908a908a908a908a90600401614a49565b600060405180830381600087803b1580156115ef57600080fd5b505af1158015611603573d6000803e3d6000fd5b50505050505050505050565b866001600160a01b031663d505accf87611627611689565b88888888886040518863ffffffff1660e01b815260040161164e9796959493929190614a08565b600060405180830381600087803b15801561166857600080fd5b505af115801561167c573d6000803e3d6000fd5b5050505050505050505050565b7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c890565b6001600160a01b0385163314806116cc57506001600160a01b03851630145b6116e85760405162461bcd60e51b815260040161061590614dcd565b60006116f388612c88565b90506000611700836127fe565b61170b5760006117a0565b6040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b038316906370a0823190611750908990600401614913565b60206040518083038186803b15801561176857600080fd5b505afa15801561177c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a0919061469d565b90506117b0888660400151612c8e565b60408601526117bd611689565b6001600160a01b031663b95cac28858b8a8a8a6040518663ffffffff1660e01b81526004016117ef9493929190614c28565b6000604051808303818588803b15801561180857600080fd5b505af115801561181c573d6000803e3d6000fd5b505050505061182a836127fe565b15610fa2576040517f70a082310000000000000000000000000000000000000000000000000000000081526000906001600160a01b038416906370a0823190611877908a90600401614913565b60206040518083038186803b15801561188f57600080fd5b505afa1580156118a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c7919061469d565b9050611603846107ad8385612d15565b6118e0826127fe565b156118f1576118ee82612845565b91505b6040517f6352211e0000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a9416841690636352211e90611956908690600401614fa2565b60206040518083038186803b15801561196e57600080fd5b505afa158015611982573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119a69190613afd565b6001600160a01b0316336001600160a01b0316146119d65760405162461bcd60e51b815260040161061590614e3b565b6119de6136a4565b6040517fe48dc1350000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684169063e48dc13590611a43908790600401614fa2565b60c06040518083038186803b158015611a5b57600080fd5b505afa158015611a6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a93919061453c565b905060007f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a9416846001600160a01b0316636e7d401983608001516040518263ffffffff1660e01b8152600401611ae79190614fa2565b60206040518083038186803b158015611aff57600080fd5b505afa158015611b13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b379190613afd565b6040517fd1abb9070000000000000000000000000000000000000000000000000000000081529091506001600160a01b037f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684169063d1abb90790611ba390879089908b90600401614fc2565b600060405180830381600087803b158015611bbd57600080fd5b505af1158015611bd1573d6000803e3d6000fd5b50506040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038416925063a9059cbb9150611c1c9089908890600401614aa9565b602060405180830381600087803b158015611c3657600080fd5b505af1158015611c4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c6e9190614027565b50611c78836127fe565b1561126457611264838561287c565b876001600160a01b0316638fcbaf0c88611c9f611689565b8989898989896040518963ffffffff1660e01b8152600401611cc89897969594939291906149bf565b600060405180830381600087803b158015611ce257600080fd5b505af1158015611cf6573d6000803e3d6000fd5b505050505050505050505050565b611d0d826127fe565b15611d1e57611d1b82612845565b91505b611d266136a4565b6040517fe48dc1350000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684169063e48dc13590611d8b908790600401614fa2565b60c06040518083038186803b158015611da357600080fd5b505afa158015611db7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ddb919061453c565b9050846001600160a01b03167f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a9416846001600160a01b0316636e7d401983608001516040518263ffffffff1660e01b8152600401611e379190614fa2565b60206040518083038186803b158015611e4f57600080fd5b505afa158015611e63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e879190613afd565b6001600160a01b031614611ead5760405162461bcd60e51b815260040161061590614e04565b6001600160a01b0386163014611ef0576001600160a01b0386163314611ee55760405162461bcd60e51b815260040161061590614dcd565b611ef0868685612b72565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0386169063095ea7b390611f57907f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684908790600401614aa9565b602060405180830381600087803b158015611f7157600080fd5b505af1158015611f85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fa99190614027565b506040517fe2bbb1580000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684169063e2bbb158906120119086908890600401614905565b600060405180830381600087803b15801561202b57600080fd5b505af115801561203f573d6000803e3d6000fd5b5050505061204c826127fe565b1561126457611264828461287c565b612064816127fe565b156120755761207281612845565b90505b612091612080611689565b6001600160a01b0384169083612d2b565b5050565b6001600160a01b0385163314806120b457506001600160a01b03851630145b6120d05760405162461bcd60e51b815260040161061590614dcd565b60608167ffffffffffffffff811180156120e957600080fd5b50604051908082528060200260200182016040528015612113578160200160208202803683370190505b50905060608267ffffffffffffffff8111801561212f57600080fd5b50604051908082528060200260200182016040528015612159578160200160208202803683370190505b50905060005b838110156122c95761217685858381811061073857fe5b6121925760405162461bcd60e51b815260040161061590614ee0565b85516000908686848181106121a357fe5b90506040020160000135815181106121b757fe5b60200260200101519050866060015115612205576121d481612e13565b8483815181106121e057fe5b60200260200101906001600160a01b031690816001600160a01b0316815250506122c0565b61220e81612e16565b61229b5761221b81612e13565b6001600160a01b03166370a08231896040518263ffffffff1660e01b81526004016122469190614913565b60206040518083038186803b15801561225e57600080fd5b505afa158015612272573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612296919061469d565b6122a7565b876001600160a01b0316315b8383815181106122b357fe5b6020026020010181815250505b5060010161215f565b50846060015115612360576122dc611689565b6001600160a01b0316630f5a6efa87846040518363ffffffff1660e01b815260040161230992919061494b565b60006040518083038186803b15801561232157600080fd5b505afa158015612335573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261235d9190810190613fa4565b90505b61236e888660400151612e23565b604086015261237b611689565b6001600160a01b0316638bdb39138a8989896040518563ffffffff1660e01b81526004016123ac9493929190614c28565b600060405180830381600087803b1580156123c657600080fd5b505af11580156123da573d6000803e3d6000fd5b50606092508591505067ffffffffffffffff811180156123f957600080fd5b50604051908082528060200260200182016040528015612423578160200160208202803683370190505b5090508560600151156124c057612438611689565b6001600160a01b0316630f5a6efa88856040518363ffffffff1660e01b815260040161246592919061494b565b60006040518083038186803b15801561247d57600080fd5b505afa158015612491573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526124b99190810190613fa4565b90506125be565b60005b848110156125bc5786516000908787848181106124dc57fe5b90506040020160000135815181106124f057fe5b6020026020010151905061250381612e16565b6125905761251081612e13565b6001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040161253b9190614913565b60206040518083038186803b15801561255357600080fd5b505afa158015612567573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061258b919061469d565b61259c565b886001600160a01b0316315b8383815181106125a857fe5b6020908102919091010152506001016124c3565b505b60005b8481101561167c5761261b8686838181106125d857fe5b905060400201602001356107ad8584815181106125f157fe5b602002602001015185858151811061260557fe5b6020026020010151612d1590919063ffffffff16565b6001016125c1565b61264e7f00000000000000000000000000000000000000000000000000000000000000008386612a9f565b915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663de0e9a3e846040518263ffffffff1660e01b815260040161269e9190614fa2565b602060405180830381600087803b1580156126b857600080fd5b505af11580156126cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126f0919061469d565b90506108e67f00000000000000000000000000000000000000000000000000000000000000008583856127d0565b600061272982612eb0565b9392505050565b600061273b826127fe565b612745578161274e565b61274e82612845565b90505b919050565b612765814710156101a3612ec7565b6000826001600160a01b03168260405161277e90612e13565b60006040518083038185875af1925050503d80600081146127bb576040519150601f19603f3d011682016040523d82523d6000602084013e6127c0565b606091505b50509050610bfc816101a4612ec7565b6001600160a01b03831630146127f4576127f46001600160a01b0385168484612aef565b61048c81836128ba565b7ffff0000000000000000000000000000000000000000000000000000000000000167fba100000000000000000000000000000000000000000000000000000000000001490565b600080600061285384612eb0565b9150915061286084612ed5565b1561272957600082559392505050565b60ff81901d9081180390565b600061288783612f1c565b919091555050565b600061289c858484612a9f565b90506128b26001600160a01b0386168583612d2b565b949350505050565b6128c3826127fe565b1561209157612091828261287c565b8060005b818110156108e6578383828181106128ea57fe5b90506020020160208101906128ff9190613ae1565b6001600160a01b0316634b820093866040518263ffffffff1660e01b815260040161292a9190614913565b602060405180830381600087803b15801561294457600080fd5b505af1158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614027565b506001016128d6565b8060608167ffffffffffffffff8111801561299f57600080fd5b506040519080825280602002602001820160405280156129d957816020015b6129c66136da565b8152602001906001900390816129be5790505b50905060005b82811015612a6b576040805160a081019091528060038152602001868684818110612a0657fe5b9050602002016020810190612a1b9190613ae1565b6001600160a01b0316815260200160018152602001876001600160a01b03168152602001876001600160a01b0316815250828281518110612a5857fe5b60209081029190910101526001016129df565b50612a74611689565b6001600160a01b0316630e8e3e84826040518263ffffffff1660e01b8152600401610f749190614b87565b6000612aaa83612730565b90506001600160a01b0382163014612729576001600160a01b0382163314612ae45760405162461bcd60e51b815260040161061590614dcd565b612729828583612b72565b610bfc8363a9059cbb60e01b8484604051602401612b0e929190614aa9565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152612f7a565b80612b7c57610bfc565b604080516001808252818301909252606091602080830190803683370190505090508281600081518110612bac57fe5b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526060918160200160208202803683370190505090508281600081518110612bf757fe5b6020026020010181815250506108e685838361301a565b606060006060846001600160a01b031684604051612c2c91906148c4565b6000604051808303816000865af19150503d8060008114612c69576040519150601f19603f3d011682016040523d82523d6000602084013e612c6e565b606091505b5091509150612c7d8282613172565b925050505b92915050565b60601c90565b60606000836003811115612c9e57fe5b1415612cb457612cad8261319c565b9050612c82565b6001836003811115612cc257fe5b1480612cd957506002836003811115612cd757fe5b145b80612cef57506003836003811115612ced57fe5b145b15612cfd57612cad8261319c565b60405162461bcd60e51b815260040161061590614ea9565b6000612d25838311156001612ec7565b50900390565b8015801590612dcf57506040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081526001600160a01b0384169063dd62ed3e90612d7c90309086906004016149a5565b60206040518083038186803b158015612d9457600080fd5b505afa158015612da8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dcc919061469d565b15155b15612df457612df48363095ea7b360e01b846000604051602401612b0e929190614a8d565b610bfc8363095ea7b360e01b8484604051602401612b0e929190614aa9565b90565b6001600160a01b03161590565b6060612e2e826131d9565b15612e3c57612cad82613208565b6000836003811115612e4a57fe5b1415612e5957612cad8261325b565b6001836003811115612e6757fe5b1415612e7657612cad826132a4565b6002836003811115612e8457fe5b1415612e9357612cad826132ea565b6003836003811115612ea157fe5b1415612cfd57612cad82613316565b600080612ebc83612f1c565b915081549050915091565b816120915761209181613349565b7fffff000000000000000000000000000000000000000000000000000000000000167fba100000000000000000000000000000000000000000000000000000000000001490565b60006001612f2983613376565b7fae1dc54057af8e8e5ce068cdd4383149c7efcb30e8fb95b592ee1594367fb509604051602001612f5b929190614905565b60408051808303601f1901815291905280516020909101200392915050565b60006060836001600160a01b031683604051612f9691906148c4565b6000604051808303816000865af19150503d8060008114612fd3576040519150601f19603f3d011682016040523d82523d6000602084013e612fd8565b606091505b50915091506000821415612ff0573d6000803e3d6000fd5b61048c8151600014806130125750818060200190518101906130129190614027565b6101a2612ec7565b6060825167ffffffffffffffff8111801561303457600080fd5b5060405190808252806020026020018201604052801561306e57816020015b61305b6136da565b8152602001906001900390816130535790505b50905060005b8351811015613106576040805160a08101909152806003815260200185838151811061309c57fe5b60200260200101516001600160a01b031681526020018483815181106130be57fe5b60200260200101518152602001866001600160a01b03168152602001306001600160a01b03168152508282815181106130f357fe5b6020908102919091010152600101613074565b5061310f611689565b6001600160a01b0316630e8e3e84826040518263ffffffff1660e01b815260040161313a9190614b87565b600060405180830381600087803b15801561315457600080fd5b505af1158015613168573d6000803e3d6000fd5b5050505050505050565b60608215613181575080612c82565b8151156131915781518083602001fd5b612c826101ae613349565b606060006131a983613399565b905060018160038111156131b957fe5b14156131d0576131c8836133af565b915050612751565b82915050612751565b600080825111801561274e575060ff8016828060200190518101906131fe91906146b5565b60ff161492915050565b6060600061321583613401565b9050613220816127fe565b156131d05761322e81612845565b905060ff81604051602001613244929190614fe1565b604051602081830303815290604052915050612751565b6060600061326883613417565b9050600081600281111561327857fe5b1415613287576131c88361342d565b600181600281111561329557fe5b14156131d0576131c883613490565b606060006132b183613417565b60028111156132bc57fe5b905060ff81166132d0576131c883826134cc565b60015b60ff168160ff1614156131d0576131c8838261352e565b606060006132f783613417565b600281111561330257fe5b905060ff81166131d0576131c883826134cc565b6060600061332383613417565b600281111561332e57fe5b905060ff8116613342576131c883826134cc565b60026132d3565b613373817f42414c0000000000000000000000000000000000000000000000000000000000613589565b50565b7dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1690565b60008180602001905181019061274e91906143cc565b60608060006133bd846135ea565b915091506133ca8261360d565b6133d457836128b2565b600182826040516020016133ea93929190614c92565b604051602081830303815290604052949350505050565b60008180602001905181019061272991906146d1565b60008180602001905181019061274e919061434d565b606060008061343b84613677565b91509150613448826127fe565b156134865761345682612845565b91506000828260405160200161346e93929190614c71565b60405160208183030381529060405292505050612751565b8392505050612751565b6060600061349d8361368e565b90506134a8816127fe565b156131d0576134b681612845565b9050600181604051602001613244929190614c5a565b60606000806134da85613677565b915091506134e7826127fe565b15613524576134f582612845565b915083828260405160200161350c93929190614ff4565b60405160208183030381529060405292505050612c82565b8492505050612c82565b6060600061353b8461368e565b9050613546816127fe565b156135805761355481612845565b90508281604051602001613569929190614fe1565b604051602081830303815290604052915050612c82565b83915050612c82565b62461bcd60e51b600090815260206004526007602452600a808404818106603090810160081b958390069590950190829004918206850160101b01602363ffffff0060e086901c160160181b0190930160c81b60445260e882901c90606490fd5b606060008280602001905181019061360291906143e8565b909590945092505050565b600080805b835181101561367057600084828151811061362957fe5b6020026020010151905061363c816127fe565b156136675761364a81612845565b85838151811061365657fe5b602002602001018181525050600192505b50600101613612565b5092915050565b600080828060200190518101906136029190614396565b6000818060200190518101906127299190614369565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805160a081019091528060008152600060208201819052604082018190526060820181905260809091015290565b8035612c82816150a0565b60008083601f840112613726578182fd5b50813567ffffffffffffffff81111561373d578182fd5b602083019150836020808302850101111561375757600080fd5b9250929050565b600082601f83011261376e578081fd5b813561378161377c82615036565b61500f565b8181529150602080830190848101818402860182018710156137a257600080fd5b60005b848110156137ca5781356137b8816150a0565b845292820192908201906001016137a5565b505050505092915050565b600082601f8301126137e5578081fd5b81356137f361377c82615036565b818152915060208083019084810160005b848110156137ca578135870160a080601f19838c0301121561382557600080fd5b61382e8161500f565b85830135815260408084013587830152606080850135828401526080915081850135818401525082840135925067ffffffffffffffff83111561387057600080fd5b61387e8c88858701016139a0565b90820152865250509282019290820190600101613804565b60008083601f8401126138a7578182fd5b50813567ffffffffffffffff8111156138be578182fd5b60208301915083602060408302850101111561375757600080fd5b600082601f8301126138e9578081fd5b81356138f761377c82615036565b81815291506020808301908481018184028601820187101561391857600080fd5b60005b848110156137ca5781358452928201929082019060010161391b565b600082601f830112613947578081fd5b815161395561377c82615036565b81815291506020808301908481018184028601820187101561397657600080fd5b60005b848110156137ca57815184529282019290820190600101613979565b8035612c82816150b5565b600082601f8301126139b0578081fd5b813567ffffffffffffffff8111156139c6578182fd5b6139d96020601f19601f8401160161500f565b91508082528360208285010111156139f057600080fd5b8060208401602084013760009082016020015292915050565b8035612c82816150d0565b803560028110612c8257600080fd5b600060808284031215613a34578081fd5b613a3e608061500f565b9050813567ffffffffffffffff80821115613a5857600080fd5b613a648583860161375e565b83526020840135915080821115613a7a57600080fd5b613a86858386016138d9565b60208401526040840135915080821115613a9f57600080fd5b50613aac848285016139a0565b604083015250613abf8360608401613995565b606082015292915050565b600060808284031215613adb578081fd5b50919050565b600060208284031215613af2578081fd5b8135612729816150a0565b600060208284031215613b0e578081fd5b8151612729816150a0565b60008060008060008060c08789031215613b31578182fd5b8635613b3c816150a0565b95506020870135613b4c816150a0565b94506040870135613b5c816150a0565b959894975094956060810135955060808101359460a0909101359350915050565b60008060008060808587031215613b92578182fd5b8435613b9d816150a0565b93506020850135613bad816150a0565b93969395505050506040820135916060013590565b600080600060408486031215613bd6578081fd5b8335613be1816150a0565b9250602084013567ffffffffffffffff811115613bfc578182fd5b613c0886828701613715565b9497909650939450505050565b60008060008060608587031215613c2a578182fd5b8435613c35816150a0565b93506020850135613c45816150b5565b9250604085013567ffffffffffffffff80821115613c61578384fd5b818701915087601f830112613c74578384fd5b813581811115613c82578485fd5b886020828501011115613c93578485fd5b95989497505060200194505050565b600080600080600060a08688031215613cb9578283fd5b8535613cc4816150a0565b94506020860135613cd4816150a0565b94979496505050506040830135926060810135926080909101359150565b600080600060608486031215613d06578081fd5b8335613d11816150a0565b95602085013595506040909401359392505050565b60008060008060808587031215613d3b578182fd5b8435613d46816150a0565b966020860135965060408601359560600135945092505050565b600080600060408486031215613d74578081fd5b833567ffffffffffffffff811115613d8a578182fd5b613d9686828701613715565b909790965060209590950135949350505050565b60008060208385031215613dbc578182fd5b823567ffffffffffffffff811115613dd2578283fd5b613dde85828601613715565b90969095509350505050565b60006020808385031215613dfc578182fd5b825167ffffffffffffffff811115613e12578283fd5b8301601f81018513613e22578283fd5b8051613e3061377c82615036565b8181528381019083850185840285018601891015613e4c578687fd5b8694505b83851015613e6e578051835260019490940193918501918501613e50565b50979650505050505050565b60008060008060608587031215613e8f578182fd5b843567ffffffffffffffff80821115613ea6578384fd5b818701915087601f830112613eb9578384fd5b8135613ec761377c82615036565b808282526020808301925080860160a08d838288028a01011115613ee957898afd5b8997505b85881015613f6c5780828f031215613f0357898afd5b613f0c8161500f565b613f168f84613a09565b8152613f248f85850161370a565b8482015260408301356040820152613f3f8f6060850161370a565b6060820152613f518f6080850161370a565b60808201528552600197909701969382019390810190613eed565b509199508a013597505050604088013592505080821115613f8b578384fd5b50613f9887828801613896565b95989497509550505050565b600060208284031215613fb5578081fd5b815167ffffffffffffffff811115613fcb578182fd5b6128b284828501613937565b60008060408385031215613fe9578182fd5b823567ffffffffffffffff811115613fff578283fd5b61400b858286016138d9565b925050602083013561401c816150a0565b809150509250929050565b600060208284031215614038578081fd5b8151612729816150b5565b60008060008060008060c0878903121561405b578384fd5b8635614066816150b5565b95506020870135614076816150a0565b945060408701359350606087013561408d816150dd565b9598949750929560808101359460a0909101359350915050565b600080600080600080600060c0888a0312156140c1578485fd5b8735965060208801356140d3816150d0565b955060408801356140e3816150a0565b945060608801356140f3816150a0565b9350608088013567ffffffffffffffff8082111561410f578283fd5b61411b8b838c01613a23565b945060a08a0135915080821115614130578283fd5b5061413d8a828b01613896565b989b979a50959850939692959293505050565b600080600080600080600060e0888a03121561416a578081fd5b87359650602088013561417c816150d0565b9550604088013561418c816150a0565b9450606088013561419c816150a0565b9350608088013567ffffffffffffffff8111156141b7578182fd5b6141c38a828b01613a23565b93505060a0880135915060c0880135905092959891949750929550565b600080600080600080600080610100898b0312156141fc578182fd5b8835614207816150a0565b97506020890135614217816150a0565b965060408901359550606089013594506080890135614235816150b5565b935060a0890135614245816150dd565b979a969950949793969295929450505060c08201359160e0013590565b600080600080600080600060e0888a03121561427c578081fd5b8735614287816150a0565b96506020880135614297816150a0565b9550604088013594506060880135935060808801356142b5816150dd565b9699959850939692959460a0840135945060c09093013592915050565b600080604083850312156142e4578182fd5b82356142ef816150a0565b946020939093013593505050565b60008060008060808587031215614312578182fd5b843561431d816150a0565b9350602085013561432d816150a0565b9250604085013561433d816150a0565b9396929550929360600135925050565b60006020828403121561435e578081fd5b8151612729816150c3565b6000806040838503121561437b578182fd5b8251614386816150c3565b6020939093015192949293505050565b6000806000606084860312156143aa578081fd5b83516143b5816150c3565b602085015160409095015190969495509392505050565b6000602082840312156143dd578081fd5b8151612729816150d0565b6000806000606084860312156143fc578081fd5b8351614407816150d0565b602085015190935067ffffffffffffffff811115614423578182fd5b61442f86828701613937565b925050604084015190509250925092565b60008060008060008060008060008060006101608c8e031215614461578485fd5b61446b8d8d613a14565b9a5067ffffffffffffffff8060208e01351115614486578586fd5b6144968e60208f01358f016137d5565b9a508060408e013511156144a8578586fd5b6144b88e60408f01358f01613715565b909a5098506144ca8e60608f01613aca565b97508060e08e013511156144dc578586fd5b6144ec8e60e08f01358f01613715565b90975095506101008d013594506101208d013593506101408d0135811015614512578283fd5b506145248d6101408e01358e01613896565b81935080925050509295989b509295989b9093969950565b600060c0828403121561454d578081fd5b61455760c061500f565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a08201528091505092915050565b60008060008060008061012087890312156145b0578384fd5b863567ffffffffffffffff808211156145c7578586fd5b9088019060c0828b0312156145da578586fd5b6145e460c061500f565b823581526145f58b60208501613a14565b60208201526040830135614608816150a0565b604082015261461a8b6060850161370a565b60608201526080830135608082015260a08301358281111561463a578788fd5b6146468c8286016139a0565b60a08301525080985050505061465f8860208901613aca565b959895975050505060a08401359360c08101359360e08201359350610100909101359150565b600060208284031215614696578081fd5b5035919050565b6000602082840312156146ae578081fd5b5051919050565b6000602082840312156146c6578081fd5b8151612729816150dd565b600080604083850312156146e3578182fd5b8251614386816150dd565b6001600160a01b03169052565b60008284526020808501945082825b8581101561473857813561471d816150a0565b6001600160a01b03168752958201959082019060010161470a565b509495945050505050565b60008284526020808501945082825b8581101561473857813587529582019590820190600101614752565b6000815180845260208085019450808401835b8381101561473857815187529582019590820190600101614781565b15159052565b600081518084526147bb816020860160208601615056565b601f01601f19169290920160200192915050565b8051608080845281519084018190526000916020919082019060a0860190845b818110156148145783516001600160a01b0316835292840192918401916001016147ef565b50508285015191508581038387015261482d818361476e565b925050506040830151848203604086015261484882826147a3565b915050606083015161485d606086018261479d565b509392505050565b8035614870816150a0565b6001600160a01b03908116835260208201359061488c826150b5565b90151560208401526040820135906148a3826150a0565b16604083015260608101356148b7816150b5565b8015156060840152505050565b600082516148d6818460208701615056565b9190910192915050565b600084516148f2818460208901615056565b8201838582379092019182525092915050565b918252602082015260400190565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6000604082016001600160a01b03808616845260206040818601528286518085526060870191508288019450855b81811015614997578551851683529483019491830191600101614979565b509098975050505050505050565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039889168152969097166020870152604086019490945260608501929092521515608084015260ff1660a083015260c082015260e08101919091526101000190565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6001600160a01b0397881681529515156020870152939095166040850152606084019190915260ff16608083015260a082019290925260c081019190915260e00190565b6001600160a01b0392909216825260ff16602082015260400190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039390931683526020830191909152604082015260600190565b6040808252810183905260008460608301825b86811015614b265760208335614b0b816150a0565b6001600160a01b031683529283019290910190600101614af6565b5080925050506001600160a01b0383166020830152949350505050565b6020808252825182820181905260009190848201906040850190845b81811015614b7b57835183529284019291840191600101614b5f565b50909695505050505050565b602080825282518282018190526000919060409081850190868401855b82811015614c105781518051614bb98161508c565b8552808701516001600160a01b0316878601528581015186860152606080820151614be6828801826146ee565b505060809081015190614bfb868201836146ee565b505060a0939093019290850190600101614ba4565b5091979650505050505050565b901515815260200190565b60008582526001600160a01b03808616602084015280851660408401525060806060830152610ae760808301846147cf565b60408101614c6784615082565b9281526020015290565b60608101614c7e85615082565b938152602081019290925260409091015290565b6000614c9d8561508c565b84825260606020830152614cb4606083018561476e565b9050826040830152949350505050565b6000610120808301614cd58c615096565b8b84526020808501929092528a5190819052610140808501928281028601909101918c8201855b82811015614d7c578785037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec00186528151805186528481015185870152604080820151908701526060808201519087015260809081015160a091870182905290614d68818801836147a3565b978601979650505090830190600101614cfc565b505050508381036040850152614d93818a8c6146fb565b915050614da36060840188614865565b82810360e0840152614db6818688614743565b915050826101008301529998505050505050505050565b60208082526010908201527f496e636f72726563742073656e64657200000000000000000000000000000000604082015260600190565b60208082526017908201527f496e636f727265637420746f6b656e20666f7220706964000000000000000000604082015260600190565b60208082526019908201527f53656e646572206e6f74206f776e6572206f662072656c696300000000000000604082015260600190565b6020808252601f908201527f52656c617965722063616e206f6e6c7920617070726f766520697473656c6600604082015260600190565b60208082526013908201527f554e48414e444c45445f504f4f4c5f4b494e4400000000000000000000000000604082015260600190565b60208082526019908201527f696e76616c696420636861696e6564207265666572656e636500000000000000604082015260600190565b600060e08252855160e08301526020860151614f3281615096565b61010083015260408601516001600160a01b03908116610120840152606087015116610140830152608086015161016083015260a086015160c0610180840152614f806101a08401826147a3565b915050614f906020830186614865565b60a082019390935260c0015292915050565b90815260200190565b9182526001600160a01b0316602082015260400190565b92835260208301919091526001600160a01b0316604082015260600190565b60ff929092168252602082015260400190565b60ff9390931683526020830191909152604082015260600190565b60405181810167ffffffffffffffff8111828210171561502e57600080fd5b604052919050565b600067ffffffffffffffff82111561504c578081fd5b5060209081020190565b60005b83811015615071578181015183820152602001615059565b8381111561048c5750506000910152565b6003811061337357fe5b6004811061337357fe5b6002811061337357fe5b6001600160a01b038116811461337357600080fd5b801515811461337357600080fd5b6003811061337357600080fd5b6004811061337357600080fd5b60ff8116811461337357600080fdfea26469706673582212201116b3dc300af81974d4880ecb3f740ae6e3b2bae1c2987e4b535ba4c4a7a69464736f6c63430007010033

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

000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684000000000000000000000000000000000000000000000000000000000000004e7b226e616d65223a22426174636852656c61796572222c2276657273696f6e223a2236222c226465706c6f796d656e74223a2232303233313033312d62617463682d72656c617965722d7636227d000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : vault (address): 0xBA12222222228d8Ba445958a75a0704d566BF2C8
Arg [1] : wstETH (address): 0x0000000000000000000000000000000000000000
Arg [2] : minter (address): 0x0000000000000000000000000000000000000000
Arg [3] : canCallUserCheckpoint (bool): True
Arg [4] : version (string): {"name":"BatchRelayer","version":"6","deployment":"20231031-batch-relayer-v6"}
Arg [5] : reliquary (address): 0x973670ce19594F857A7cD85EE834c7a74a941684

-----Encoded View---------------
10 Constructor Arguments found :
Arg [0] : 000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [4] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [5] : 000000000000000000000000973670ce19594f857a7cd85ee834c7a74a941684
Arg [6] : 000000000000000000000000000000000000000000000000000000000000004e
Arg [7] : 7b226e616d65223a22426174636852656c61796572222c2276657273696f6e22
Arg [8] : 3a2236222c226465706c6f796d656e74223a2232303233313033312d62617463
Arg [9] : 682d72656c617965722d7636227d000000000000000000000000000000000000


Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

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

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