Skip to content
Verified contractPartialMIT

PegKeeperCaller

Address0x7f37e4c181b96ac59e9780ab7ddd730ffb2e5a78
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,415,634
Creation transaction
0x73fba4f636…01dc51fe94

src/PegKeeperCaller.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

// 2026-10-11 pkfix FIX1 (Ahmet onayı): genel crvUSD PegKeeper helper'ı.
// update(owner) LP'yi doğrudan owner'a basar; kontratta fon tutulmaz. No-op (LP=0) -> REVERT
// "noprofit" => revert eden tx bundle'dan düşer (no-revert bundle yolu). Tip msg.value'dan
// coinbase'e gider (OlympusBeatSniper.snipe kalıbı). Reentrancy: owner sabit, harici çağrılar
// yalnız keeper/pool; checks-effects sırasına dikkat edildi.
interface IPegKeeper {
    function update(address) external returns (uint256);
    function pool() external view returns (address);
}

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


interface ICurvePool {
    function coins(uint256) external view returns (address);
    function remove_liquidity_one_coin(uint256 amount, int128 i, uint256 minDy) external returns (uint256);
}

interface IUniswapV3Pool {
    function token0() external view returns (address);
    function token1() external view returns (address);
    function fee() external view returns (uint24);
    function factory() external view returns (address);
    function swap(address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data)
        external
        returns (int256, int256);
}

interface IV3Factory {
    function getPool(address, address, uint24) external view returns (address);
}

interface IWETH {
    function balanceOf(address) external view returns (uint256);
    function withdraw(uint256) external;
}

