ETH Price: $1,876.45 (-3.70%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Advanced mode:
Parent Transaction Hash Method Block
From
To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ValidlyFactory

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
cancun EvmVersion
File 1 of 24 : ValidlyFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IProtocolFactory} from "@valantis-core/protocol-factory/interfaces/IProtocolFactory.sol";
import {SovereignPoolConstructorArgs} from "@valantis-core/pools/structs/SovereignPoolStructs.sol";
import {ISovereignPool} from "@valantis-core/pools/interfaces/ISovereignPool.sol";

import {Validly} from "./Validly.sol";
import {IValidlyFactory} from "./interfaces/IValidlyFactory.sol";

contract ValidlyFactory is IValidlyFactory {
    using SafeERC20 for IERC20;

    /**
     *  ERRORS
     */
    error ValidlyFactory__onlyProtocolManager();
    error ValidlyFactory__claimTokens_invalidRecipient();
    error ValidlyFactory__claimTokens_invalidToken();
    error ValidlyFactory__constructor_invalidFeeBips();
    error ValidlyFactory__createPair_alreadyDeployed();
    error ValidlyFactory__setPoolManagerFees_unauthorized();

    /**
     *  IMMUTABLES
     */

    /**
     * @notice The protocol factory contract used for deploying pools.
     * @dev This is set in the constructor and cannot be changed.
     */
    IProtocolFactory public immutable protocolFactory;

    /**
     * @notice The fee percentage for the Validly pool.
     * @dev This is set in the constructor and cannot be changed.
     * @dev If new pool fee tiers are required, one can deploy new Validly factories.
     */
    uint256 public immutable feeBips;

    /**
     *  STORAGE
     */

    /**
     * @notice Mapping from pool keys to pool addresses.
     */
    mapping(bytes32 key => address pool) public pools;

    /**
     *  CONSTRUCTOR
     */
    constructor(address _protocolFactory, uint256 _feeBips) {
        protocolFactory = IProtocolFactory(_protocolFactory);

        if (_feeBips == 0 || _feeBips > 10000) {
            revert ValidlyFactory__constructor_invalidFeeBips();
        }

        feeBips = _feeBips;
    }

    /**
     *
     *  MODIFIERS
     *
     */
    modifier onlyProtocolManager() {
        if (msg.sender != protocolFactory.protocolManager()) {
            revert ValidlyFactory__onlyProtocolManager();
        }
        _;
    }

    /**
     *  EXTERNAL FUNCTIONS
     */

    /**
     * @notice Deploys a new Validly pool for a given token pair.
     * @dev Tokens are sorted internally to ensure consistent pool keys.
     * @param _token0 The address of the first token in the pair.
     * @param _token1 The address of the second token in the pair.
     * @param _isStable Boolean indicating if the pool should be stable or volatile.
     * @custom:error ValidlyFactory__createPair_alreadyDeployed Thrown if a pool for the given token pair and stability type already exists.
     * @custom:error ValidlyFactory__createPair_failedDeployment Thrown if the Validly contract deployment fails.
     * @custom:error ValidlyFactory__createPair_invalidFeeBips Thrown if the feeBips is not between 0 and 10000.
     */
    function createPair(address _token0, address _token1, bool _isStable) external returns (address) {
        (_token0, _token1) = _token0 < _token1 ? (_token0, _token1) : (_token1, _token0);

        bytes32 poolKey = _poolKey(_token0, _token1, _isStable);

        if (pools[poolKey] != address(0)) {
            revert ValidlyFactory__createPair_alreadyDeployed();
        }

        SovereignPoolConstructorArgs memory args = SovereignPoolConstructorArgs(
            _token0,
            _token1,
            address(protocolFactory),
            address(this),
            address(0),
            address(0),
            false,
            false,
            0,
            0,
            feeBips
        );

        address pool = protocolFactory.deploySovereignPool(args);

        Validly validly = new Validly{salt: poolKey}(pool, _isStable);

        ISovereignPool(pool).setALM(address(validly));

        pools[poolKey] = pool;

        emit PoolCreated(pool, _token0, _token1, _isStable);

        return address(validly);
    }

    /**
     * @notice Creates a new Validly pool, mostly for rebase tokens, which is not indexed in pools mapping.
     * @dev This function is used to create a pool given the SovereignPool constructor arguments.
     * @param _args The constructor arguments for the SovereignPool.
     * @param _isStable Boolean indicating if the pool should be stable or volatile.
     * @custom:error ValidlyFactory__createPool_failedDeployment Thrown if the Validly contract deployment fails.
     */
    function createPool(SovereignPoolConstructorArgs memory _args, bool _isStable) external returns (address validly) {
        _args.poolManager = address(this);
        // This factory does not support Sovereign Pools with Verifier Modules
        _args.verifierModule = address(0);

        address pool = protocolFactory.deploySovereignPool(_args);

        validly = address(new Validly(pool, _isStable));

        ISovereignPool(pool).setALM(address(validly));

        emit PoolCreated(pool, _args.token0, _args.token1, _isStable);
    }

    /**
     * @notice Sets the pool manager fees for a given pool.
     * @dev This function is used to set the pool manager fees for a given pool.
     * @param _pool The address of the pool to set the pool manager fees for.
     * @param _feeBips The fee percentage for the pool manager.
     * @custom:error ValidlyFactory__setPoolManagerFees_unauthorized Thrown if the caller is not the protocol manager.
     */
    function setPoolManagerFeeBips(address _pool, uint256 _feeBips) external onlyProtocolManager {
        ISovereignPool(_pool).setPoolManagerFeeBips(_feeBips);

        emit PoolManagerFeeBipsSet(_pool, _feeBips);
    }

    /**
     * @notice Claims rebase token fees accumulated in this contract.
     * @dev By design of Sovereign Pools, manager fees for rebase tokens
     *      get transferred on every swap to its manager (this contract).
     * @param _token The address of the token to claim.
     * @param _recipient The address of the recipient.
     */
    function claimTokens(address _token, address _recipient) external onlyProtocolManager {
        if (_token == address(0)) {
            revert ValidlyFactory__claimTokens_invalidToken();
        }
        if (_recipient == address(0)) {
            revert ValidlyFactory__claimTokens_invalidRecipient();
        }

        IERC20 token = IERC20(_token);
        uint256 balance = token.balanceOf(address(this));

        if (balance > 0) {
            token.safeTransfer(_recipient, balance);

            emit TokenClaimed(_token, _recipient, balance);
        }
    }

    /**
     * @notice Claims the pool manager fees for a given pool.
     * @dev This function is used to claim the pool manager fees for a given pool.
     * @param _pool The address of the pool to claim the pool manager fees for.
     */
    function claimFees(address _pool) external {
        // It marks all fees as protocol fees to be used by gauge
        ISovereignPool(_pool).claimPoolManagerFees(10_000, 10_000);

        emit FeesClaimed(_pool);
    }

    /**
     *  PRIVATE FUNCTIONS
     */
    function _poolKey(address token0, address token1, bool isStable) private pure returns (bytes32 key) {
        key = keccak256(abi.encode(token0, token1, isStable));
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

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

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

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

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

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

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

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

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

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

File 4 of 24 : IProtocolFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { SovereignPoolConstructorArgs } from '../../pools/structs/SovereignPoolStructs.sol';

interface IProtocolFactory {
    event GovernanceTokenSet(address governanceToken);
    event ProtocolManagerSet(address protocolManager);
    event UniversalPoolFactorySet(address universalPoolFactory);
    event SovereignPoolFactorySet(address sovereignPoolFactory);
    event AuctionControllerSet(address auctionController);
    event EmissionsControllerSet(address emissionsController);
    event UniversalGaugeFactorySet(address universalGaugeFactory);
    event SovereignGaugeFactorySet(address sovereignGaugeFactory);

    event UniversalALMDeployed(address alm, address pool, address factory);
    event SovereignALMDeployed(address alm, address pool, address factory);
    event SwapFeeModuleDeployed(address swapFeeModule, address pool, address factory);
    event UniversalOracleDeployed(address universalOracle, address pool, address factory);
    event SovereignOracleDeployed(address sovereignOracle, address pool, address factory);
    event UniversalPoolDeployed(address indexed token0, address indexed token1, address pool);
    event SovereignPoolDeployed(address indexed token0, address indexed token1, address pool);
    event UniversalGaugeDeployed(address gauge, address pool, address manager);
    event SovereignGaugeDeployed(address gauge, address pool, address manager);

    event UniversalALMFactoryAdded(address factory);
    event UniversalALMFactoryRemoved(address factory);
    event SovereignALMFactoryAdded(address factory);
    event SovereignALMFactoryRemoved(address factory);
    event SwapFeeModuleFactoryAdded(address factory);
    event SwapFeeModuleFactoryRemoved(address factory);
    event UniversalOracleFactoryAdded(address factory);
    event UniversalOracleFactoryRemoved(address factory);
    event SovereignOracleFactoryAdded(address factory);
    event SovereignOracleFactoryRemoved(address factory);

    function protocolDeployer() external view returns (address);

    function almFactories(address _almPosition) external view returns (address);

    function swapFeeModules(address _pool) external view returns (address);

    function universalOracleModules(address _pool) external view returns (address);

    function sovereignOracleModules(address _pool) external view returns (address);

    function auctionController() external view returns (address);

    function emissionsController() external view returns (address);

    function almNonce() external view returns (uint256);

    function swapFeeModuleNonce() external view returns (uint256);

    function universalOracleModuleNonce() external view returns (uint256);

    function sovereignOracleModuleNonce() external view returns (uint256);

    function protocolManager() external view returns (address);

    function governanceToken() external view returns (address);

    function universalPoolFactory() external view returns (address);

    function sovereignPoolFactory() external view returns (address);

    function universalGaugeFactory() external view returns (address);

    function sovereignGaugeFactory() external view returns (address);

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

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

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

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

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

    function gaugeByPool(address _pool) external view returns (address);

    function poolByGauge(address _gauge) external view returns (address);

    function isValidUniversalPool(address _pool) external view returns (bool);

    function isValidSovereignPool(address _pool) external view returns (bool);

    function isValidUniversalALMFactory(address _almFactory) external view returns (bool);

    function isValidSovereignALMFactory(address _almFactory) external view returns (bool);

    function isValidSwapFeeModuleFactory(address _swapFeeModuleFactory) external view returns (bool);

    function isValidUniversalOracleModuleFactory(address _universalOracleModuleFactory) external view returns (bool);

    function isValidSovereignOracleModuleFactory(address _sovereignOracleModuleFactory) external view returns (bool);

    function isValidUniversalALMPosition(address _almPosition) external view returns (bool);

    function isValidSovereignALMPosition(address _almPosition) external view returns (bool);

    function isValidSwapFeeModule(address _swapFeeModule) external view returns (bool);

    function isValidUniversalOracleModule(address _universalOracleModule) external view returns (bool);

    function isValidSovereignOracleModule(address _sovereignOracleModule) external view returns (bool);

    function setGovernanceToken(address _governanceToken) external;

    function setProtocolManager(address _protocolManager) external;

    function setUniversalPoolFactory(address _universalPoolFactory) external;

    function setSovereignPoolFactory(address _sovereignPoolFactory) external;

    function setAuctionController(address _auctionController) external;

    function setEmissionsController(address _emissionsController) external;

    function setSovereignGaugeFactory(address _poolGaugeFactory) external;

    function setUniversalGaugeFactory(address _universalGaugeFactory) external;

    function deployUniversalGauge(address _pool, address _manager) external returns (address gauge);

    function deploySovereignGauge(address _pool, address _manager) external returns (address gauge);

    function deployALMPositionForUniversalPool(
        address _pool,
        address _almFactory,
        bytes calldata _constructorArgs
    ) external returns (address alm);

    function deployALMPositionForSovereignPool(
        address _pool,
        address _almFactory,
        bytes calldata _constructorArgs
    ) external returns (address alm);

    function deploySwapFeeModuleForPool(
        address _pool,
        address _swapFeeModuleFactory,
        bytes calldata _constructorArgs
    ) external returns (address swapFeeModule);

    function deployUniversalPool(
        address _token0,
        address _token1,
        address _poolManager,
        uint256 _deploySwapFeeBips
    ) external returns (address pool);

    function deploySovereignPool(SovereignPoolConstructorArgs memory _args) external returns (address pool);

    function deployUniversalOracleForPool(
        address _pool,
        address _universalOracleModuleFactory,
        bytes calldata _constructorArgs
    ) external returns (address universalOracleModule);

    function deploySovereignOracleForPool(
        address _pool,
        address _sovereignOracleModuleFactory,
        bytes calldata _constructorArgs
    ) external returns (address sovereignOracleModule);

    function addUniversalALMFactory(address _almFactory) external;

    function addSovereignALMFactory(address _almFactory) external;

    function addSwapFeeModuleFactory(address _swapFeeModuleFactory) external;

    function addUniversalOracleModuleFactory(address _universalOracleModuleFactory) external;

    function addSovereignOracleModuleFactory(address _sovereignOracleModuleFactory) external;

    function removeUniversalALMFactory(address _almFactory) external;

    function removeSovereignALMFactory(address _almFactory) external;

    function removeSwapFeeModuleFactory(address _swapFeeModuleFactory) external;

    function removeUniversalOracleModuleFactory(address _universalOracleModuleFactory) external;

    function removeSovereignOracleModuleFactory(address _sovereignOracleModuleFactory) external;
}

File 5 of 24 : SovereignPoolStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { IERC20 } from '../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol';

import { ISwapFeeModule } from '../../swap-fee-modules/interfaces/ISwapFeeModule.sol';

struct SovereignPoolConstructorArgs {
    address token0;
    address token1;
    address protocolFactory;
    address poolManager;
    address sovereignVault;
    address verifierModule;
    bool isToken0Rebase;
    bool isToken1Rebase;
    uint256 token0AbsErrorTolerance;
    uint256 token1AbsErrorTolerance;
    uint256 defaultSwapFeeBips;
}

struct SovereignPoolSwapContextData {
    bytes externalContext;
    bytes verifierContext;
    bytes swapCallbackContext;
    bytes swapFeeModuleContext;
}

struct SwapCache {
    ISwapFeeModule swapFeeModule;
    IERC20 tokenInPool;
    IERC20 tokenOutPool;
    uint256 amountInWithoutFee;
}

struct SovereignPoolSwapParams {
    bool isSwapCallback;
    bool isZeroToOne;
    uint256 amountIn;
    uint256 amountOutMin;
    uint256 deadline;
    address recipient;
    address swapTokenOut;
    SovereignPoolSwapContextData swapContext;
}

File 6 of 24 : ISovereignPool.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { IValantisPool } from '../interfaces/IValantisPool.sol';
import { PoolLocks } from '../structs/ReentrancyGuardStructs.sol';
import { SovereignPoolSwapContextData, SovereignPoolSwapParams } from '../structs/SovereignPoolStructs.sol';

interface ISovereignPool is IValantisPool {
    event SwapFeeModuleSet(address swapFeeModule);
    event ALMSet(address alm);
    event GaugeSet(address gauge);
    event PoolManagerSet(address poolManager);
    event PoolManagerFeeSet(uint256 poolManagerFeeBips);
    event SovereignOracleSet(address sovereignOracle);
    event PoolManagerFeesClaimed(uint256 amount0, uint256 amount1);
    event DepositLiquidity(uint256 amount0, uint256 amount1);
    event WithdrawLiquidity(address indexed recipient, uint256 amount0, uint256 amount1);
    event Swap(address indexed sender, bool isZeroToOne, uint256 amountIn, uint256 fee, uint256 amountOut);

    function getTokens() external view returns (address[] memory tokens);

    function sovereignVault() external view returns (address);

    function protocolFactory() external view returns (address);

    function gauge() external view returns (address);

    function poolManager() external view returns (address);

    function sovereignOracleModule() external view returns (address);

    function swapFeeModule() external view returns (address);

    function verifierModule() external view returns (address);

    function isLocked() external view returns (bool);

    function isRebaseTokenPool() external view returns (bool);

    function poolManagerFeeBips() external view returns (uint256);

    function defaultSwapFeeBips() external view returns (uint256);

    function swapFeeModuleUpdateTimestamp() external view returns (uint256);

    function alm() external view returns (address);

    function getPoolManagerFees() external view returns (uint256 poolManagerFee0, uint256 poolManagerFee1);

    function getReserves() external view returns (uint256 reserve0, uint256 reserve1);

    function setPoolManager(address _manager) external;

    function setGauge(address _gauge) external;

    function setPoolManagerFeeBips(uint256 _poolManagerFeeBips) external;

    function setSovereignOracle(address sovereignOracle) external;

    function setSwapFeeModule(address _swapFeeModule) external;

    function setALM(address _alm) external;

    function swap(SovereignPoolSwapParams calldata _swapParams) external returns (uint256, uint256);

    function depositLiquidity(
        uint256 _amount0,
        uint256 _amount1,
        address _sender,
        bytes calldata _verificationContext,
        bytes calldata _depositData
    ) external returns (uint256 amount0Deposited, uint256 amount1Deposited);

    function withdrawLiquidity(
        uint256 _amount0,
        uint256 _amount1,
        address _sender,
        address _recipient,
        bytes calldata _verificationContext
    ) external;
}

File 7 of 24 : Validly.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {ALMLiquidityQuoteInput, ALMLiquidityQuote} from "@valantis-core/ALM/structs/SovereignALMStructs.sol";
import {ISovereignPool} from "@valantis-core/pools/interfaces/ISovereignPool.sol";

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

/**
 * @title Validly Liquidity Module.
 * @dev UniswapV2 style constant product and Solidly's stable invariant,
 *      implemented as a Valantis Sovereign Liquidity Module.
 */
contract Validly is IValidly, ERC20, ReentrancyGuard {
    using SafeERC20 for IERC20Metadata;

    /**
     *
     *  ERRORS
     *
     */
    error Validly__deadlineExpired();
    error Validly__onlyPool();
    error Validly__constructor_customSovereignVaultNotAllowed();
    error Validly__constructor_invalidPool();
    error Validly__deposit_insufficientToken0Deposited();
    error Validly__deposit_insufficientToken1Deposited();
    error Validly__deposit_lessThanMinShares();
    error Validly__deposit_zeroShares();
    error Validly__getLiquidityQuote_feeInBipsZero();
    error Validly__onSwapCallback_invariantViolated();
    error Validly__withdraw_AmountZero();
    error Validly__withdraw_insufficientToken0Withdrawn();
    error Validly__withdraw_insufficientToken1Withdrawn();
    error Validly__withdraw_zeroShares();
    error Validly__withdraw_invalidRecipient();
    error Validly___get_y_notConverged();

    /**
     *
     *  CONSTANTS
     *
     */
    uint256 public constant MINIMUM_LIQUIDITY = 1000;

    bytes32 public constant INVARIANT_CACHE_SLOT = keccak256("validly.invariant");

    /**
     *
     *  IMMUTABLES
     *
     */

    /**
     * @dev SovereignPool is both the entry point contract for swaps (via `swap` function),
     *      and the contract in which token0 and token1 balances should be stored.
     */
    ISovereignPool public immutable pool;

    /**
     * @dev Boolean indicating if the pool is stable or volatile.
     */
    bool public immutable isStable;

    /**
     * @dev Decimals of token0.
     */
    uint256 public immutable decimals0;

    /**
     * @dev Decimals of token1.
     */
    uint256 public immutable decimals1;

    /**
     *
     *  CONSTRUCTOR
     *
     */
    constructor(address _pool, bool _isStable) ERC20("Validly LP Token", "VAL-LP") {
        if (_pool == address(0)) revert Validly__constructor_invalidPool();

        pool = ISovereignPool(_pool);

        if (pool.sovereignVault() != _pool) {
            revert Validly__constructor_customSovereignVaultNotAllowed();
        }

        isStable = _isStable;

        decimals0 = 10 ** IERC20Metadata(pool.token0()).decimals();
        decimals1 = 10 ** IERC20Metadata(pool.token1()).decimals();
    }

    /**
     *
     *  MODIFIERS
     *
     */
    modifier onlyPool() {
        if (msg.sender != address(pool)) {
            revert Validly__onlyPool();
        }
        _;
    }

    modifier ensureDeadline(uint256 deadline) {
        _checkDeadline(deadline);
        _;
    }

    /**
     *
     *  EXTERNAL FUNCTIONS
     *
     */

    /**
     * @notice Deposit liquidity into `pool` and mint LP tokens.
     * @param _amount0 Amount of token0 deposited.
     * @param _amount1 Amount of token1 deposited.
     * @param _minShares Minimum amount of shares to mint.
     * @param _deadline Block timestamp after which this call reverts.
     * @param _recipient Address to mint LP tokens for.
     * @param _verificationContext Bytes encoded payload, in case `pool` has a Verifier Module.
     * @return shares Amount of shares minted.
     */
    function deposit(
        uint256 _amount0,
        uint256 _amount1,
        uint256 _minShares,
        uint256 _deadline,
        address _recipient,
        bytes calldata _verificationContext
    )
        external
        override
        ensureDeadline(_deadline)
        nonReentrant
        returns (uint256 shares, uint256 amount0, uint256 amount1)
    {
        uint256 totalSupplyCache = totalSupply();
        if (totalSupplyCache == 0) {
            // Minimum token amounts taken as amounts during first deposit
            amount0 = _amount0;
            amount1 = _amount1;

            _mint(address(1), MINIMUM_LIQUIDITY);

            // _shares param is ignored during first deposit
            shares = Math.sqrt(amount0 * amount1) - MINIMUM_LIQUIDITY;
        } else {
            (uint256 reserve0, uint256 reserve1) = pool.getReserves();

            uint256 shares0 = Math.mulDiv(_amount0, totalSupplyCache, reserve0);
            uint256 shares1 = Math.mulDiv(_amount1, totalSupplyCache, reserve1);
            // Normal deposits are made using `onDepositLiquidityCallback`
            if (shares0 < shares1) {
                shares = shares0;
                amount1 = Math.mulDiv(reserve1, shares, totalSupplyCache, Math.Rounding.Ceil);
                amount0 = _amount0;
            } else {
                shares = shares1;
                amount0 = Math.mulDiv(reserve0, shares, totalSupplyCache, Math.Rounding.Ceil);
                amount1 = _amount1;
            }

            // This is a sanity check to ensure that the amounts are not over the amounts specified.
            // This can occur due to rounding errors in mulDiv ceiling.
            if (amount0 > _amount0) {
                revert Validly__deposit_insufficientToken0Deposited();
            }
            if (amount1 > _amount1) {
                revert Validly__deposit_insufficientToken1Deposited();
            }
        }

        if (shares < _minShares) revert Validly__deposit_lessThanMinShares();

        if (shares == 0) revert Validly__deposit_zeroShares();

        _mint(_recipient, shares);

        (amount0, amount1) =
            pool.depositLiquidity(amount0, amount1, msg.sender, _verificationContext, abi.encode(msg.sender));
    }

    /**
     * @notice Withdraw liquidity from `pool` and burn LP tokens.
     * @param _shares Amount of LP tokens to burn.
     * @param _amount0Min Minimum amount of token0 required for `_recipient`.
     * @param _amount1Min Minimum amount of token1 required for `_recipient`.
     * @param _deadline Block timestamp after which this call reverts.
     * @param _recipient Address to receive token0 and token1 amounts.
     * @param _verificationContext Bytes encoded payload, in case `pool` has a Verifier Module.
     * @return amount0 Amount of token0 withdrawn. WARNING: Potentially innacurate in case token0 is rebase.
     * @return amount1 Amount of token1 withdrawn. WARNING: Potentially innacurate in case token1 is rebase.
     */
    function withdraw(
        uint256 _shares,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint256 _deadline,
        address _recipient,
        bytes calldata _verificationContext
    ) external override ensureDeadline(_deadline) nonReentrant returns (uint256 amount0, uint256 amount1) {
        if (_shares == 0) revert Validly__withdraw_zeroShares();

        if (_recipient == address(0)) {
            revert Validly__withdraw_invalidRecipient();
        }

        (uint256 reserve0, uint256 reserve1) = pool.getReserves();

        uint256 totalSupplyCache = totalSupply();
        amount0 = Math.mulDiv(reserve0, _shares, totalSupplyCache);
        amount1 = Math.mulDiv(reserve1, _shares, totalSupplyCache);

        if (amount0 == 0 || amount1 == 0) revert Validly__withdraw_AmountZero();

        // Slippage protection checks
        if (amount0 < _amount0Min) {
            revert Validly__withdraw_insufficientToken0Withdrawn();
        }
        if (amount1 < _amount1Min) {
            revert Validly__withdraw_insufficientToken1Withdrawn();
        }

        _burn(msg.sender, _shares);

        pool.withdrawLiquidity(amount0, amount1, msg.sender, _recipient, _verificationContext);
    }

    /**
     * @notice Callback to transfer tokens from user into `pool` during deposits.
     */
    function onDepositLiquidityCallback(uint256 _amount0, uint256 _amount1, bytes memory _data)
        external
        override
        onlyPool
    {
        address user = abi.decode(_data, (address));

        if (_amount0 > 0) {
            IERC20Metadata(pool.token0()).safeTransferFrom(user, msg.sender, _amount0);
        }

        if (_amount1 > 0) {
            IERC20Metadata(pool.token1()).safeTransferFrom(user, msg.sender, _amount1);
        }
    }

    /**
     * @notice Swap callback from pool.
     * @param _poolInput Contains fundamental data about the swap.
     * @return quote Quote information that prices tokenIn and tokenOut.
     */
    function getLiquidityQuote(
        ALMLiquidityQuoteInput memory _poolInput,
        bytes calldata, /*_externalContext*/
        bytes calldata /*_verifierData*/
    ) external override onlyPool returns (ALMLiquidityQuote memory quote) {
        if (_poolInput.feeInBips == 0) {
            revert Validly__getLiquidityQuote_feeInBipsZero();
        }

        (uint256 reserve0, uint256 reserve1) = pool.getReserves();

        (uint256 reserveIn, uint256 reserveOut) = _poolInput.isZeroToOne ? (reserve0, reserve1) : (reserve1, reserve0);

        uint256 invariant;
        if (isStable) {
            invariant = _stableInvariant(reserve0, reserve1);
            // Scale reserves and amounts to 18 decimals
            reserveIn = _poolInput.isZeroToOne ? (reserveIn * 1e18) / decimals0 : (reserveIn * 1e18) / decimals1;
            reserveOut = _poolInput.isZeroToOne ? (reserveOut * 1e18) / decimals1 : (reserveOut * 1e18) / decimals0;
            uint256 amountIn = _poolInput.isZeroToOne
                ? (_poolInput.amountInMinusFee * 1e18) / decimals0
                : (_poolInput.amountInMinusFee * 1e18) / decimals1;
            uint256 amountOut = reserveOut - _get_y_stableInvariant(amountIn + reserveIn, invariant, reserveOut);

            quote.amountOut = (amountOut * (_poolInput.isZeroToOne ? decimals1 : decimals0)) / 1e18;
        } else {
            invariant = reserve0 * reserve1;

            quote.amountOut = (reserveOut * _poolInput.amountInMinusFee) / (reserveIn + _poolInput.amountInMinusFee);
        }

        _cacheInvariant(invariant);

        quote.isCallbackOnSwap = true;

        quote.amountInFilled = _poolInput.amountInMinusFee;
    }

    /**
     * @notice Callback to check invariant after swap.
     */
    function onSwapCallback(
        bool,
        /*_isZeroToOne*/
        uint256,
        /*_amountIn*/
        uint256 /*_amountOut*/
    ) external override onlyPool {
        (uint256 reserve0, uint256 reserve1) = pool.getReserves();

        uint256 invariant = isStable ? _stableInvariant(reserve0, reserve1) : reserve0 * reserve1;

        if (invariant < _getCachedInvariant()) {
            revert Validly__onSwapCallback_invariantViolated();
        }

        _clearInvariant();
    }

    /**
     *
     *  PRIVATE FUNCTIONS
     *
     */
    function _cacheInvariant(uint256 invariant) private {
        bytes32 invariantSlot = INVARIANT_CACHE_SLOT;
        assembly {
            tstore(invariantSlot, invariant)
        }
    }

    function _clearInvariant() private {
        bytes32 invariantSlot = INVARIANT_CACHE_SLOT;
        assembly {
            tstore(invariantSlot, 0)
        }
    }

    function _checkDeadline(uint256 _deadline) private view {
        if (block.timestamp > _deadline) {
            revert Validly__deadlineExpired();
        }
    }

    function _stableInvariant(uint256 x, uint256 y) private view returns (uint256) {
        uint256 _x = (x * 1e18) / decimals0;
        uint256 _y = (y * 1e18) / decimals1;
        uint256 _a = (_x * _y) / 1e18;
        uint256 _b = ((_x * _x) / 1e18 + (_y * _y) / 1e18);
        return (_a * _b) / 1e18; // x3y+y3x >= k
    }

    function _getCachedInvariant() private view returns (uint256 invariant) {
        bytes32 invariantSlot = INVARIANT_CACHE_SLOT;
        assembly {
            invariant := tload(invariantSlot)
        }
    }

    function _f(uint256 x0, uint256 y) private pure returns (uint256) {
        return (x0 * ((((y * y) / 1e18) * y) / 1e18)) / 1e18 + (((((x0 * x0) / 1e18) * x0) / 1e18) * y) / 1e18;
    }

    function _d(uint256 x0, uint256 y) private pure returns (uint256) {
        return (3 * x0 * ((y * y) / 1e18)) / 1e18 + ((((x0 * x0) / 1e18) * x0) / 1e18);
    }

    function _get_y_stableInvariant(uint256 x0, uint256 invariant, uint256 y) private pure returns (uint256) {
        for (uint256 i = 0; i < 255; i++) {
            uint256 y_prev = y;
            uint256 k = _f(x0, y);
            if (k < invariant) {
                uint256 dy = ((invariant - k) * 1e18) / _d(x0, y);
                y = y + dy;
            } else {
                uint256 dy = ((k - invariant) * 1e18) / _d(x0, y);
                y = y - dy;
            }
            if (y > y_prev) {
                if (y - y_prev <= 1) {
                    return y;
                }
            } else {
                if (y_prev - y <= 1) {
                    return y;
                }
            }
        }
        // Did not converge in 255 fixed point iterations,
        // revert for safety
        revert Validly___get_y_notConverged();
    }
}

File 8 of 24 : IValidlyFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {IProtocolFactory} from "@valantis-core/protocol-factory/interfaces/IProtocolFactory.sol";

interface IValidlyFactory {
    /**
     *  EVENTS
     */
    event FeesClaimed(address indexed pool);
    event PoolCreated(address indexed pool, address indexed token0, address indexed token1, bool isStable);
    event PoolManagerFeeBipsSet(address indexed pool, uint256 feeBips);
    event TokenClaimed(address indexed token, address indexed recipient, uint256 amount);

    /**
     *  EXTERNAL FUNCTIONS
     */
    function protocolFactory() external view returns (IProtocolFactory);

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

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

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

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

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

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

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 12 of 24 : ISwapFeeModule.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/**
    @notice Struct returned by the swapFeeModule during the getSwapFeeInBips call.
    * feeInBips: The swap fee in bips.
    * internalContext: Arbitrary bytes context data.
 */
struct SwapFeeModuleData {
    uint256 feeInBips;
    bytes internalContext;
}

interface ISwapFeeModuleMinimal {
    /**
        @notice Returns the swap fee in bips for both Universal & Sovereign Pools.
        @param _tokenIn The address of the token that the user wants to swap.
        @param _tokenOut The address of the token that the user wants to receive.
        @param _amountIn The amount of tokenIn being swapped.
        @param _user The address of the user.
        @param _swapFeeModuleContext Arbitrary bytes data which can be sent to the swap fee module.
        @return swapFeeModuleData A struct containing the swap fee in bips, and internal context data.
     */
    function getSwapFeeInBips(
        address _tokenIn,
        address _tokenOut,
        uint256 _amountIn,
        address _user,
        bytes memory _swapFeeModuleContext
    ) external returns (SwapFeeModuleData memory swapFeeModuleData);
}

interface ISwapFeeModule is ISwapFeeModuleMinimal {
    /**
        @notice Callback function called by the pool after the swap has finished. ( Universal Pools )
        @param _effectiveFee The effective fee charged for the swap.
        @param _spotPriceTick The spot price tick after the swap.
        @param _amountInUsed The amount of tokenIn used for the swap.
        @param _amountOut The amount of the tokenOut transferred to the user.
        @param _swapFeeModuleData The context data returned by getSwapFeeInBips.
     */
    function callbackOnSwapEnd(
        uint256 _effectiveFee,
        int24 _spotPriceTick,
        uint256 _amountInUsed,
        uint256 _amountOut,
        SwapFeeModuleData memory _swapFeeModuleData
    ) external;

    /**
        @notice Callback function called by the pool after the swap has finished. ( Sovereign Pools )
        @param _effectiveFee The effective fee charged for the swap.
        @param _amountInUsed The amount of tokenIn used for the swap.
        @param _amountOut The amount of the tokenOut transferred to the user.
        @param _swapFeeModuleData The context data returned by getSwapFeeInBips.
     */
    function callbackOnSwapEnd(
        uint256 _effectiveFee,
        uint256 _amountInUsed,
        uint256 _amountOut,
        SwapFeeModuleData memory _swapFeeModuleData
    ) external;
}

File 13 of 24 : IValantisPool.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

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

interface IValantisPool {
    /************************************************
     *  EVENTS
     ***********************************************/

    event Flashloan(address indexed initiator, address indexed receiver, uint256 amount, address token);

    /************************************************
     *  ERRORS
     ***********************************************/

    error ValantisPool__flashloan_callbackFailed();
    error ValantisPool__flashLoan_flashLoanDisabled();
    error ValantisPool__flashLoan_flashLoanNotRepaid();
    error ValantisPool__flashLoan_rebaseTokenNotAllowed();

    /************************************************
     *  VIEW FUNCTIONS
     ***********************************************/

    /**
        @notice Address of ERC20 token0 of the pool.
     */
    function token0() external view returns (address);

    /**
        @notice Address of ERC20 token1 of the pool.
     */
    function token1() external view returns (address);

    /************************************************
     *  EXTERNAL FUNCTIONS
     ***********************************************/

    /**
        @notice Claim share of protocol fees accrued by this pool.
        @dev Can only be claimed by `gauge` of the pool. 
     */
    function claimProtocolFees() external returns (uint256, uint256);

    /**
        @notice Claim share of fees accrued by this pool
                And optionally share some with the protocol.
        @dev Only callable by `poolManager`.
        @param _feeProtocol0Bips Percent of `token0` fees to be shared with protocol.
        @param _feeProtocol1Bips Percent of `token1` fees to be shared with protocol.
     */
    function claimPoolManagerFees(
        uint256 _feeProtocol0Bips,
        uint256 _feeProtocol1Bips
    ) external returns (uint256 feePoolManager0Received, uint256 feePoolManager1Received);

    /**
        @notice Sets the gauge contract address for the pool.
        @dev Only callable by `protocolFactory`.
        @dev Once a gauge is set it cannot be changed again.
        @param _gauge address of the gauge.
     */
    function setGauge(address _gauge) external;

    /**
        @notice Allows anyone to flash loan any amount of tokens from the pool.
        @param _isTokenZero True if token0 is being flash loaned, False otherwise.
        @param _receiver Address of the flash loan receiver.
        @param _amount Amount of tokens to be flash loaned.
        @param _data Bytes encoded data for flash loan callback.
     */
    function flashLoan(bool _isTokenZero, IFlashBorrower _receiver, uint256 _amount, bytes calldata _data) external;
}

File 14 of 24 : ReentrancyGuardStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

enum Lock {
    WITHDRAWAL,
    DEPOSIT,
    SWAP,
    SPOT_PRICE_TICK
}

struct PoolLocks {
    /**
        @notice Locks all functions that require any withdrawal of funds from the pool
                This involves the following functions -
                * withdrawLiquidity
                * claimProtocolFees
                * claimPoolManagerFees
     */
    uint8 withdrawals;
    /**
        @notice Only locks the deposit function
    */
    uint8 deposit;
    /**
        @notice Only locks the swap function
    */
    uint8 swap;
    /**
        @notice Only locks the spotPriceTick function
    */
    uint8 spotPriceTick;
}

File 15 of 24 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

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

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

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

File 16 of 24 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

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

File 17 of 24 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

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

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

File 18 of 24 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be 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;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    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 making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

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

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}

File 19 of 24 : SovereignALMStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

struct ALMLiquidityQuoteInput {
    bool isZeroToOne;
    uint256 amountInMinusFee;
    uint256 feeInBips;
    address sender;
    address recipient;
    address tokenOutSwap;
}

struct ALMLiquidityQuote {
    bool isCallbackOnSwap;
    uint256 amountOut;
    uint256 amountInFilled;
}

File 20 of 24 : IValidly.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {ISovereignALM} from "@valantis-core/ALM/interfaces/ISovereignALM.sol";
import {ISovereignPool} from "@valantis-core/pools/interfaces/ISovereignPool.sol";

interface IValidly is ISovereignALM {
    function MINIMUM_LIQUIDITY() external view returns (uint256);

    function INVARIANT_CACHE_SLOT() external view returns (bytes32);

    function pool() external view returns (ISovereignPool);

    function isStable() external view returns (bool);

    function decimals0() external view returns (uint256);

    function decimals1() external view returns (uint256);

    function deposit(
        uint256 _amount0,
        uint256 _amount1,
        uint256 _minShares,
        uint256 _deadline,
        address _recipient,
        bytes calldata _verificationContext
    ) external returns (uint256 shares, uint256 amount0, uint256 amount1);

    function withdraw(
        uint256 _shares,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint256 _deadline,
        address _recipient,
        bytes calldata _verificationContext
    ) external returns (uint256 amount0, uint256 amount1);
}

File 21 of 24 : IFlashBorrower.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

interface IFlashBorrower {
    /**
        @dev Receive a flash loan.
        @param initiator The initiator of the loan.
        @param token The loan currency.
        @param amount The amount of tokens lent.
        @param data Arbitrary data structure, intended to contain user-defined parameters.
        @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
     */
    function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        bytes calldata data
    ) external returns (bytes32);
}

File 22 of 24 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

File 23 of 24 : draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

File 24 of 24 : ISovereignALM.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ALMLiquidityQuoteInput, ALMLiquidityQuote } from '../structs/SovereignALMStructs.sol';

