S Price: $0.457777 (-0.41%)

Contract

0x8e3313C319f4D99b8b91CdAF62bAf9D27874715e

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

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

Contract Source Code Verified (Exact Match)

Contract Name:
FRouter

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 16 : FRouter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import "openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol";

import "./FFactory.sol";
import "./IFPair.sol";

contract FRouter is Initializable, AccessControlUpgradeable, ReentrancyGuardUpgradeable {
    using SafeERC20 for IERC20;

    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
    bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");

    FFactory public factory;
    address public assetToken;

    error ZeroAddressUnallowed();
    error InvalidAmount();

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize(address factory_, address assetToken_) external initializer {
        if (factory_ == address(0) || assetToken_ == address(0)) revert ZeroAddressUnallowed();
        __ReentrancyGuard_init();
        __AccessControl_init();
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);

        factory = FFactory(factory_);
        assetToken = assetToken_;
    }

    function getAmountsOut(address token, address assetToken_, uint256 amountIn)
        public
        view
        returns (uint256 _amountOut)
    {
        if (token == address(0)) revert ZeroAddressUnallowed();

        address pairAddress = factory.getPair(token, assetToken);

        IFPair pair = IFPair(pairAddress);

        (uint256 reserveA, uint256 reserveB) = pair.getReserves();

        uint256 k = pair.kLast();

        uint256 amountOut;

        if (assetToken_ == assetToken) {
            uint256 newReserveB = reserveB + amountIn;

            uint256 newReserveA = k / newReserveB;

            amountOut = reserveA - newReserveA;
        } else {
            uint256 newReserveA = reserveA + amountIn;

            uint256 newReserveB = k / newReserveA;

            amountOut = reserveB - newReserveB;
        }

        return amountOut;
    }

    function addInitialLiquidity(address token_, uint256 amountToken_, uint256 amountAsset_)
        public
        onlyRole(EXECUTOR_ROLE)
        returns (uint256, uint256)
    {
        if (token_ == address(0)) revert ZeroAddressUnallowed();

        address pairAddress = factory.getPair(token_, assetToken);

        IFPair pair = IFPair(pairAddress);

        IERC20 token = IERC20(token_);

        token.safeTransferFrom(msg.sender, pairAddress, amountToken_);

        pair.mint(amountToken_, amountAsset_);

        return (amountToken_, amountAsset_);
    }

    function sell(uint256 amountIn, address tokenAddress, address to)
        public
        nonReentrant
        onlyRole(EXECUTOR_ROLE)
        returns (uint256, uint256)
    {
        if (tokenAddress == address(0) || to == address(0)) revert ZeroAddressUnallowed();

        address pairAddress = factory.getPair(tokenAddress, assetToken);

        IFPair pair = IFPair(pairAddress);

        IERC20 token = IERC20(tokenAddress);

        uint256 amountOut = getAmountsOut(tokenAddress, address(0), amountIn);

        token.safeTransferFrom(to, pairAddress, amountIn);

        uint256 fee = factory.sellTax();
        uint256 txFee = (fee * amountOut) / 100;

        uint256 amount = amountOut - txFee;
        address feeTo = factory.taxVault();

        pair.transferAsset(to, amount);
        pair.transferAsset(feeTo, txFee);

        pair.swap(amountIn, 0, 0, amountOut);

        return (amountIn, amountOut);
    }

    function buy(uint256 amountIn, address tokenAddress, address to)
        public
        onlyRole(EXECUTOR_ROLE)
        nonReentrant
        returns (uint256, uint256)
    {
        if (tokenAddress == address(0) || to == address(0)) revert ZeroAddressUnallowed();
        if (amountIn == 0) revert InvalidAmount();

        address pair = factory.getPair(tokenAddress, assetToken);

        uint256 fee = factory.buyTax();
        uint256 txFee = (fee * amountIn) / 100;
        address feeTo = factory.taxVault();

        uint256 amount = amountIn - txFee;

        IERC20(assetToken).safeTransferFrom(to, pair, amount);

        IERC20(assetToken).safeTransferFrom(to, feeTo, txFee);

        uint256 amountOut = getAmountsOut(tokenAddress, assetToken, amount);

        IFPair(pair).transferTo(to, amountOut);

        IFPair(pair).swap(0, amountOut, amount, 0);

        return (amount, amountOut);
    }

    function launch(address tokenAddress) public onlyRole(EXECUTOR_ROLE) nonReentrant {
        if (tokenAddress == address(0)) revert ZeroAddressUnallowed();
        address pair = factory.getPair(tokenAddress, assetToken);
        uint256 assetBalance = IFPair(pair).assetBalance();
        FPair(pair).transferAsset(msg.sender, assetBalance);
    }

    function approval(address pair, address asset, address spender, uint256 amount)
        public
        onlyRole(EXECUTOR_ROLE)
        nonReentrant
    {
        if (spender == address(0)) revert ZeroAddressUnallowed();

        IFPair(pair).approval(spender, asset, amount);
    }
}