// t6208 (Ahmet 14 Kas 23:19 onayı): _payV3 güvenlik düzeltmesi.
//  - Callback yalnız bu tx içinde swap'ı başlatılan havuzdan kabul edilir (transient POOL slot),
//    havuz Uni/Pancake/Sushi V3 factory.getPool(coin,WETH,fee) ile doğrulanır, coin calldata'dan
//    değil transient slottan okunur, yalnız coin tarafındaki pozitif delta ödenir, slot tek kullanımlık.
//  - callUpdate / callUpdateCycle transient reentrancy kilidi.
contract PegKeeperCaller {
    address public immutable owner;

    address internal constant UNI_V3_FACTORY = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
    address internal constant PANCAKE_V3_FACTORY = 0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865;
    address internal constant SUSHI_V3_FACTORY = 0xbACEB8eC6b9355Dfc0269C18bac9d6E2Bdc29C4F;
    // transient storage slotları (EIP-1153, cancun)
    uint256 internal constant T_LOCK = uint256(keccak256("t6208.pk.lock"));
    uint256 internal constant T_POOL = uint256(keccak256("t6208.pk.pool"));
    uint256 internal constant T_COIN = uint256(keccak256("t6208.pk.coin"));

    error BadCallback();
    error BadPool();
    error Reentrancy();

    modifier nonReentrant() {
        _lock();
        _;
        _unlock();
    }

    function _lock() private {
        uint256 slot = T_LOCK;
        uint256 l;
        assembly { l := tload(slot) }
        if (l != 0) revert Reentrancy();
        assembly { tstore(slot, 1) }
    }

    function _unlock() private {
        uint256 slot = T_LOCK;
        assembly { tstore(slot, 0) }
    }

    constructor() {
        owner = msg.sender;
    }

    /// keeper: herhangi bir crvUSD PegKeeper (V2: pool() + update(address)).
    /// minLp: owner'a gelmesi gereken min LP (no-op => revert). tipWei: block.coinbase payı.
    /// maxBlock: bu bloktan sonra çağrı reddedilir (bayat işlem koruması). Artan value owner'a iade.
    function callUpdate(address keeper, uint256 minLp, uint256 tipWei, uint256 maxBlock)
        external
        payable
        nonReentrant
        returns (uint256 lp)
    {
        require(msg.sender == owner, "owner");
        require(block.number <= maxBlock, "late");
        require(minLp > 0, "minLp");
        require(msg.value >= tipWei, "tip");

        address pool = IPegKeeper(keeper).pool();
        uint256 b0 = IERC20(pool).balanceOf(owner);

        // dönüş değerine güvenme; bakiye farkı esas
        IPegKeeper(keeper).update(owner);

        lp = IERC20(pool).balanceOf(owner) - b0;
        require(lp >= minLp, "noprofit"); // no-op => REVERT (bundle'dan düşer)

        if (tipWei > 0) {
            (bool ok, ) = block.coinbase.call{value: tipWei}("");
            require(ok, "cb");
        }
        uint256 refund = msg.value - tipWei;
        if (refund > 0) {
            (bool ok2, ) = owner.call{value: refund}("");
            require(ok2, "ref");
        }
    }

    // t6008 native cycle: WETH on Ethereum. USDT/USDC -> WETH Uni V3 (token0 may be either).
    address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    uint256 internal constant GAS_OVERHEAD = 80_000;
    uint160 internal constant MIN_SQRT = 4295128740;
    uint160 internal constant MAX_SQRT = 1461446703485210103287273052203988822378723970341;

    error NetLow(uint256 ethOut, uint256 gasCost, uint256 tipWei, uint256 minProfit);
    error Pay();

    receive() external payable {}

    /// t6008: update(this) + remove_liquidity_one_coin(coinIndex) + Uni V3 coin->WETH + unwrap.
    /// Tip and gas come from the reward (msg.value not used). Reverts if ethOut < gasCost+tip+minProfit.
    /// minProfitWei must be > 0 (bot passes >= $0.05). coinIndex 0 = USDT/USDC on the two live keepers.
    function callUpdateCycle(
        address keeper,
        uint256 minLp,
        uint256 tipWei,
        uint256 maxBlock,
        uint256 minProfitWei,
        int128 coinIndex,
        address v3Pool
    ) external nonReentrant returns (uint256 lp) {
        uint256 gasStart = gasleft();
        require(msg.sender == owner, "owner");
        require(block.number <= maxBlock, "late");
        require(minLp > 0, "minLp");
        require(minProfitWei > 0, "minProfit");
        require(v3Pool != address(0), "pool");
        require(coinIndex >= 0, "i");

        address curvePool = IPegKeeper(keeper).pool();
        uint256 b0 = IERC20(curvePool).balanceOf(address(this));
        IPegKeeper(keeper).update(address(this));
        lp = IERC20(curvePool).balanceOf(address(this)) - b0;
        require(lp >= minLp, "noprofit");

        ICurvePool(curvePool).remove_liquidity_one_coin(lp, coinIndex, 0);
        address coin = ICurvePool(curvePool).coins(uint256(int256(coinIndex)));
        uint256 amt = IERC20(coin).balanceOf(address(this));
        if (amt > 0) _swapToWeth(v3Pool, coin, amt);

        uint256 w = IWETH(WETH).balanceOf(address(this));
        if (w > 0) IWETH(WETH).withdraw(w);

        uint256 ethOut = address(this).balance;
        uint256 gasCost = (gasStart - gasleft() + GAS_OVERHEAD) * tx.gasprice;
        if (ethOut < gasCost + tipWei + minProfitWei) {
            revert NetLow(ethOut, gasCost, tipWei, minProfitWei);
        }
        if (tipWei > 0) {
            (bool ok, ) = block.coinbase.call{value: tipWei}("");
            if (!ok) revert Pay();
        }
        uint256 send = address(this).balance;
        if (send > 0) {
            (bool ok2, ) = owner.call{value: send}("");
            if (!ok2) revert Pay();
        }
    }

    function uniswapV3SwapCallback(int256 d0, int256 d1, bytes calldata data) external {
        _payV3(d0, d1, data);
    }

    function pancakeV3SwapCallback(int256 d0, int256 d1, bytes calldata data) external {
        _payV3(d0, d1, data);
    }

    /// t6208: doğrulanmış havuzda coin->WETH; callback yalnız bu havuzdan, tek sefer kabul edilir.
    function _swapToWeth(address v3Pool, address coin, uint256 amt) internal {
        bool zfo = _checkPool(v3Pool, coin);
        uint256 sp = T_POOL;
        uint256 sc = T_COIN;
        assembly {
            tstore(sp, v3Pool)
            tstore(sc, coin)
        }
        IUniswapV3Pool(v3Pool).swap(address(this), zfo, int256(amt), zfo ? MIN_SQRT : MAX_SQRT, abi.encode(coin));
        assembly {
            tstore(sp, 0)
            tstore(sc, 0)
        }
    }

    /// t6208: havuz, coin'in WETH çifti olan Uni/Pancake/Sushi V3 havuzu mu? (factory.getPool ile)
    /// Dönüş: zeroForOne (coin token0 ise true).
    function _checkPool(address pool, address coin) internal view returns (bool zfo) {
        address t0 = IUniswapV3Pool(pool).token0();
        address t1 = IUniswapV3Pool(pool).token1();
        if (!((t0 == coin && t1 == WETH) || (t0 == WETH && t1 == coin))) revert BadPool();
        address f = IUniswapV3Pool(pool).factory();
        if (f != UNI_V3_FACTORY && f != PANCAKE_V3_FACTORY && f != SUSHI_V3_FACTORY) revert BadPool();
        if (IV3Factory(f).getPool(t0, t1, IUniswapV3Pool(pool).fee()) != pool) revert BadPool();
        zfo = (t0 == coin);
    }

    function _payV3(int256 d0, int256 d1, bytes calldata) internal {
        uint256 sp = T_POOL;
        uint256 sc = T_COIN;
        address pool;
        address coin;
        assembly {
            pool := tload(sp)
            coin := tload(sc)
        }
        // yalnız bu tx'te bizim başlattığımız swap'ın havuzu, tek sefer
        if (pool == address(0) || msg.sender != pool || coin == address(0)) revert BadCallback();
        assembly { tstore(sp, 0) }
        int256 d = (coin == IUniswapV3Pool(pool).token0()) ? d0 : d1;
        if (d <= 0) return;
        _safeTransfer(coin, msg.sender, uint256(d));
    }

    function _safeTransfer(address token, address to, uint256 amt) internal {
        (bool ok, bytes memory r) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, amt));
        require(ok && (r.length == 0 || abi.decode(r, (bool))), "xfer");
    }

    /// ETH için token==address(0).
    function sweep(address token) external {
        require(msg.sender == owner, "owner");
        if (token == address(0)) {
            (bool ok, ) = owner.call{value: address(this).balance}("");
            require(ok, "sweep");
        } else {
            require(IERC20(token).transfer(owner, IERC20(token).balanceOf(address(this))), "sweep");
        }
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.