/**
    @title Sovereign ALM interface
    @notice All ALMs bound to a Sovereign Pool must implement it.
 */
interface ISovereignALM {
    /** 
        @notice Called by the Sovereign pool to request a liquidity quote from the ALM.
        @param _almLiquidityQuoteInput Contains fundamental data about the swap.
        @param _externalContext Data received by the pool from the user.
        @param _verifierData Verification data received by the pool from the verifier module
        @return almLiquidityQuote Liquidity quote containing tokenIn and tokenOut amounts filled.
    */
    function getLiquidityQuote(
        ALMLiquidityQuoteInput memory _almLiquidityQuoteInput,
        bytes calldata _externalContext,
        bytes calldata _verifierData
    ) external returns (ALMLiquidityQuote memory);

    /**
        @notice Callback function for `depositLiquidity` .
        @param _amount0 Amount of token0 being deposited.
        @param _amount1 Amount of token1 being deposited.
        @param _data Context data passed by the ALM, while calling `depositLiquidity`.
    */
    function onDepositLiquidityCallback(uint256 _amount0, uint256 _amount1, bytes memory _data) external;

    /**
        @notice Callback to ALM after swap into liquidity pool.
        @dev Only callable by pool.
        @param _isZeroToOne Direction of swap.
        @param _amountIn Amount of tokenIn in swap.
        @param _amountOut Amount of tokenOut in swap. 
     */
    function onSwapCallback(bool _isZeroToOne, uint256 _amountIn, uint256 _amountOut) external;
}

