Skip to content
Verified contractExactMIT

NFTStrategyArb

Address0x89c55331cbc12dc7cd41eea6ba493649e4503bd5
Balance

0 ETH

 

Transactions

24

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,042,391
Creation transaction
0xc14f185970…45752b539a

contracts/1_Storage.sol

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

interface INFTStrategy {
    function buyTargetNFT(uint256 value, bytes calldata data, uint256 expectedId, address target) external;
    function currentFees() external view returns (uint256);
    function getMaxPriceForBuy() external view returns (uint256);
}

interface ISeaport {
    struct OfferItem { uint8 itemType; address token; uint256 identifierOrCriteria; uint256 startAmount; uint256 endAmount; }
    struct ConsiderationItem { uint8 itemType; address token; uint256 identifierOrCriteria; uint256 startAmount; uint256 endAmount; address payable recipient; }
    struct OrderParameters {
        address offerer; address zone;
        OfferItem[] offer; ConsiderationItem[] consideration;
        uint8 orderType; uint256 startTime; uint256 endTime;
        bytes32 zoneHash; uint256 salt; bytes32 conduitKey;
        uint256 totalOriginalConsiderationItems;
    }
    struct AdvancedOrder { OrderParameters parameters; uint120 numerator; uint120 denominator; bytes signature; bytes extraData; }
    struct CriteriaResolver { uint256 orderIndex; uint8 side; uint256 index; uint256 identifier; bytes32[] criteriaProof; }
    function fulfillAdvancedOrder(
        AdvancedOrder calldata advancedOrder,
        CriteriaResolver[] calldata criteriaResolvers,
        bytes32 fulfillerConduitKey,
        address recipient
    ) external payable returns (bool);
}

contract NFTStrategyArb {
    address public constant SEAPORT = 0x0000000000000068F116a894984e2DB1123eB395;

    address public immutable owner;
    address public immutable strategy;

    error NotOwner();
    error NotStrategy();
    error BadOrder();
    error LowValue();
    error NotProfitable();
    error TipTooHigh();
    error TipFailed();
    error PayoutFailed();

    event ArbDone(uint256 indexed nftId, uint256 value, uint256 cost, uint256 profit, uint256 tip, address coinbase);

    constructor(address _strategy) {
        require(_strategy != address(0), "zero strategy");
        owner = msg.sender;
        strategy = _strategy;
    }

    modifier onlyOwner() {
        if (msg.sender != owner) revert NotOwner();
        _;
    }

    /// @param tipWei      сумма, которую отправляем block.coinbase (0 = без взятки)
    function attack(
        ISeaport.AdvancedOrder calldata order,
        uint256 minProfit,
        uint256 tipWei
    ) external onlyOwner {
        ISeaport.OrderParameters calldata p = order.parameters;
        if (p.offer.length == 0 || p.consideration.length == 0) revert BadOrder();
        if (p.consideration[0].itemType != 0) revert BadOrder();
        if (p.consideration[0].token != address(0)) revert BadOrder();

        uint256 nftId = p.offer[0].identifierOrCriteria;
        uint256 cost = _orderCost(p);

        uint256 fees = INFTStrategy(strategy).currentFees();
        uint256 maxBuy = INFTStrategy(strategy).getMaxPriceForBuy();
        uint256 value = fees < maxBuy ? fees : maxBuy;
        if (value <= cost) revert NotProfitable();

        uint256 balBefore = address(this).balance;

        bytes memory cb = abi.encodeWithSelector(this.onStrategyCall.selector, order);
        INFTStrategy(strategy).buyTargetNFT(value, cb, nftId, address(this));

        uint256 profit = address(this).balance - balBefore;
        if (profit < minProfit) revert NotProfitable();
        if (tipWei > profit) revert TipTooHigh();

        if (tipWei > 0) {
            (bool ok, ) = block.coinbase.call{value: tipWei}("");
            if (!ok) revert TipFailed();
        }

        uint256 payout = address(this).balance;
        if (payout > 0) {
            (bool ok, ) = owner.call{value: payout}("");
            if (!ok) revert PayoutFailed();
        }

        emit ArbDone(nftId, value, cost, profit, tipWei, block.coinbase);
    }

    function onStrategyCall(ISeaport.AdvancedOrder calldata order) external payable {
        if (msg.sender != strategy) revert NotStrategy();

        uint256 cost = _orderCost(order.parameters);
        if (msg.value < cost) revert LowValue();

        ISeaport.CriteriaResolver[] memory resolvers = new ISeaport.CriteriaResolver[](0);

        ISeaport(SEAPORT).fulfillAdvancedOrder{value: cost}(
            order, resolvers, bytes32(0), strategy
        );
    }

    function _orderCost(ISeaport.OrderParameters calldata params)
        internal pure returns (uint256 total)
    {
        for (uint256 i = 0; i < params.consideration.length; i++) {
            total += params.consideration[i].startAmount;
        }
    }

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

    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.