File 2 of 16 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

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

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

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

File 3 of 16 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;


    /// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
    struct AccessControlStorage {
        mapping(bytes32 role => RoleData) _roles;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;

    function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
        assembly {
            $.slot := AccessControlStorageLocation
        }
    }

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        return $._roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        return $._roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        AccessControlStorage storage $ = _getAccessControlStorage();
        bytes32 previousAdminRole = getRoleAdmin(role);
        $._roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (!hasRole(role, account)) {
            $._roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (hasRole(role, account)) {
            $._roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}

File 4 of 16 : 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 5 of 16 : 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 6 of 16 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // 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;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

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

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._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 {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // 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 {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // 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) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}

File 7 of 16 : FFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";

import "./FPair.sol";

contract FFactory is Initializable, AccessControlUpgradeable, ReentrancyGuardUpgradeable {
    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
    bytes32 public constant CREATOR_ROLE = keccak256("CREATOR_ROLE");

    mapping(address => mapping(address => address)) private _pair;

    address[] public pairs;

    address public router;

    address public taxVault;
    uint256 public buyTax;
    uint256 public sellTax;

    event PairCreated(address indexed tokenA, address indexed tokenB, address pair, uint256);

    error ZeroAddressUnallowed();
    error InvalidAmount();
    error RouterDoesNotExist();

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize(address taxVault_, address router_, uint256 buyTax_, uint256 sellTax_) external initializer {
        __AccessControl_init();
        __ReentrancyGuard_init();
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);

        taxVault = taxVault_;
        router = router_;
        buyTax = buyTax_;
        sellTax = sellTax_;
    }

    function _createPair(address tokenA, address tokenB) internal returns (address) {
        if (tokenA == address(0) || tokenB == address(0)) revert ZeroAddressUnallowed();
        if (router == address(0)) revert RouterDoesNotExist();

        FPair pair_ = new FPair(router, tokenA, tokenB);

        _pair[tokenA][tokenB] = address(pair_);
        _pair[tokenB][tokenA] = address(pair_);

        pairs.push(address(pair_));

        uint256 n = pairs.length;

        emit PairCreated(tokenA, tokenB, address(pair_), n);

        return address(pair_);
    }

    function createPair(address tokenA, address tokenB)
        external
        onlyRole(CREATOR_ROLE)
        nonReentrant
        returns (address)
    {
        address pair = _createPair(tokenA, tokenB);

        return pair;
    }

    function getPair(address tokenA, address tokenB) public view returns (address) {
        return _pair[tokenA][tokenB];
    }

    function allPairsLength() public view returns (uint256) {
        return pairs.length;
    }

    function setTaxVault(address newVault) public onlyRole(ADMIN_ROLE) {
        if (newVault == address(0)) revert ZeroAddressUnallowed();
        taxVault = newVault;
    }

    function setSellTax(uint256 newSellTax) public onlyRole(ADMIN_ROLE) {
        if (newSellTax == 0) revert InvalidAmount();
        sellTax = newSellTax;
    }

    function setBuyTax(uint256 newBuyTax) public onlyRole(ADMIN_ROLE) {
        if (newBuyTax == 0) revert InvalidAmount();
        buyTax = newBuyTax;
    }

    function setRouter(address router_) public onlyRole(ADMIN_ROLE) {
        router = router_;
    }
}

File 8 of 16 : IFPair.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IFPair {
    function getReserves() external view returns (uint256, uint256);

    function assetBalance() external view returns (uint256);

    function balance() external view returns (uint256);

    function mint(uint256 reserve0, uint256 reserve1) external returns (bool);

    function transferAsset(address recipient, uint256 amount) external;

    function transferTo(address recipient, uint256 amount) external;

    function swap(uint256 amount0In, uint256 amount0Out, uint256 amount1In, uint256 amount1Out)
        external
        returns (bool);

    function kLast() external view returns (uint256);

    function approval(address _user, address _token, uint256 amount) external returns (bool);
}

File 9 of 16 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}

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

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

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

