Skip to content
Verified contractExactMIT

JITLPExecutor

Address0x17aef3201d0cd7942d334b1bf8831f19eea6d4e0
Balance

0.000913 ETH

 

Transactions

2

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,346,715
Creation transaction
0x3bf5c615bc…4c27572e06

contracts/JITLPExecutor.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * JITLPExecutor (Stateless Executor)
 * - Single generic executor contract that can call:
 *   - Uniswap v2 pairs (mint/burn/swap/skim/sync/etc.)
 *   - Uniswap v3 periphery (NonfungiblePositionManager mint/increase/decrease/collect, etc.)
 * - Strategy, sizing, tick/range math, routing are ALL off-chain.
 * - This contract stores no strategy state—only access control + safety guards.
 *
 * MVP mode: use it for v2 JIT LP first, then v3 later without redeploy.
 */

interface IERC20 {
    function balanceOf(address a) external view returns (uint256);
    function transfer(address to, uint256 amt) external returns (bool);
}

contract JITLPExecutor {
    // -----------------------------
    // Ownership (minimal Ownable)
    // -----------------------------
    address public owner;

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

    modifier onlyOwner() {
        require(msg.sender == owner, "JITLPExecutor: not owner");
        _;
    }

    // -----------------------------
    // Reentrancy guard (minimal)
    // -----------------------------
    uint256 private _locked = 1;
    modifier nonReentrant() {
        require(_locked == 1, "JITLPExecutor: reentrant");
        _locked = 2;
        _;
        _locked = 1;
    }

    // -----------------------------
    // Events
    // -----------------------------
    event Executed(address indexed target, uint256 value, bytes data, bytes result);
    event BatchExecuted(uint256 count);
    event RescueToken(address indexed token, address indexed to, uint256 amount);
    event RescueETH(address indexed to, uint256 amount);

    constructor(address _owner) {
        require(_owner != address(0), "JITLPExecutor: owner=0");
        owner = _owner;
        emit OwnershipTransferred(address(0), _owner);
    }

    // Accept ETH (needed for WETH unwrap flows, bribes via separate tx, or periphery calls that require msg.value)
    receive() external payable {}
    fallback() external payable {}

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "JITLPExecutor: owner=0");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }

    /**
     * Execute a single external call.
     * @param target Contract to call (e.g., UniswapV2Pair, NonfungiblePositionManager, WETH, Router, etc.)
     * @param value  ETH value to send with the call (usually 0; sometimes needed for v3 periphery)
     * @param data   Calldata to forward
     */
    function execute(address target, uint256 value, bytes calldata data)
        external
        onlyOwner
        nonReentrant
        returns (bytes memory result)
    {
        require(target != address(0), "JITLPExecutor: target=0");
        (bool ok, bytes memory res) = target.call{value: value}(data);
        if (!ok) _revertWith(res);
        emit Executed(target, value, data, res);
        return res;
    }

    /**
     * Execute multiple calls atomically (same tx).
     * Typical JIT LP sequencing can be done off-chain by building the correct bundle ordering,
     * but this is useful for "mint -> burn -> collect" within a single tx if desired.
     *
     * @dev targets.length == values.length == data.length
     */
    function executeBatch(
        address[] calldata targets,
        uint256[] calldata values,
        bytes[] calldata data
    )
        external
        onlyOwner
        nonReentrant
        returns (bytes[] memory results)
    {
        uint256 n = targets.length;
        require(n == values.length && n == data.length, "JITLPExecutor: len mismatch");
        results = new bytes[](n);

        for (uint256 i = 0; i < n; i++) {
            address t = targets[i];
            require(t != address(0), "JITLPExecutor: target=0");
            (bool ok, bytes memory res) = t.call{value: values[i]}(data[i]);
            if (!ok) _revertWith(res);
            results[i] = res;
            emit Executed(t, values[i], data[i], res);
        }

        emit BatchExecuted(n);
        return results;
    }

    /**
     * Rescue ERC20 token balances accidentally left in the executor.
     * This is a safety hatch only—your normal flow should keep balances minimal.
     */
    function rescueToken(address token, address to, uint256 amount) external onlyOwner nonReentrant {
        require(token != address(0), "JITLPExecutor: token=0");
        require(to != address(0), "JITLPExecutor: to=0");

        // Optional: clamp to balance if amount==type(uint256).max style not provided
        uint256 bal = IERC20(token).balanceOf(address(this));
        uint256 amt = amount > bal ? bal : amount;

        require(IERC20(token).transfer(to, amt), "JITLPExecutor: transfer failed");
        emit RescueToken(token, to, amt);
    }

    /**
     * Rescue ETH balances accidentally left in the executor.
     */
    function rescueETH(address payable to, uint256 amount) external onlyOwner nonReentrant {
        require(to != address(0), "JITLPExecutor: to=0");
        uint256 bal = address(this).balance;
        uint256 amt = amount > bal ? bal : amount;

        (bool ok, ) = to.call{value: amt}("");
        require(ok, "JITLPExecutor: eth transfer failed");
        emit RescueETH(to, amt);
    }

    // -----------------------------
    // Internal helpers
    // -----------------------------
    function _revertWith(bytes memory res) internal pure {
        // Bubble up revert reason from target if present
        if (res.length > 0) {
            assembly {
                revert(add(res, 32), mload(res))
            }
        } else {
            revert("JITLPExecutor: call failed");
        }
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.