Settings
{
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "@valantis-core/=lib/valantis-core/src/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "ds-test/=lib/valantis-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/valantis-core/lib/openzeppelin-contracts/contracts/",
    "valantis-core/=lib/valantis-core/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false,
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_protocolFactory","type":"address"},{"internalType":"uint256","name":"_feeBips","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"ValidlyFactory__claimTokens_invalidRecipient","type":"error"},{"inputs":[],"name":"ValidlyFactory__claimTokens_invalidToken","type":"error"},{"inputs":[],"name":"ValidlyFactory__constructor_invalidFeeBips","type":"error"},{"inputs":[],"name":"ValidlyFactory__createPair_alreadyDeployed","type":"error"},{"inputs":[],"name":"ValidlyFactory__onlyProtocolManager","type":"error"},{"inputs":[],"name":"ValidlyFactory__setPoolManagerFees_unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"}],"name":"FeesClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"bool","name":"isStable","type":"bool"}],"name":"PoolCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"feeBips","type":"uint256"}],"name":"PoolManagerFeeBipsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokenClaimed","type":"event"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"}],"name":"claimFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"claimTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token0","type":"address"},{"internalType":"address","name":"_token1","type":"address"},{"internalType":"bool","name":"_isStable","type":"bool"}],"name":"createPair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"protocolFactory","type":"address"},{"internalType":"address","name":"poolManager","type":"address"},{"internalType":"address","name":"sovereignVault","type":"address"},{"internalType":"address","name":"verifierModule","type":"address"},{"internalType":"bool","name":"isToken0Rebase","type":"bool"},{"internalType":"bool","name":"isToken1Rebase","type":"bool"},{"internalType":"uint256","name":"token0AbsErrorTolerance","type":"uint256"},{"internalType":"uint256","name":"token1AbsErrorTolerance","type":"uint256"},{"internalType":"uint256","name":"defaultSwapFeeBips","type":"uint256"}],"internalType":"struct SovereignPoolConstructorArgs","name":"_args","type":"tuple"},{"internalType":"bool","name":"_isStable","type":"bool"}],"name":"createPool","outputs":[{"internalType":"address","name":"validly","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeBips","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"pools","outputs":[{"internalType":"address","name":"pool","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFactory","outputs":[{"internalType":"contract IProtocolFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint256","name":"_feeBips","type":"uint256"}],"name":"setPoolManagerFeeBips","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60c060405234801561000f575f80fd5b50604051613a30380380613a3083398101604081905261002e91610070565b6001600160a01b038216608052801580610049575061271081115b1561006757604051630f742a5f60e31b815260040160405180910390fd5b60a052506100a7565b5f8060408385031215610081575f80fd5b82516001600160a01b0381168114610097575f80fd5b6020939093015192949293505050565b60805160a0516139456100eb5f395f8181610157015261070e01525f818161018e0152818161027901528181610405015281816106b301526108b701526139455ff3fe608060405234801562000010575f80fd5b506004361062000090575f3560e01c8063a2efc23b116200005f578063a2efc23b146200010f578063b5217bb41462000126578063d22290a41462000151578063f489048a1462000188575f80fd5b806315a0ea6a1462000094578063227d5c6914620000ad57806369ffa08a14620000e157806382dfdce414620000f8575b5f80fd5b620000ab620000a536600462000c18565b620001b0565b005b620000c4620000be36600462000c88565b6200025a565b6040516001600160a01b0390911681526020015b60405180910390f35b620000ab620000f236600462000d88565b62000403565b620000c46200010936600462000dc4565b620005e9565b620000ab6200012036600462000e13565b620008b5565b620000c46200013736600462000e40565b5f602081905290815260409020546001600160a01b031681565b620001797f000000000000000000000000000000000000000000000000000000000000000081565b604051908152602001620000d8565b620000c47f000000000000000000000000000000000000000000000000000000000000000081565b60405163780ef17560e01b81526127106004820181905260248201526001600160a01b0382169063780ef1759060440160408051808303815f875af1158015620001fc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000222919062000e58565b50506040516001600160a01b038216907fc708bc9126baf78945ae1d05c03aa332ca0460db0e59169024d96f0188f411d1905f90a250565b3060608301525f60a08301819052604051631f156d7560e21b815281907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690637c55b5d490620002b890879060040162000e7b565b6020604051808303815f875af1158015620002d5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620002fb919062000f6b565b905080836040516200030d9062000be3565b6001600160a01b03909216825215156020820152604001604051809103905ff0801580156200033e573d5f803e3d5ffd5b50604051639e25bc7d60e01b81526001600160a01b03808316600483015291935090821690639e25bc7d906024015f604051808303815f87803b15801562000384575f80fd5b505af115801562000397573d5f803e3d5ffd5b5050505083602001516001600160a01b0316845f01516001600160a01b0316826001600160a01b03167f2f50e78ec41ff359ae53695bfffb5c9bae020d7db3779e5f666a3a020ef062b486604051620003f4911515815260200190565b60405180910390a45092915050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ab4b66926040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000460573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000486919062000f6b565b6001600160a01b0316336001600160a01b031614620004b857604051631f81048d60e21b815260040160405180910390fd5b6001600160a01b038216620004e057604051638b8836c160e01b815260040160405180910390fd5b6001600160a01b038116620005085760405163c88687d160e01b815260040160405180910390fd5b6040516370a0823160e01b815230600482015282905f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156200054f573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000575919062000f89565b90508015620005e357620005946001600160a01b038316848362000a09565b826001600160a01b0316846001600160a01b03167f4831bdd9dcf3048a28319ce81d3cab7a15366bcf449bc7803a539107440809cc83604051620005da91815260200190565b60405180910390a35b50505050565b5f826001600160a01b0316846001600160a01b0316106200060c5782846200060f565b83835b604080516001600160a01b0380851660208084019190915290841682840152861515606080840191909152835180840390910181526080909201909252805191012091955093505f905f818152602081905260409020549091506001600160a01b031615620006915760405163f9b17a5f60e01b815260040160405180910390fd5b60408051610160810182526001600160a01b03808816825286811660208301527f0000000000000000000000000000000000000000000000000000000000000000168183018190523060608301525f6080830181905260a0830181905260c0830181905260e08301819052610100830181905261012083018190527f00000000000000000000000000000000000000000000000000000000000000006101408401529251631f156d7560e21b8152919291637c55b5d4906200075890859060040162000e7b565b6020604051808303815f875af115801562000775573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200079b919062000f6b565b90505f838287604051620007af9062000be3565b6001600160a01b039092168252151560208201526040018190604051809103905ff5905080158015620007e4573d5f803e3d5ffd5b50604051639e25bc7d60e01b81526001600160a01b03808316600483015291925090831690639e25bc7d906024015f604051808303815f87803b1580156200082a575f80fd5b505af11580156200083d573d5f803e3d5ffd5b5050505f858152602081815260409182902080546001600160a01b0319166001600160a01b0387811691821790925592518a151581528b82169450908c1692917f2f50e78ec41ff359ae53695bfffb5c9bae020d7db3779e5f666a3a020ef062b4910160405180910390a493505050505b9392505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ab4b66926040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000912573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000938919062000f6b565b6001600160a01b0316336001600160a01b0316146200096a57604051631f81048d60e21b815260040160405180910390fd5b60405163453edd5160e11b8152600481018290526001600160a01b03831690638a7dbaa2906024015f604051808303815f87803b158015620009aa575f80fd5b505af1158015620009bd573d5f803e3d5ffd5b50505050816001600160a01b03167fe36f4d28bc9befc502de8a71eed3f393a3957dd629bd76807611d9afdcbb102382604051620009fd91815260200190565b60405180910390a25050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b17905262000a5d90849062000a62565b505050565b5f62000a786001600160a01b0384168362000ace565b905080515f1415801562000a9f57508080602001905181019062000a9d919062000fa1565b155b1562000a5d57604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b6060620008ae83835f845f80856001600160a01b0316848660405162000af5919062000fbf565b5f6040518083038185875af1925050503d805f811462000b31576040519150601f19603f3d011682016040523d82523d5f602084013e62000b36565b606091505b509150915062000b4886838362000b52565b9695505050505050565b60608262000b6b5762000b658262000bb6565b620008ae565b815115801562000b8357506001600160a01b0384163b155b1562000bae57604051639996b31560e01b81526001600160a01b038516600482015260240162000ac5565b5080620008ae565b80511562000bc75780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b50565b6129228062000fee83390190565b6001600160a01b038116811462000be0575f80fd5b803562000c138162000bf1565b919050565b5f6020828403121562000c29575f80fd5b8135620008ae8162000bf1565b604051610160810167ffffffffffffffff8111828210171562000c6757634e487b7160e01b5f52604160045260245ffd5b60405290565b801515811462000be0575f80fd5b803562000c138162000c6d565b5f8082840361018081121562000c9c575f80fd5b6101608082121562000cac575f80fd5b62000cb662000c36565b915062000cc38562000c06565b825262000cd36020860162000c06565b602083015262000ce66040860162000c06565b604083015262000cf96060860162000c06565b606083015262000d0c6080860162000c06565b608083015262000d1f60a0860162000c06565b60a083015262000d3260c0860162000c7b565b60c083015262000d4560e0860162000c7b565b60e0830152610100858101359083015261012080860135908301526101408086013590830152909250829062000d7d81860162000c7b565b925050509250929050565b5f806040838503121562000d9a575f80fd5b823562000da78162000bf1565b9150602083013562000db98162000bf1565b809150509250929050565b5f805f6060848603121562000dd7575f80fd5b833562000de48162000bf1565b9250602084013562000df68162000bf1565b9150604084013562000e088162000c6d565b809150509250925092565b5f806040838503121562000e25575f80fd5b823562000e328162000bf1565b946020939093013593505050565b5f6020828403121562000e51575f80fd5b5035919050565b5f806040838503121562000e6a575f80fd5b505080516020909101519092909150565b81516001600160a01b031681526101608101602083015162000ea860208401826001600160a01b03169052565b50604083015162000ec460408401826001600160a01b03169052565b50606083015162000ee060608401826001600160a01b03169052565b50608083015162000efc60808401826001600160a01b03169052565b5060a083015162000f1860a08401826001600160a01b03169052565b5060c083015162000f2d60c084018215159052565b5060e083015162000f4260e084018215159052565b506101008381015190830152610120808401519083015261014092830151929091019190915290565b5f6020828403121562000f7c575f80fd5b8151620008ae8162000bf1565b5f6020828403121562000f9a575f80fd5b5051919050565b5f6020828403121562000fb2575f80fd5b8151620008ae8162000c6d565b5f82515f5b8181101562000fe0576020818601810151858301520162000fc4565b505f92019182525091905056fe61010060405234801562000011575f80fd5b506040516200292238038062002922833981016040819052620000349162000347565b6040518060400160405280601081526020016f2b30b634b2363c902628102a37b5b2b760811b81525060405180604001604052806006815260200165056414c2d4c560d41b81525081600390816200008d919062000422565b5060046200009c828262000422565b50506001600555506001600160a01b038216620000cc5760405163d3cbf7ed60e01b815260040160405180910390fd5b6001600160a01b03821660808190526040805163baad44eb60e01b81529051829163baad44eb9160048083019260209291908290030181865afa15801562000116573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200013c9190620004ee565b6001600160a01b0316146200016457604051635b7e700760e01b815260040160405180910390fd5b80151560a0811515815250506080516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015620001af573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620001d59190620004ee565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000211573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000237919062000511565b6200024490600a62000642565b60c081815250506080516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200028a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620002b09190620004ee565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015620002ec573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000312919062000511565b6200031f90600a62000642565b60e05250620006529050565b80516001600160a01b038116811462000342575f80fd5b919050565b5f806040838503121562000359575f80fd5b62000364836200032b565b91506020830151801515811462000379575f80fd5b809150509250929050565b634e487b7160e01b5f52604160045260245ffd5b600181811c90821680620003ad57607f821691505b602082108103620003cc57634e487b7160e01b5f52602260045260245ffd5b50919050565b601f8211156200041d57805f5260205f20601f840160051c81016020851015620003f95750805b601f840160051c820191505b818110156200041a575f815560010162000405565b50505b505050565b81516001600160401b038111156200043e576200043e62000384565b62000456816200044f845462000398565b84620003d2565b602080601f8311600181146200048c575f8415620004745750858301515b5f19600386901b1c1916600185901b178555620004e6565b5f85815260208120601f198616915b82811015620004bc578886015182559484019460019091019084016200049b565b5085821015620004da57878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b5f60208284031215620004ff575f80fd5b6200050a826200032b565b9392505050565b5f6020828403121562000522575f80fd5b815160ff811681146200050a575f80fd5b634e487b7160e01b5f52601160045260245ffd5b600181815b808511156200058757815f19048211156200056b576200056b62000533565b808516156200057957918102915b93841c93908002906200054c565b509250929050565b5f826200059f575060016200063c565b81620005ad57505f6200063c565b8160018114620005c65760028114620005d157620005f1565b60019150506200063c565b60ff841115620005e557620005e562000533565b50506001821b6200063c565b5060208310610133831016604e8410600b841016171562000616575081810a6200063c565b62000622838362000547565b805f190482111562000638576200063862000533565b0290505b92915050565b5f6200050a60ff8416836200058f565b60805160a05160c05160e0516121fb620007275f395f818161028b01528181610ac501528181610b8f01528181610bd701528181610cbc015261119301525f818161024801528181610b0701528181610b4d01528181610c1f01528181610c96015261115301525f818161014e015281816106ba0152610a8c01525f81816101980152818161047a015281816104dd0152818161057a015281816105f401528181610636015281816107a3015281816108d60152818161098a015281816109f001528181610dc30152610f2c01526121fb5ff3fe608060405234801561000f575f80fd5b5060043610610127575f3560e01c80637c25cf2a116100a9578063ba9a7a561161006e578063ba9a7a56146102d3578063bf99591d146102dc578063dd62ed3e14610304578063ede5e5841461033c578063f55a2e8314610373575f80fd5b80637c25cf2a1461026a57806395d89b411461027e578063a28af8a414610286578063a3f3d722146102ad578063a9059cbb146102c0575f80fd5b806323b872dd116100ef57806323b872dd146101e45780632d4b23bd146101f7578063313ce5671461020c57806370a082311461021b5780637bdd6b4414610243575f80fd5b806306fdde031461012b57806309047bdd14610149578063095ea7b31461018057806316f0115b1461019357806318160ddd146101d2575b5f80fd5b6101336103a1565b6040516101409190611bc4565b60405180910390f35b6101707f000000000000000000000000000000000000000000000000000000000000000081565b6040519015158152602001610140565b61017061018e366004611bea565b610431565b6101ba7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610140565b6002545b604051908152602001610140565b6101706101f2366004611c14565b61044a565b61020a610205366004611cc0565b61046f565b005b60405160128152602001610140565b6101d6610229366004611d61565b6001600160a01b03165f9081526020819052604090205490565b6101d67f000000000000000000000000000000000000000000000000000000000000000081565b6101d65f805160206121a683398151915281565b6101336105da565b6101d67f000000000000000000000000000000000000000000000000000000000000000081565b61020a6102bb366004611d89565b6105e9565b6101706102ce366004611bea565b610737565b6101d66103e881565b6102ef6102ea366004611e00565b610744565b60408051928352602083019190915201610140565b6101d6610312366004611e77565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b61034f61034a366004611eae565b61095c565b60408051825115158152602080840151908201529181015190820152606001610140565b610386610381366004611e00565b610d5e565b60408051938452602084019290925290820152606001610140565b6060600380546103b090611f94565b80601f01602080910402602001604051908101604052809291908181526020018280546103dc90611f94565b80156104275780601f106103fe57610100808354040283529160200191610427565b820191905f5260205f20905b81548152906001019060200180831161040a57829003601f168201915b5050505050905090565b5f3361043e81858561100c565b60019150505b92915050565b5f3361045785828561101e565b610462858585611098565b60019150505b9392505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146104b85760405163c1268d9560e01b815260040160405180910390fd5b5f818060200190518101906104cd9190611fcc565b9050831561056c5761056c8133867f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610537573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061055b9190611fcc565b6001600160a01b03169291906110f5565b82156105d4576105d48133857f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610537573d5f803e3d5ffd5b50505050565b6060600480546103b090611f94565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146106325760405163c1268d9560e01b815260040160405180910390fd5b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa15801561068f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106b39190611fe7565b915091505f7f00000000000000000000000000000000000000000000000000000000000000006106ec576106e7828461201d565b6106f6565b6106f6838361114f565b90505f805160206121a68339815191525c81101561072757604051630b69d15960e11b815260040160405180910390fd5b61072f61125f565b505050505050565b5f3361043e818585611098565b5f808561075081611273565b610758611297565b895f03610778576040516314be162b60e31b815260040160405180910390fd5b6001600160a01b03861661079f5760405163a02b995160e01b815260040160405180910390fd5b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa1580156107fc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108209190611fe7565b915091505f61082e60025490565b905061083b838e836112c1565b9550610848828e836112c1565b9450851580610855575084155b1561087357604051637d81219d60e01b815260040160405180910390fd5b8b861015610894576040516336c87b1160e11b815260040160405180910390fd5b8a8510156108b557604051633651b34b60e21b815260040160405180910390fd5b6108bf338e611380565b6040516301c48a4360e61b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063712290c090610915908990899033908f908f908f9060040161205c565b5f604051808303815f87803b15801561092c575f80fd5b505af115801561093e573d5f803e3d5ffd5b5050505050505061094f6001600555565b5097509795505050505050565b61097f60405180606001604052805f151581526020015f81526020015f81525090565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109c85760405163c1268d9560e01b815260040160405180910390fd5b85604001515f036109ec57604051632d85e30560e21b815260040160405180910390fd5b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa158015610a49573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a6d9190611fe7565b915091505f80895f0151610a82578284610a85565b83835b915091505f7f000000000000000000000000000000000000000000000000000000000000000015610cfd57610aba858561114f565b8b51909150610b05577f0000000000000000000000000000000000000000000000000000000000000000610af684670de0b6b3a764000061201d565b610b0091906120b5565b610b42565b7f0000000000000000000000000000000000000000000000000000000000000000610b3884670de0b6b3a764000061201d565b610b4291906120b5565b8b51909350610b8d577f0000000000000000000000000000000000000000000000000000000000000000610b7e83670de0b6b3a764000061201d565b610b8891906120b5565b610bca565b7f0000000000000000000000000000000000000000000000000000000000000000610bc083670de0b6b3a764000061201d565b610bca91906120b5565b91505f8b5f0151610c1d577f00000000000000000000000000000000000000000000000000000000000000008c60200151670de0b6b3a7640000610c0e919061201d565b610c1891906120b5565b610c60565b7f00000000000000000000000000000000000000000000000000000000000000008c60200151670de0b6b3a7640000610c56919061201d565b610c6091906120b5565b90505f610c77610c7086846120c8565b84866113b8565b610c8190856120db565b9050670de0b6b3a76400008d5f0151610cba577f0000000000000000000000000000000000000000000000000000000000000000610cdc565b7f00000000000000000000000000000000000000000000000000000000000000005b610ce6908361201d565b610cf091906120b5565b602089015250610d389050565b610d07848661201d565b90508a6020015183610d1991906120c8565b60208c0151610d28908461201d565b610d3291906120b5565b60208701525b610d41816114c9565b505060018452505050602090950151604086015250929392505050565b5f805f86610d6b81611273565b610d73611297565b5f610d7d60025490565b9050805f03610dbf578b93508a9250610d9960016103e86114de565b6103e8610dae610da9858761201d565b611512565b610db891906120db565b9450610edf565b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa158015610e1c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e409190611fe7565b915091505f610e508f85856112c1565b90505f610e5e8f86856112c1565b905080821015610e8257819850610e78838a8760016115f6565b96508f9750610e98565b809850610e92848a8760016115f6565b97508e96505b8f881115610eb95760405163071c3a9160e31b815260040160405180910390fd5b8e871115610eda5760405163033c957d60e11b815260040160405180910390fd5b505050505b89851015610f00576040516365b750ff60e01b815260040160405180910390fd5b845f03610f205760405163bde995d360e01b815260040160405180910390fd5b610f2a88866114de565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166341a41e9e8585338b8b33604051602001610f7e91906001600160a01b0391909116815260200190565b6040516020818303038152906040526040518763ffffffff1660e01b8152600401610fae969594939291906120ee565b60408051808303815f875af1158015610fc9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fed9190611fe7565b9094509250610ffe90506001600555565b509750975097945050505050565b6110198383836001611645565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f1981146105d4578181101561108a57604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064015b60405180910390fd5b6105d484848484035f611645565b6001600160a01b0383166110c157604051634b637e8f60e11b81525f6004820152602401611081565b6001600160a01b0382166110ea5760405163ec442f0560e01b81525f6004820152602401611081565b611019838383611717565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526105d490859061183d565b5f807f000000000000000000000000000000000000000000000000000000000000000061118485670de0b6b3a764000061201d565b61118e91906120b5565b90505f7f00000000000000000000000000000000000000000000000000000000000000006111c485670de0b6b3a764000061201d565b6111ce91906120b5565b90505f670de0b6b3a76400006111e4838561201d565b6111ee91906120b5565b90505f670de0b6b3a7640000611204848061201d565b61120e91906120b5565b670de0b6b3a7640000611221868061201d565b61122b91906120b5565b61123591906120c8565b9050670de0b6b3a764000061124a828461201d565b61125491906120b5565b979650505050505050565b5f805160206121a68339815191525f815d50565b8042111561129457604051636ca8dcf160e11b815260040160405180910390fd5b50565b6002600554036112ba57604051633ee5aeb560e01b815260040160405180910390fd5b6002600555565b5f838302815f1985870982811083820303915050805f036112f5578382816112eb576112eb6120a1565b0492505050610468565b8084116113155760405163227bc15360e01b815260040160405180910390fd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6001600160a01b0382166113a957604051634b637e8f60e11b81525f6004820152602401611081565b6113b4825f83611717565b5050565b5f805b60ff8110156114af57825f6113d0878361189e565b90508581101561141f575f6113e5888761193a565b6113ef83896120db565b61140190670de0b6b3a764000061201d565b61140b91906120b5565b905061141781876120c8565b955050611460565b5f61142a888761193a565b61143488846120db565b61144690670de0b6b3a764000061201d565b61145091906120b5565b905061145c81876120db565b9550505b8185111561148957600161147483876120db565b1161148457849350505050610468565b6114a5565b600161149586846120db565b116114a557849350505050610468565b50506001016113bb565b50604051633e3dc24960e21b815260040160405180910390fd5b5f805160206121a683398151915281815d5050565b6001600160a01b0382166115075760405163ec442f0560e01b81525f6004820152602401611081565b6113b45f8383611717565b5f815f0361152157505f919050565b5f600161152d846119a1565b901c6001901b90506001818481611546576115466120a1565b048201901c9050600181848161155e5761155e6120a1565b048201901c90506001818481611576576115766120a1565b048201901c9050600181848161158e5761158e6120a1565b048201901c905060018184816115a6576115a66120a1565b048201901c905060018184816115be576115be6120a1565b048201901c905060018184816115d6576115d66120a1565b048201901c9050610468818285816115f0576115f06120a1565b04611a34565b5f806116038686866112c1565b905061160e83611a49565b801561162957505f8480611624576116246120a1565b868809115b1561163c576116396001826120c8565b90505b95945050505050565b6001600160a01b03841661166e5760405163e602df0560e01b81525f6004820152602401611081565b6001600160a01b03831661169757604051634a1406b160e11b81525f6004820152602401611081565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156105d457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161170991815260200190565b60405180910390a350505050565b6001600160a01b038316611741578060025f82825461173691906120c8565b909155506117b19050565b6001600160a01b0383165f90815260208190526040902054818110156117935760405163391434e360e21b81526001600160a01b03851660048201526024810182905260448101839052606401611081565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b0382166117cd576002805482900390556117eb565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161183091815260200190565b60405180910390a3505050565b5f6118516001600160a01b03841683611a75565b905080515f14158015611875575080806020019051810190611873919061213a565b155b1561101957604051635274afe760e01b81526001600160a01b0384166004820152602401611081565b5f670de0b6b3a7640000828185816118b6828061201d565b6118c091906120b5565b6118ca919061201d565b6118d491906120b5565b6118de919061201d565b6118e891906120b5565b670de0b6b3a76400008084816118fe828061201d565b61190891906120b5565b611912919061201d565b61191c91906120b5565b611926908661201d565b61193091906120b5565b61046891906120c8565b5f670de0b6b3a76400008381611950828061201d565b61195a91906120b5565b611964919061201d565b61196e91906120b5565b670de0b6b3a764000080611982858061201d565b61198c91906120b5565b61199786600361201d565b611926919061201d565b5f80608083901c156119b557608092831c92015b604083901c156119c757604092831c92015b602083901c156119d957602092831c92015b601083901c156119eb57601092831c92015b600883901c156119fd57600892831c92015b600483901c15611a0f57600492831c92015b600283901c15611a2157600292831c92015b600183901c156104445760010192915050565b5f818310611a425781610468565b5090919050565b5f6002826003811115611a5e57611a5e612155565b611a689190612169565b60ff166001149050919050565b606061046883835f845f80856001600160a01b03168486604051611a99919061218a565b5f6040518083038185875af1925050503d805f8114611ad3576040519150601f19603f3d011682016040523d82523d5f602084013e611ad8565b606091505b5091509150611ae8868383611af2565b9695505050505050565b606082611b0757611b0282611b4e565b610468565b8151158015611b1e57506001600160a01b0384163b155b15611b4757604051639996b31560e01b81526001600160a01b0385166004820152602401611081565b5080610468565b805115611b5e5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b5f5b83811015611b91578181015183820152602001611b79565b50505f910152565b5f8151808452611bb0816020860160208601611b77565b601f01601f19169290920160200192915050565b602081525f6104686020830184611b99565b6001600160a01b0381168114611294575f80fd5b5f8060408385031215611bfb575f80fd5b8235611c0681611bd6565b946020939093013593505050565b5f805f60608486031215611c26575f80fd5b8335611c3181611bd6565b92506020840135611c4181611bd6565b929592945050506040919091013590565b634e487b7160e01b5f52604160045260245ffd5b60405160c0810167ffffffffffffffff81118282101715611c8957611c89611c52565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611cb857611cb8611c52565b604052919050565b5f805f60608486031215611cd2575f80fd5b833592506020808501359250604085013567ffffffffffffffff80821115611cf8575f80fd5b818701915087601f830112611d0b575f80fd5b813581811115611d1d57611d1d611c52565b611d2f601f8201601f19168501611c8f565b91508082528884828501011115611d44575f80fd5b80848401858401375f848284010152508093505050509250925092565b5f60208284031215611d71575f80fd5b813561046881611bd6565b8015158114611294575f80fd5b5f805f60608486031215611d9b575f80fd5b8335611da681611d7c565b95602085013595506040909401359392505050565b5f8083601f840112611dcb575f80fd5b50813567ffffffffffffffff811115611de2575f80fd5b602083019150836020828501011115611df9575f80fd5b9250929050565b5f805f805f805f60c0888a031215611e16575f80fd5b873596506020880135955060408801359450606088013593506080880135611e3d81611bd6565b925060a088013567ffffffffffffffff811115611e58575f80fd5b611e648a828b01611dbb565b989b979a50959850939692959293505050565b5f8060408385031215611e88575f80fd5b8235611e9381611bd6565b91506020830135611ea381611bd6565b809150509250929050565b5f805f805f858703610100811215611ec4575f80fd5b60c0811215611ed1575f80fd5b50611eda611c66565b8635611ee581611d7c565b8082525060208701356020820152604087013560408201526060870135611f0b81611bd6565b60608201526080870135611f1e81611bd6565b608082015260a0870135611f3181611bd6565b60a0820152945060c086013567ffffffffffffffff80821115611f52575f80fd5b611f5e89838a01611dbb565b909650945060e0880135915080821115611f76575f80fd5b50611f8388828901611dbb565b969995985093965092949392505050565b600181811c90821680611fa857607f821691505b602082108103611fc657634e487b7160e01b5f52602260045260245ffd5b50919050565b5f60208284031215611fdc575f80fd5b815161046881611bd6565b5f8060408385031215611ff8575f80fd5b505080516020909101519092909150565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761044457610444612009565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b868152602081018690526001600160a01b0385811660408301528416606082015260a0608082018190525f906120959083018486612034565b98975050505050505050565b634e487b7160e01b5f52601260045260245ffd5b5f826120c3576120c36120a1565b500490565b8082018082111561044457610444612009565b8181038181111561044457610444612009565b86815285602082015260018060a01b038516604082015260a060608201525f61211b60a083018587612034565b828103608084015261212d8185611b99565b9998505050505050505050565b5f6020828403121561214a575f80fd5b815161046881611d7c565b634e487b7160e01b5f52602160045260245ffd5b5f60ff83168061217b5761217b6120a1565b8060ff84160691505092915050565b5f825161219b818460208701611b77565b919091019291505056fe52f706286e01e431c0f568fbf950e6f1794322feba1e039f98b8888d605f5707a26469706673582212201c6a57badec4368e2d3d13fe50438bc568278c581f2f6db90914dcff2649c5b664736f6c63430008180033a2646970667358221220c186fb712cdd5436c8b84306143c93f84d1b4659bc04994e46d32124a91b494c64736f6c6343000818003300000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a6030000000000000000000000000000000000000000000000000000000000000005

Deployed Bytecode

0x608060405234801562000010575f80fd5b506004361062000090575f3560e01c8063a2efc23b116200005f578063a2efc23b146200010f578063b5217bb41462000126578063d22290a41462000151578063f489048a1462000188575f80fd5b806315a0ea6a1462000094578063227d5c6914620000ad57806369ffa08a14620000e157806382dfdce414620000f8575b5f80fd5b620000ab620000a536600462000c18565b620001b0565b005b620000c4620000be36600462000c88565b6200025a565b6040516001600160a01b0390911681526020015b60405180910390f35b620000ab620000f236600462000d88565b62000403565b620000c46200010936600462000dc4565b620005e9565b620000ab6200012036600462000e13565b620008b5565b620000c46200013736600462000e40565b5f602081905290815260409020546001600160a01b031681565b620001797f000000000000000000000000000000000000000000000000000000000000000581565b604051908152602001620000d8565b620000c47f00000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a60381565b60405163780ef17560e01b81526127106004820181905260248201526001600160a01b0382169063780ef1759060440160408051808303815f875af1158015620001fc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000222919062000e58565b50506040516001600160a01b038216907fc708bc9126baf78945ae1d05c03aa332ca0460db0e59169024d96f0188f411d1905f90a250565b3060608301525f60a08301819052604051631f156d7560e21b815281907f00000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a6036001600160a01b031690637c55b5d490620002b890879060040162000e7b565b6020604051808303815f875af1158015620002d5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620002fb919062000f6b565b905080836040516200030d9062000be3565b6001600160a01b03909216825215156020820152604001604051809103905ff0801580156200033e573d5f803e3d5ffd5b50604051639e25bc7d60e01b81526001600160a01b03808316600483015291935090821690639e25bc7d906024015f604051808303815f87803b15801562000384575f80fd5b505af115801562000397573d5f803e3d5ffd5b5050505083602001516001600160a01b0316845f01516001600160a01b0316826001600160a01b03167f2f50e78ec41ff359ae53695bfffb5c9bae020d7db3779e5f666a3a020ef062b486604051620003f4911515815260200190565b60405180910390a45092915050565b7f00000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a6036001600160a01b031663ab4b66926040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000460573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000486919062000f6b565b6001600160a01b0316336001600160a01b031614620004b857604051631f81048d60e21b815260040160405180910390fd5b6001600160a01b038216620004e057604051638b8836c160e01b815260040160405180910390fd5b6001600160a01b038116620005085760405163c88687d160e01b815260040160405180910390fd5b6040516370a0823160e01b815230600482015282905f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156200054f573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000575919062000f89565b90508015620005e357620005946001600160a01b038316848362000a09565b826001600160a01b0316846001600160a01b03167f4831bdd9dcf3048a28319ce81d3cab7a15366bcf449bc7803a539107440809cc83604051620005da91815260200190565b60405180910390a35b50505050565b5f826001600160a01b0316846001600160a01b0316106200060c5782846200060f565b83835b604080516001600160a01b0380851660208084019190915290841682840152861515606080840191909152835180840390910181526080909201909252805191012091955093505f905f818152602081905260409020549091506001600160a01b031615620006915760405163f9b17a5f60e01b815260040160405180910390fd5b60408051610160810182526001600160a01b03808816825286811660208301527f00000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a603168183018190523060608301525f6080830181905260a0830181905260c0830181905260e08301819052610100830181905261012083018190527f00000000000000000000000000000000000000000000000000000000000000056101408401529251631f156d7560e21b8152919291637c55b5d4906200075890859060040162000e7b565b6020604051808303815f875af115801562000775573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200079b919062000f6b565b90505f838287604051620007af9062000be3565b6001600160a01b039092168252151560208201526040018190604051809103905ff5905080158015620007e4573d5f803e3d5ffd5b50604051639e25bc7d60e01b81526001600160a01b03808316600483015291925090831690639e25bc7d906024015f604051808303815f87803b1580156200082a575f80fd5b505af11580156200083d573d5f803e3d5ffd5b5050505f858152602081815260409182902080546001600160a01b0319166001600160a01b0387811691821790925592518a151581528b82169450908c1692917f2f50e78ec41ff359ae53695bfffb5c9bae020d7db3779e5f666a3a020ef062b4910160405180910390a493505050505b9392505050565b7f00000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a6036001600160a01b031663ab4b66926040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000912573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000938919062000f6b565b6001600160a01b0316336001600160a01b0316146200096a57604051631f81048d60e21b815260040160405180910390fd5b60405163453edd5160e11b8152600481018290526001600160a01b03831690638a7dbaa2906024015f604051808303815f87803b158015620009aa575f80fd5b505af1158015620009bd573d5f803e3d5ffd5b50505050816001600160a01b03167fe36f4d28bc9befc502de8a71eed3f393a3957dd629bd76807611d9afdcbb102382604051620009fd91815260200190565b60405180910390a25050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b17905262000a5d90849062000a62565b505050565b5f62000a786001600160a01b0384168362000ace565b905080515f1415801562000a9f57508080602001905181019062000a9d919062000fa1565b155b1562000a5d57604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b6060620008ae83835f845f80856001600160a01b0316848660405162000af5919062000fbf565b5f6040518083038185875af1925050503d805f811462000b31576040519150601f19603f3d011682016040523d82523d5f602084013e62000b36565b606091505b509150915062000b4886838362000b52565b9695505050505050565b60608262000b6b5762000b658262000bb6565b620008ae565b815115801562000b8357506001600160a01b0384163b155b1562000bae57604051639996b31560e01b81526001600160a01b038516600482015260240162000ac5565b5080620008ae565b80511562000bc75780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b50565b6129228062000fee83390190565b6001600160a01b038116811462000be0575f80fd5b803562000c138162000bf1565b919050565b5f6020828403121562000c29575f80fd5b8135620008ae8162000bf1565b604051610160810167ffffffffffffffff8111828210171562000c6757634e487b7160e01b5f52604160045260245ffd5b60405290565b801515811462000be0575f80fd5b803562000c138162000c6d565b5f8082840361018081121562000c9c575f80fd5b6101608082121562000cac575f80fd5b62000cb662000c36565b915062000cc38562000c06565b825262000cd36020860162000c06565b602083015262000ce66040860162000c06565b604083015262000cf96060860162000c06565b606083015262000d0c6080860162000c06565b608083015262000d1f60a0860162000c06565b60a083015262000d3260c0860162000c7b565b60c083015262000d4560e0860162000c7b565b60e0830152610100858101359083015261012080860135908301526101408086013590830152909250829062000d7d81860162000c7b565b925050509250929050565b5f806040838503121562000d9a575f80fd5b823562000da78162000bf1565b9150602083013562000db98162000bf1565b809150509250929050565b5f805f6060848603121562000dd7575f80fd5b833562000de48162000bf1565b9250602084013562000df68162000bf1565b9150604084013562000e088162000c6d565b809150509250925092565b5f806040838503121562000e25575f80fd5b823562000e328162000bf1565b946020939093013593505050565b5f6020828403121562000e51575f80fd5b5035919050565b5f806040838503121562000e6a575f80fd5b505080516020909101519092909150565b81516001600160a01b031681526101608101602083015162000ea860208401826001600160a01b03169052565b50604083015162000ec460408401826001600160a01b03169052565b50606083015162000ee060608401826001600160a01b03169052565b50608083015162000efc60808401826001600160a01b03169052565b5060a083015162000f1860a08401826001600160a01b03169052565b5060c083015162000f2d60c084018215159052565b5060e083015162000f4260e084018215159052565b506101008381015190830152610120808401519083015261014092830151929091019190915290565b5f6020828403121562000f7c575f80fd5b8151620008ae8162000bf1565b5f6020828403121562000f9a575f80fd5b5051919050565b5f6020828403121562000fb2575f80fd5b8151620008ae8162000c6d565b5f82515f5b8181101562000fe0576020818601810151858301520162000fc4565b505f92019182525091905056fe61010060405234801562000011575f80fd5b506040516200292238038062002922833981016040819052620000349162000347565b6040518060400160405280601081526020016f2b30b634b2363c902628102a37b5b2b760811b81525060405180604001604052806006815260200165056414c2d4c560d41b81525081600390816200008d919062000422565b5060046200009c828262000422565b50506001600555506001600160a01b038216620000cc5760405163d3cbf7ed60e01b815260040160405180910390fd5b6001600160a01b03821660808190526040805163baad44eb60e01b81529051829163baad44eb9160048083019260209291908290030181865afa15801562000116573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200013c9190620004ee565b6001600160a01b0316146200016457604051635b7e700760e01b815260040160405180910390fd5b80151560a0811515815250506080516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015620001af573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620001d59190620004ee565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000211573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000237919062000511565b6200024490600a62000642565b60c081815250506080516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200028a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620002b09190620004ee565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015620002ec573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000312919062000511565b6200031f90600a62000642565b60e05250620006529050565b80516001600160a01b038116811462000342575f80fd5b919050565b5f806040838503121562000359575f80fd5b62000364836200032b565b91506020830151801515811462000379575f80fd5b809150509250929050565b634e487b7160e01b5f52604160045260245ffd5b600181811c90821680620003ad57607f821691505b602082108103620003cc57634e487b7160e01b5f52602260045260245ffd5b50919050565b601f8211156200041d57805f5260205f20601f840160051c81016020851015620003f95750805b601f840160051c820191505b818110156200041a575f815560010162000405565b50505b505050565b81516001600160401b038111156200043e576200043e62000384565b62000456816200044f845462000398565b84620003d2565b602080601f8311600181146200048c575f8415620004745750858301515b5f19600386901b1c1916600185901b178555620004e6565b5f85815260208120601f198616915b82811015620004bc578886015182559484019460019091019084016200049b565b5085821015620004da57878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b5f60208284031215620004ff575f80fd5b6200050a826200032b565b9392505050565b5f6020828403121562000522575f80fd5b815160ff811681146200050a575f80fd5b634e487b7160e01b5f52601160045260245ffd5b600181815b808511156200058757815f19048211156200056b576200056b62000533565b808516156200057957918102915b93841c93908002906200054c565b509250929050565b5f826200059f575060016200063c565b81620005ad57505f6200063c565b8160018114620005c65760028114620005d157620005f1565b60019150506200063c565b60ff841115620005e557620005e562000533565b50506001821b6200063c565b5060208310610133831016604e8410600b841016171562000616575081810a6200063c565b62000622838362000547565b805f190482111562000638576200063862000533565b0290505b92915050565b5f6200050a60ff8416836200058f565b60805160a05160c05160e0516121fb620007275f395f818161028b01528181610ac501528181610b8f01528181610bd701528181610cbc015261119301525f818161024801528181610b0701528181610b4d01528181610c1f01528181610c96015261115301525f818161014e015281816106ba0152610a8c01525f81816101980152818161047a015281816104dd0152818161057a015281816105f401528181610636015281816107a3015281816108d60152818161098a015281816109f001528181610dc30152610f2c01526121fb5ff3fe608060405234801561000f575f80fd5b5060043610610127575f3560e01c80637c25cf2a116100a9578063ba9a7a561161006e578063ba9a7a56146102d3578063bf99591d146102dc578063dd62ed3e14610304578063ede5e5841461033c578063f55a2e8314610373575f80fd5b80637c25cf2a1461026a57806395d89b411461027e578063a28af8a414610286578063a3f3d722146102ad578063a9059cbb146102c0575f80fd5b806323b872dd116100ef57806323b872dd146101e45780632d4b23bd146101f7578063313ce5671461020c57806370a082311461021b5780637bdd6b4414610243575f80fd5b806306fdde031461012b57806309047bdd14610149578063095ea7b31461018057806316f0115b1461019357806318160ddd146101d2575b5f80fd5b6101336103a1565b6040516101409190611bc4565b60405180910390f35b6101707f000000000000000000000000000000000000000000000000000000000000000081565b6040519015158152602001610140565b61017061018e366004611bea565b610431565b6101ba7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610140565b6002545b604051908152602001610140565b6101706101f2366004611c14565b61044a565b61020a610205366004611cc0565b61046f565b005b60405160128152602001610140565b6101d6610229366004611d61565b6001600160a01b03165f9081526020819052604090205490565b6101d67f000000000000000000000000000000000000000000000000000000000000000081565b6101d65f805160206121a683398151915281565b6101336105da565b6101d67f000000000000000000000000000000000000000000000000000000000000000081565b61020a6102bb366004611d89565b6105e9565b6101706102ce366004611bea565b610737565b6101d66103e881565b6102ef6102ea366004611e00565b610744565b60408051928352602083019190915201610140565b6101d6610312366004611e77565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b61034f61034a366004611eae565b61095c565b60408051825115158152602080840151908201529181015190820152606001610140565b610386610381366004611e00565b610d5e565b60408051938452602084019290925290820152606001610140565b6060600380546103b090611f94565b80601f01602080910402602001604051908101604052809291908181526020018280546103dc90611f94565b80156104275780601f106103fe57610100808354040283529160200191610427565b820191905f5260205f20905b81548152906001019060200180831161040a57829003601f168201915b5050505050905090565b5f3361043e81858561100c565b60019150505b92915050565b5f3361045785828561101e565b610462858585611098565b60019150505b9392505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146104b85760405163c1268d9560e01b815260040160405180910390fd5b5f818060200190518101906104cd9190611fcc565b9050831561056c5761056c8133867f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610537573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061055b9190611fcc565b6001600160a01b03169291906110f5565b82156105d4576105d48133857f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610537573d5f803e3d5ffd5b50505050565b6060600480546103b090611f94565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146106325760405163c1268d9560e01b815260040160405180910390fd5b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa15801561068f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106b39190611fe7565b915091505f7f00000000000000000000000000000000000000000000000000000000000000006106ec576106e7828461201d565b6106f6565b6106f6838361114f565b90505f805160206121a68339815191525c81101561072757604051630b69d15960e11b815260040160405180910390fd5b61072f61125f565b505050505050565b5f3361043e818585611098565b5f808561075081611273565b610758611297565b895f03610778576040516314be162b60e31b815260040160405180910390fd5b6001600160a01b03861661079f5760405163a02b995160e01b815260040160405180910390fd5b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa1580156107fc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108209190611fe7565b915091505f61082e60025490565b905061083b838e836112c1565b9550610848828e836112c1565b9450851580610855575084155b1561087357604051637d81219d60e01b815260040160405180910390fd5b8b861015610894576040516336c87b1160e11b815260040160405180910390fd5b8a8510156108b557604051633651b34b60e21b815260040160405180910390fd5b6108bf338e611380565b6040516301c48a4360e61b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063712290c090610915908990899033908f908f908f9060040161205c565b5f604051808303815f87803b15801561092c575f80fd5b505af115801561093e573d5f803e3d5ffd5b5050505050505061094f6001600555565b5097509795505050505050565b61097f60405180606001604052805f151581526020015f81526020015f81525090565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109c85760405163c1268d9560e01b815260040160405180910390fd5b85604001515f036109ec57604051632d85e30560e21b815260040160405180910390fd5b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa158015610a49573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a6d9190611fe7565b915091505f80895f0151610a82578284610a85565b83835b915091505f7f000000000000000000000000000000000000000000000000000000000000000015610cfd57610aba858561114f565b8b51909150610b05577f0000000000000000000000000000000000000000000000000000000000000000610af684670de0b6b3a764000061201d565b610b0091906120b5565b610b42565b7f0000000000000000000000000000000000000000000000000000000000000000610b3884670de0b6b3a764000061201d565b610b4291906120b5565b8b51909350610b8d577f0000000000000000000000000000000000000000000000000000000000000000610b7e83670de0b6b3a764000061201d565b610b8891906120b5565b610bca565b7f0000000000000000000000000000000000000000000000000000000000000000610bc083670de0b6b3a764000061201d565b610bca91906120b5565b91505f8b5f0151610c1d577f00000000000000000000000000000000000000000000000000000000000000008c60200151670de0b6b3a7640000610c0e919061201d565b610c1891906120b5565b610c60565b7f00000000000000000000000000000000000000000000000000000000000000008c60200151670de0b6b3a7640000610c56919061201d565b610c6091906120b5565b90505f610c77610c7086846120c8565b84866113b8565b610c8190856120db565b9050670de0b6b3a76400008d5f0151610cba577f0000000000000000000000000000000000000000000000000000000000000000610cdc565b7f00000000000000000000000000000000000000000000000000000000000000005b610ce6908361201d565b610cf091906120b5565b602089015250610d389050565b610d07848661201d565b90508a6020015183610d1991906120c8565b60208c0151610d28908461201d565b610d3291906120b5565b60208701525b610d41816114c9565b505060018452505050602090950151604086015250929392505050565b5f805f86610d6b81611273565b610d73611297565b5f610d7d60025490565b9050805f03610dbf578b93508a9250610d9960016103e86114de565b6103e8610dae610da9858761201d565b611512565b610db891906120db565b9450610edf565b5f807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa158015610e1c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e409190611fe7565b915091505f610e508f85856112c1565b90505f610e5e8f86856112c1565b905080821015610e8257819850610e78838a8760016115f6565b96508f9750610e98565b809850610e92848a8760016115f6565b97508e96505b8f881115610eb95760405163071c3a9160e31b815260040160405180910390fd5b8e871115610eda5760405163033c957d60e11b815260040160405180910390fd5b505050505b89851015610f00576040516365b750ff60e01b815260040160405180910390fd5b845f03610f205760405163bde995d360e01b815260040160405180910390fd5b610f2a88866114de565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166341a41e9e8585338b8b33604051602001610f7e91906001600160a01b0391909116815260200190565b6040516020818303038152906040526040518763ffffffff1660e01b8152600401610fae969594939291906120ee565b60408051808303815f875af1158015610fc9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fed9190611fe7565b9094509250610ffe90506001600555565b509750975097945050505050565b6110198383836001611645565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f1981146105d4578181101561108a57604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064015b60405180910390fd5b6105d484848484035f611645565b6001600160a01b0383166110c157604051634b637e8f60e11b81525f6004820152602401611081565b6001600160a01b0382166110ea5760405163ec442f0560e01b81525f6004820152602401611081565b611019838383611717565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526105d490859061183d565b5f807f000000000000000000000000000000000000000000000000000000000000000061118485670de0b6b3a764000061201d565b61118e91906120b5565b90505f7f00000000000000000000000000000000000000000000000000000000000000006111c485670de0b6b3a764000061201d565b6111ce91906120b5565b90505f670de0b6b3a76400006111e4838561201d565b6111ee91906120b5565b90505f670de0b6b3a7640000611204848061201d565b61120e91906120b5565b670de0b6b3a7640000611221868061201d565b61122b91906120b5565b61123591906120c8565b9050670de0b6b3a764000061124a828461201d565b61125491906120b5565b979650505050505050565b5f805160206121a68339815191525f815d50565b8042111561129457604051636ca8dcf160e11b815260040160405180910390fd5b50565b6002600554036112ba57604051633ee5aeb560e01b815260040160405180910390fd5b6002600555565b5f838302815f1985870982811083820303915050805f036112f5578382816112eb576112eb6120a1565b0492505050610468565b8084116113155760405163227bc15360e01b815260040160405180910390fd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6001600160a01b0382166113a957604051634b637e8f60e11b81525f6004820152602401611081565b6113b4825f83611717565b5050565b5f805b60ff8110156114af57825f6113d0878361189e565b90508581101561141f575f6113e5888761193a565b6113ef83896120db565b61140190670de0b6b3a764000061201d565b61140b91906120b5565b905061141781876120c8565b955050611460565b5f61142a888761193a565b61143488846120db565b61144690670de0b6b3a764000061201d565b61145091906120b5565b905061145c81876120db565b9550505b8185111561148957600161147483876120db565b1161148457849350505050610468565b6114a5565b600161149586846120db565b116114a557849350505050610468565b50506001016113bb565b50604051633e3dc24960e21b815260040160405180910390fd5b5f805160206121a683398151915281815d5050565b6001600160a01b0382166115075760405163ec442f0560e01b81525f6004820152602401611081565b6113b45f8383611717565b5f815f0361152157505f919050565b5f600161152d846119a1565b901c6001901b90506001818481611546576115466120a1565b048201901c9050600181848161155e5761155e6120a1565b048201901c90506001818481611576576115766120a1565b048201901c9050600181848161158e5761158e6120a1565b048201901c905060018184816115a6576115a66120a1565b048201901c905060018184816115be576115be6120a1565b048201901c905060018184816115d6576115d66120a1565b048201901c9050610468818285816115f0576115f06120a1565b04611a34565b5f806116038686866112c1565b905061160e83611a49565b801561162957505f8480611624576116246120a1565b868809115b1561163c576116396001826120c8565b90505b95945050505050565b6001600160a01b03841661166e5760405163e602df0560e01b81525f6004820152602401611081565b6001600160a01b03831661169757604051634a1406b160e11b81525f6004820152602401611081565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156105d457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161170991815260200190565b60405180910390a350505050565b6001600160a01b038316611741578060025f82825461173691906120c8565b909155506117b19050565b6001600160a01b0383165f90815260208190526040902054818110156117935760405163391434e360e21b81526001600160a01b03851660048201526024810182905260448101839052606401611081565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b0382166117cd576002805482900390556117eb565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161183091815260200190565b60405180910390a3505050565b5f6118516001600160a01b03841683611a75565b905080515f14158015611875575080806020019051810190611873919061213a565b155b1561101957604051635274afe760e01b81526001600160a01b0384166004820152602401611081565b5f670de0b6b3a7640000828185816118b6828061201d565b6118c091906120b5565b6118ca919061201d565b6118d491906120b5565b6118de919061201d565b6118e891906120b5565b670de0b6b3a76400008084816118fe828061201d565b61190891906120b5565b611912919061201d565b61191c91906120b5565b611926908661201d565b61193091906120b5565b61046891906120c8565b5f670de0b6b3a76400008381611950828061201d565b61195a91906120b5565b611964919061201d565b61196e91906120b5565b670de0b6b3a764000080611982858061201d565b61198c91906120b5565b61199786600361201d565b611926919061201d565b5f80608083901c156119b557608092831c92015b604083901c156119c757604092831c92015b602083901c156119d957602092831c92015b601083901c156119eb57601092831c92015b600883901c156119fd57600892831c92015b600483901c15611a0f57600492831c92015b600283901c15611a2157600292831c92015b600183901c156104445760010192915050565b5f818310611a425781610468565b5090919050565b5f6002826003811115611a5e57611a5e612155565b611a689190612169565b60ff166001149050919050565b606061046883835f845f80856001600160a01b03168486604051611a99919061218a565b5f6040518083038185875af1925050503d805f8114611ad3576040519150601f19603f3d011682016040523d82523d5f602084013e611ad8565b606091505b5091509150611ae8868383611af2565b9695505050505050565b606082611b0757611b0282611b4e565b610468565b8151158015611b1e57506001600160a01b0384163b155b15611b4757604051639996b31560e01b81526001600160a01b0385166004820152602401611081565b5080610468565b805115611b5e5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b5f5b83811015611b91578181015183820152602001611b79565b50505f910152565b5f8151808452611bb0816020860160208601611b77565b601f01601f19169290920160200192915050565b602081525f6104686020830184611b99565b6001600160a01b0381168114611294575f80fd5b5f8060408385031215611bfb575f80fd5b8235611c0681611bd6565b946020939093013593505050565b5f805f60608486031215611c26575f80fd5b8335611c3181611bd6565b92506020840135611c4181611bd6565b929592945050506040919091013590565b634e487b7160e01b5f52604160045260245ffd5b60405160c0810167ffffffffffffffff81118282101715611c8957611c89611c52565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611cb857611cb8611c52565b604052919050565b5f805f60608486031215611cd2575f80fd5b833592506020808501359250604085013567ffffffffffffffff80821115611cf8575f80fd5b818701915087601f830112611d0b575f80fd5b813581811115611d1d57611d1d611c52565b611d2f601f8201601f19168501611c8f565b91508082528884828501011115611d44575f80fd5b80848401858401375f848284010152508093505050509250925092565b5f60208284031215611d71575f80fd5b813561046881611bd6565b8015158114611294575f80fd5b5f805f60608486031215611d9b575f80fd5b8335611da681611d7c565b95602085013595506040909401359392505050565b5f8083601f840112611dcb575f80fd5b50813567ffffffffffffffff811115611de2575f80fd5b602083019150836020828501011115611df9575f80fd5b9250929050565b5f805f805f805f60c0888a031215611e16575f80fd5b873596506020880135955060408801359450606088013593506080880135611e3d81611bd6565b925060a088013567ffffffffffffffff811115611e58575f80fd5b611e648a828b01611dbb565b989b979a50959850939692959293505050565b5f8060408385031215611e88575f80fd5b8235611e9381611bd6565b91506020830135611ea381611bd6565b809150509250929050565b5f805f805f858703610100811215611ec4575f80fd5b60c0811215611ed1575f80fd5b50611eda611c66565b8635611ee581611d7c565b8082525060208701356020820152604087013560408201526060870135611f0b81611bd6565b60608201526080870135611f1e81611bd6565b608082015260a0870135611f3181611bd6565b60a0820152945060c086013567ffffffffffffffff80821115611f52575f80fd5b611f5e89838a01611dbb565b909650945060e0880135915080821115611f76575f80fd5b50611f8388828901611dbb565b969995985093965092949392505050565b600181811c90821680611fa857607f821691505b602082108103611fc657634e487b7160e01b5f52602260045260245ffd5b50919050565b5f60208284031215611fdc575f80fd5b815161046881611bd6565b5f8060408385031215611ff8575f80fd5b505080516020909101519092909150565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761044457610444612009565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b868152602081018690526001600160a01b0385811660408301528416606082015260a0608082018190525f906120959083018486612034565b98975050505050505050565b634e487b7160e01b5f52601260045260245ffd5b5f826120c3576120c36120a1565b500490565b8082018082111561044457610444612009565b8181038181111561044457610444612009565b86815285602082015260018060a01b038516604082015260a060608201525f61211b60a083018587612034565b828103608084015261212d8185611b99565b9998505050505050505050565b5f6020828403121561214a575f80fd5b815161046881611d7c565b634e487b7160e01b5f52602160045260245ffd5b5f60ff83168061217b5761217b6120a1565b8060ff84160691505092915050565b5f825161219b818460208701611b77565b919091019291505056fe52f706286e01e431c0f568fbf950e6f1794322feba1e039f98b8888d605f5707a26469706673582212201c6a57badec4368e2d3d13fe50438bc568278c581f2f6db90914dcff2649c5b664736f6c63430008180033a2646970667358221220c186fb712cdd5436c8b84306143c93f84d1b4659bc04994e46d32124a91b494c64736f6c63430008180033

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

00000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a6030000000000000000000000000000000000000000000000000000000000000005

-----Decoded View---------------
Arg [0] : _protocolFactory (address): 0x29939b3b2aD83882174a50DFD80a3B6329C4a603
Arg [1] : _feeBips (uint256): 5

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 00000000000000000000000029939b3b2ad83882174a50dfd80a3b6329c4a603
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000005


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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.