File 11 of 16 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165Upgradeable is Initializable, IERC165 {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 12 of 16 : 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 13 of 16 : 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 14 of 16 : FPair.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

import "./IFPair.sol";

contract FPair is IFPair, ReentrancyGuard {
    using SafeERC20 for IERC20;

    address public router;
    address public tokenA;
    address public tokenB;

    struct Pool {
        uint256 reserve0;
        uint256 reserve1;
        uint256 k;
        uint256 lastUpdated;
    }

    Pool private _pool;

    event Mint(uint256 reserve0, uint256 reserve1);
    event Swap(uint256 amount0In, uint256 amount0Out, uint256 amount1In, uint256 amount1Out);

    error ZeroAddressUnallowed();
    error Unauthorized();
    error AlreadyMinted();

    constructor(address router_, address token0, address token1) {
        if (router_ == address(0) || token0 == address(0) || token1 == address(0)) revert ZeroAddressUnallowed();

        router = router_;
        tokenA = token0;
        tokenB = token1;
    }

    modifier onlyRouter() {
        if (router != msg.sender) revert Unauthorized();
        _;
    }

    function mint(uint256 reserve0, uint256 reserve1) public onlyRouter returns (bool) {
        if (_pool.lastUpdated != 0) revert AlreadyMinted();

        _pool = Pool({reserve0: reserve0, reserve1: reserve1, k: reserve0 * reserve1, lastUpdated: block.timestamp});

        emit Mint(reserve0, reserve1);

        return true;
    }

    function swap(uint256 amount0In, uint256 amount0Out, uint256 amount1In, uint256 amount1Out)
        public
        onlyRouter
        returns (bool)
    {
        uint256 _reserve0 = (_pool.reserve0 + amount0In) - amount0Out;
        uint256 _reserve1 = (_pool.reserve1 + amount1In) - amount1Out;

        _pool = Pool({reserve0: _reserve0, reserve1: _reserve1, k: _pool.k, lastUpdated: block.timestamp});

        emit Swap(amount0In, amount0Out, amount1In, amount1Out);

        return true;
    }

    function getPoolInfo() public returns (Pool memory) {
        return _pool;
    }

    function approval(address _user, address _token, uint256 amount) public onlyRouter returns (bool) {
        if (_user == address(0) || _token == address(0)) revert ZeroAddressUnallowed();

        IERC20 token = IERC20(_token);

        token.forceApprove(_user, amount);

        return true;
    }

    function transferAsset(address recipient, uint256 amount) public onlyRouter {
        if (recipient == address(0)) revert ZeroAddressUnallowed();

        IERC20(tokenB).safeTransfer(recipient, amount);
    }

    function transferTo(address recipient, uint256 amount) public onlyRouter {
        if (recipient == address(0)) revert ZeroAddressUnallowed();

        IERC20(tokenA).safeTransfer(recipient, amount);
    }

    function getReserves() public view returns (uint256, uint256) {
        return (_pool.reserve0, _pool.reserve1);
    }

    function kLast() public view returns (uint256) {
        return _pool.k;
    }

    function priceALast() public view returns (uint256) {
        return _pool.reserve1 / _pool.reserve0;
    }

    function priceBLast() public view returns (uint256) {
        return _pool.reserve0 / _pool.reserve1;
    }

    function balance() public view returns (uint256) {
        return IERC20(tokenA).balanceOf(address(this));
    }

    function assetBalance() public view returns (uint256) {
        return IERC20(tokenB).balanceOf(address(this));
    }
}

File 15 of 16 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

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

File 16 of 16 : 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;
    }
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"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":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"ZeroAddressUnallowed","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"inputs":[],"name":"ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EXECUTOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"uint256","name":"amountToken_","type":"uint256"},{"internalType":"uint256","name":"amountAsset_","type":"uint256"}],"name":"addInitialLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approval","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"assetToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"to","type":"address"}],"name":"buy","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract FFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"assetToken_","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256","name":"_amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"factory_","type":"address"},{"internalType":"address","name":"assetToken_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"launch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"to","type":"address"}],"name":"sell","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b5061001961001e565b6100d0565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff161561006e5760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100cd5780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b6119bc806100df6000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c80636f08e177116100a2578063ab3c475a11610071578063ab3c475a1461026f578063ba37fd3814610282578063c45a015514610295578063d547741f146102a8578063e753858a146102bb57600080fd5b80636f08e1771461020557806375b238fc1461022d57806391d1485414610254578063a217fddf1461026757600080fd5b8063248a9ca3116100e9578063248a9ca3146101a65780632f2ff15d146101b957806336568abe146101cc57806345608d00146101df578063485cc955146101f257600080fd5b806301ffc9a71461011b57806307bd0265146101435780631083f76114610166578063214013ca14610191575b600080fd5b61012e61012936600461162a565b6102ce565b60405190151581526020015b60405180910390f35b61015860008051602061194783398151915281565b60405190815260200161013a565b600154610179906001600160a01b031681565b6040516001600160a01b03909116815260200161013a565b6101a461019f366004611669565b610305565b005b6101586101b4366004611686565b6104ab565b6101a46101c736600461169f565b6104cd565b6101a46101da36600461169f565b6104ef565b6101586101ed3660046116cf565b610527565b6101a4610200366004611710565b610721565b61021861021336600461173e565b6108b0565b6040805192835260208301919091520161013a565b6101587fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177581565b61012e61026236600461169f565b610c4b565b610158600081565b6101a461027d366004611780565b610c83565b6102186102903660046117d1565b610d64565b600054610179906001600160a01b031681565b6101a46102b636600461169f565b610ebe565b6102186102c936600461173e565b610eda565b60006001600160e01b03198216637965db0b60e01b14806102ff57506301ffc9a760e01b6001600160e01b03198316145b92915050565b60008051602061194783398151915261031d81611243565b610325611250565b6001600160a01b03821661034c576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038681166004830152918216602482015291169063e6a4390590604401602060405180830381865afa1580156103a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103c59190611806565b90506000816001600160a01b031663c66f24556040518163ffffffff1660e01b8152600401602060405180830381865afa158015610407573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061042b9190611823565b604051635c921eb960e01b8152336004820152602481018290529091506001600160a01b03831690635c921eb990604401600060405180830381600087803b15801561047657600080fd5b505af115801561048a573d6000803e3d6000fd5b5050505050506104a7600160008051602061196783398151915255565b5050565b6000908152600080516020611927833981519152602052604090206001015490565b6104d6826104ab565b6104df81611243565b6104e9838361129c565b50505050565b6001600160a01b03811633146105185760405163334bd91960e11b815260040160405180910390fd5b6105228282611341565b505050565b60006001600160a01b038416610550576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038881166004830152918216602482015291169063e6a4390590604401602060405180830381865afa1580156105a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105c99190611806565b90506000819050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa158015610610573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610634919061183c565b915091506000836001600160a01b0316637464fc3d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610678573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061069c9190611823565b6001549091506000906001600160a01b03908116908a16036106e75760006106c48985611876565b905060006106d28285611889565b90506106de81876118ab565b92505050610712565b60006106f38986611876565b905060006107018285611889565b905061070d81866118ab565b925050505b955050505050505b9392505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff166000811580156107675750825b905060008267ffffffffffffffff1660011480156107845750303b155b905081158015610792575080155b156107b05760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff1916600117855583156107da57845460ff60401b1916600160401b1785555b6001600160a01b03871615806107f757506001600160a01b038616155b15610815576040516310f73e1360e21b815260040160405180910390fd5b61081d6113bd565b6108256113cf565b61083060003361129c565b50600080546001600160a01b03808a166001600160a01b031992831617909255600180549289169290911691909117905583156108a757845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b6000806108bb611250565b6000805160206119478339815191526108d381611243565b6001600160a01b03851615806108f057506001600160a01b038416155b1561090e576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038981166004830152918216602482015291169063e6a4390590604401602060405180830381865afa158015610963573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109879190611806565b90508086600061099882828c610527565b90506109af6001600160a01b03831689868d6113d7565b60008060009054906101000a90046001600160a01b03166001600160a01b031663cc1776d36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a279190611823565b905060006064610a3784846118be565b610a419190611889565b90506000610a4f82856118ab565b905060008060009054906101000a90046001600160a01b03166001600160a01b031663e2ad37b06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610aa5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac99190611806565b604051635c921eb960e01b81526001600160a01b038e811660048301526024820185905291925090881690635c921eb990604401600060405180830381600087803b158015610b1757600080fd5b505af1158015610b2b573d6000803e3d6000fd5b5050604051635c921eb960e01b81526001600160a01b038481166004830152602482018790528a169250635c921eb99150604401600060405180830381600087803b158015610b7957600080fd5b505af1158015610b8d573d6000803e3d6000fd5b50505050866001600160a01b0316635673b02d8f600080896040518563ffffffff1660e01b8152600401610bda949392919093845260208401929092526040830152606082015260800190565b6020604051808303816000875af1158015610bf9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1d91906118d5565b508d9a509398505050505050505050610c43600160008051602061196783398151915255565b935093915050565b6000918252600080516020611927833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600080516020611947833981519152610c9b81611243565b610ca3611250565b6001600160a01b038316610cca576040516310f73e1360e21b815260040160405180910390fd5b604051632e2952f960e11b81526001600160a01b038481166004830152858116602483015260448201849052861690635c52a5f2906064016020604051808303816000875af1158015610d21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4591906118d5565b50610d5d600160008051602061196783398151915255565b5050505050565b600080600080516020611947833981519152610d7f81611243565b6001600160a01b038616610da6576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038a81166004830152918216602482015291169063e6a4390590604401602060405180830381865afa158015610dfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e1f9190611806565b90508087610e386001600160a01b03821633848b6113d7565b604051630d9778e560e11b815260048101899052602481018890526001600160a01b03831690631b2ef1ca906044016020604051808303816000875af1158015610e86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eaa91906118d5565b508787955095505050505b50935093915050565b610ec7826104ab565b610ed081611243565b6104e98383611341565b600080600080516020611947833981519152610ef581611243565b610efd611250565b6001600160a01b0385161580610f1a57506001600160a01b038416155b15610f38576040516310f73e1360e21b815260040160405180910390fd5b85600003610f595760405163162908e360e11b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038981166004830152918216602482015291169063e6a4390590604401602060405180830381865afa158015610fae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd29190611806565b905060008060009054906101000a90046001600160a01b03166001600160a01b0316634f7041a56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611028573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061104c9190611823565b90506000606461105c8a846118be565b6110669190611889565b905060008060009054906101000a90046001600160a01b03166001600160a01b031663e2ad37b06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e09190611806565b905060006110ee838c6118ab565b600154909150611109906001600160a01b03168a87846113d7565b600154611121906001600160a01b03168a84866113d7565b60015460009061113c908c906001600160a01b031684610527565b6040516302ccb1b360e41b81526001600160a01b038c811660048301526024820183905291925090871690632ccb1b3090604401600060405180830381600087803b15801561118a57600080fd5b505af115801561119e573d6000803e3d6000fd5b5050604051635673b02d60e01b8152600060048201819052602482018590526044820186905260648201526001600160a01b0389169250635673b02d91506084016020604051808303816000875af11580156111fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122291906118d5565b50909750955050505050610eb5600160008051602061196783398151915255565b61124d8133611431565b50565b60008051602061196783398151915280546001190161128257604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b600160008051602061196783398151915255565b60006000805160206119278339815191526112b78484610c4b565b611337576000848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556112ed3390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a460019150506102ff565b60009150506102ff565b600060008051602061192783398151915261135c8484610c4b565b15611337576000848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a460019150506102ff565b6113c561146f565b6113cd6114b8565b565b6113cd61146f565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526104e99085906114c0565b61143b8282610c4b565b6104a75760405163e2517d3f60e01b81526001600160a01b0382166004820152602481018390526044015b60405180910390fd5b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff166113cd57604051631afcd79f60e31b815260040160405180910390fd5b61128861146f565b60006114d56001600160a01b03841683611523565b905080516000141580156114fa5750808060200190518101906114f891906118d5565b155b1561052257604051635274afe760e01b81526001600160a01b0384166004820152602401611466565b606061071a8383600084600080856001600160a01b0316848660405161154991906118f7565b60006040518083038185875af1925050503d8060008114611586576040519150601f19603f3d011682016040523d82523d6000602084013e61158b565b606091505b509150915061159b8683836115a5565b9695505050505050565b6060826115ba576115b582611601565b61071a565b81511580156115d157506001600160a01b0384163b155b156115fa57604051639996b31560e01b81526001600160a01b0385166004820152602401611466565b508061071a565b8051156116115780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60006020828403121561163c57600080fd5b81356001600160e01b03198116811461071a57600080fd5b6001600160a01b038116811461124d57600080fd5b60006020828403121561167b57600080fd5b813561071a81611654565b60006020828403121561169857600080fd5b5035919050565b600080604083850312156116b257600080fd5b8235915060208301356116c481611654565b809150509250929050565b6000806000606084860312156116e457600080fd5b83356116ef81611654565b925060208401356116ff81611654565b929592945050506040919091013590565b6000806040838503121561172357600080fd5b823561172e81611654565b915060208301356116c481611654565b60008060006060848603121561175357600080fd5b83359250602084013561176581611654565b9150604084013561177581611654565b809150509250925092565b6000806000806080858703121561179657600080fd5b84356117a181611654565b935060208501356117b181611654565b925060408501356117c181611654565b9396929550929360600135925050565b6000806000606084860312156117e657600080fd5b83356117f181611654565b95602085013595506040909401359392505050565b60006020828403121561181857600080fd5b815161071a81611654565b60006020828403121561183557600080fd5b5051919050565b6000806040838503121561184f57600080fd5b505080516020909101519092909150565b634e487b7160e01b600052601160045260246000fd5b808201808211156102ff576102ff611860565b6000826118a657634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156102ff576102ff611860565b80820281158282048414176102ff576102ff611860565b6000602082840312156118e757600080fd5b8151801515811461071a57600080fd5b6000825160005b8181101561191857602081860181015185830152016118fe565b50600092019182525091905056fe02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800d8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e639b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220e2d17a33e4a7b235d15297a37c3ba5277f369b76ac244c01be166ba762a26d4664736f6c63430008140033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101165760003560e01c80636f08e177116100a2578063ab3c475a11610071578063ab3c475a1461026f578063ba37fd3814610282578063c45a015514610295578063d547741f146102a8578063e753858a146102bb57600080fd5b80636f08e1771461020557806375b238fc1461022d57806391d1485414610254578063a217fddf1461026757600080fd5b8063248a9ca3116100e9578063248a9ca3146101a65780632f2ff15d146101b957806336568abe146101cc57806345608d00146101df578063485cc955146101f257600080fd5b806301ffc9a71461011b57806307bd0265146101435780631083f76114610166578063214013ca14610191575b600080fd5b61012e61012936600461162a565b6102ce565b60405190151581526020015b60405180910390f35b61015860008051602061194783398151915281565b60405190815260200161013a565b600154610179906001600160a01b031681565b6040516001600160a01b03909116815260200161013a565b6101a461019f366004611669565b610305565b005b6101586101b4366004611686565b6104ab565b6101a46101c736600461169f565b6104cd565b6101a46101da36600461169f565b6104ef565b6101586101ed3660046116cf565b610527565b6101a4610200366004611710565b610721565b61021861021336600461173e565b6108b0565b6040805192835260208301919091520161013a565b6101587fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177581565b61012e61026236600461169f565b610c4b565b610158600081565b6101a461027d366004611780565b610c83565b6102186102903660046117d1565b610d64565b600054610179906001600160a01b031681565b6101a46102b636600461169f565b610ebe565b6102186102c936600461173e565b610eda565b60006001600160e01b03198216637965db0b60e01b14806102ff57506301ffc9a760e01b6001600160e01b03198316145b92915050565b60008051602061194783398151915261031d81611243565b610325611250565b6001600160a01b03821661034c576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038681166004830152918216602482015291169063e6a4390590604401602060405180830381865afa1580156103a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103c59190611806565b90506000816001600160a01b031663c66f24556040518163ffffffff1660e01b8152600401602060405180830381865afa158015610407573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061042b9190611823565b604051635c921eb960e01b8152336004820152602481018290529091506001600160a01b03831690635c921eb990604401600060405180830381600087803b15801561047657600080fd5b505af115801561048a573d6000803e3d6000fd5b5050505050506104a7600160008051602061196783398151915255565b5050565b6000908152600080516020611927833981519152602052604090206001015490565b6104d6826104ab565b6104df81611243565b6104e9838361129c565b50505050565b6001600160a01b03811633146105185760405163334bd91960e11b815260040160405180910390fd5b6105228282611341565b505050565b60006001600160a01b038416610550576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038881166004830152918216602482015291169063e6a4390590604401602060405180830381865afa1580156105a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105c99190611806565b90506000819050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b81526004016040805180830381865afa158015610610573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610634919061183c565b915091506000836001600160a01b0316637464fc3d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610678573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061069c9190611823565b6001549091506000906001600160a01b03908116908a16036106e75760006106c48985611876565b905060006106d28285611889565b90506106de81876118ab565b92505050610712565b60006106f38986611876565b905060006107018285611889565b905061070d81866118ab565b925050505b955050505050505b9392505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff166000811580156107675750825b905060008267ffffffffffffffff1660011480156107845750303b155b905081158015610792575080155b156107b05760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff1916600117855583156107da57845460ff60401b1916600160401b1785555b6001600160a01b03871615806107f757506001600160a01b038616155b15610815576040516310f73e1360e21b815260040160405180910390fd5b61081d6113bd565b6108256113cf565b61083060003361129c565b50600080546001600160a01b03808a166001600160a01b031992831617909255600180549289169290911691909117905583156108a757845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b6000806108bb611250565b6000805160206119478339815191526108d381611243565b6001600160a01b03851615806108f057506001600160a01b038416155b1561090e576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038981166004830152918216602482015291169063e6a4390590604401602060405180830381865afa158015610963573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109879190611806565b90508086600061099882828c610527565b90506109af6001600160a01b03831689868d6113d7565b60008060009054906101000a90046001600160a01b03166001600160a01b031663cc1776d36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a279190611823565b905060006064610a3784846118be565b610a419190611889565b90506000610a4f82856118ab565b905060008060009054906101000a90046001600160a01b03166001600160a01b031663e2ad37b06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610aa5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac99190611806565b604051635c921eb960e01b81526001600160a01b038e811660048301526024820185905291925090881690635c921eb990604401600060405180830381600087803b158015610b1757600080fd5b505af1158015610b2b573d6000803e3d6000fd5b5050604051635c921eb960e01b81526001600160a01b038481166004830152602482018790528a169250635c921eb99150604401600060405180830381600087803b158015610b7957600080fd5b505af1158015610b8d573d6000803e3d6000fd5b50505050866001600160a01b0316635673b02d8f600080896040518563ffffffff1660e01b8152600401610bda949392919093845260208401929092526040830152606082015260800190565b6020604051808303816000875af1158015610bf9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1d91906118d5565b508d9a509398505050505050505050610c43600160008051602061196783398151915255565b935093915050565b6000918252600080516020611927833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600080516020611947833981519152610c9b81611243565b610ca3611250565b6001600160a01b038316610cca576040516310f73e1360e21b815260040160405180910390fd5b604051632e2952f960e11b81526001600160a01b038481166004830152858116602483015260448201849052861690635c52a5f2906064016020604051808303816000875af1158015610d21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4591906118d5565b50610d5d600160008051602061196783398151915255565b5050505050565b600080600080516020611947833981519152610d7f81611243565b6001600160a01b038616610da6576040516310f73e1360e21b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038a81166004830152918216602482015291169063e6a4390590604401602060405180830381865afa158015610dfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e1f9190611806565b90508087610e386001600160a01b03821633848b6113d7565b604051630d9778e560e11b815260048101899052602481018890526001600160a01b03831690631b2ef1ca906044016020604051808303816000875af1158015610e86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eaa91906118d5565b508787955095505050505b50935093915050565b610ec7826104ab565b610ed081611243565b6104e98383611341565b600080600080516020611947833981519152610ef581611243565b610efd611250565b6001600160a01b0385161580610f1a57506001600160a01b038416155b15610f38576040516310f73e1360e21b815260040160405180910390fd5b85600003610f595760405163162908e360e11b815260040160405180910390fd5b6000805460015460405163e6a4390560e01b81526001600160a01b038981166004830152918216602482015291169063e6a4390590604401602060405180830381865afa158015610fae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd29190611806565b905060008060009054906101000a90046001600160a01b03166001600160a01b0316634f7041a56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611028573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061104c9190611823565b90506000606461105c8a846118be565b6110669190611889565b905060008060009054906101000a90046001600160a01b03166001600160a01b031663e2ad37b06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e09190611806565b905060006110ee838c6118ab565b600154909150611109906001600160a01b03168a87846113d7565b600154611121906001600160a01b03168a84866113d7565b60015460009061113c908c906001600160a01b031684610527565b6040516302ccb1b360e41b81526001600160a01b038c811660048301526024820183905291925090871690632ccb1b3090604401600060405180830381600087803b15801561118a57600080fd5b505af115801561119e573d6000803e3d6000fd5b5050604051635673b02d60e01b8152600060048201819052602482018590526044820186905260648201526001600160a01b0389169250635673b02d91506084016020604051808303816000875af11580156111fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122291906118d5565b50909750955050505050610eb5600160008051602061196783398151915255565b61124d8133611431565b50565b60008051602061196783398151915280546001190161128257604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b600160008051602061196783398151915255565b60006000805160206119278339815191526112b78484610c4b565b611337576000848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556112ed3390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a460019150506102ff565b60009150506102ff565b600060008051602061192783398151915261135c8484610c4b565b15611337576000848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a460019150506102ff565b6113c561146f565b6113cd6114b8565b565b6113cd61146f565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526104e99085906114c0565b61143b8282610c4b565b6104a75760405163e2517d3f60e01b81526001600160a01b0382166004820152602481018390526044015b60405180910390fd5b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff166113cd57604051631afcd79f60e31b815260040160405180910390fd5b61128861146f565b60006114d56001600160a01b03841683611523565b905080516000141580156114fa5750808060200190518101906114f891906118d5565b155b1561052257604051635274afe760e01b81526001600160a01b0384166004820152602401611466565b606061071a8383600084600080856001600160a01b0316848660405161154991906118f7565b60006040518083038185875af1925050503d8060008114611586576040519150601f19603f3d011682016040523d82523d6000602084013e61158b565b606091505b509150915061159b8683836115a5565b9695505050505050565b6060826115ba576115b582611601565b61071a565b81511580156115d157506001600160a01b0384163b155b156115fa57604051639996b31560e01b81526001600160a01b0385166004820152602401611466565b508061071a565b8051156116115780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60006020828403121561163c57600080fd5b81356001600160e01b03198116811461071a57600080fd5b6001600160a01b038116811461124d57600080fd5b60006020828403121561167b57600080fd5b813561071a81611654565b60006020828403121561169857600080fd5b5035919050565b600080604083850312156116b257600080fd5b8235915060208301356116c481611654565b809150509250929050565b6000806000606084860312156116e457600080fd5b83356116ef81611654565b925060208401356116ff81611654565b929592945050506040919091013590565b6000806040838503121561172357600080fd5b823561172e81611654565b915060208301356116c481611654565b60008060006060848603121561175357600080fd5b83359250602084013561176581611654565b9150604084013561177581611654565b809150509250925092565b6000806000806080858703121561179657600080fd5b84356117a181611654565b935060208501356117b181611654565b925060408501356117c181611654565b9396929550929360600135925050565b6000806000606084860312156117e657600080fd5b83356117f181611654565b95602085013595506040909401359392505050565b60006020828403121561181857600080fd5b815161071a81611654565b60006020828403121561183557600080fd5b5051919050565b6000806040838503121561184f57600080fd5b505080516020909101519092909150565b634e487b7160e01b600052601160045260246000fd5b808201808211156102ff576102ff611860565b6000826118a657634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156102ff576102ff611860565b80820281158282048414176102ff576102ff611860565b6000602082840312156118e757600080fd5b8151801515811461071a57600080fd5b6000825160005b8181101561191857602081860181015185830152016118fe565b50600092019182525091905056fe02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800d8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e639b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220e2d17a33e4a7b235d15297a37c3ba5277f369b76ac244c01be166ba762a26d4664736f6c63430008140033

Block Transaction Gas Used Reward
view all blocks ##produced##

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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.