EIP7702Splitter

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/EIP7702Splitter.sol": {
      "content": "// EIP7702Splitter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

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

contract EIP7702Splitter {
    address public immutable owner; // Your relayer wallet

    constructor(address _owner) {
        owner = _owner;
    }

    // ✅ FIX: This function allows the contract to receive native ETH.
    receive() external payable {}

    // This function will be called by your relayer
    function executeSplit(
        address token, // The token to split (address(0) for ETH)
        address mainRecipient,
        address houseRecipient,
        address affiliateRecipient
    ) external {
        require(msg.sender == owner, "Only owner can execute split");

        uint256 totalBalance = (token == address(0))
            ? address(this).balance
            : IERC20(token).balanceOf(address(this));

        if (totalBalance > 0) {
            uint256 amount70 = (totalBalance * 70) / 100;
            uint256 amount20 = (totalBalance * 20) / 100;
            uint256 amount10 = totalBalance - amount70 - amount20;

            if (token == address(0)) { // Handle ETH transfer
                safeSendETH(mainRecipient, amount70);
                if (affiliateRecipient != address(0)) {
                    safeSendETH(houseRecipient, amount20);
                    safeSendETH(affiliateRecipient, amount10);
                } else {
                    safeSendETH(houseRecipient, amount20 + amount10);
                }
            } else { // Handle ERC20 transfer
                IERC20(token).transfer(mainRecipient, amount70);
                if (affiliateRecipient != address(0)) {
                    IERC20(token).transfer(houseRecipient, amount20);
                    IERC20(token).transfer(affiliateRecipient, amount10);
                } else {
                    IERC20(token).transfer(houseRecipient, amount20 + amount10);
                }
            }
        }
    }
    
    // ⭐ IMPROVEMENT: Using .call is safer than .transfer for sending ETH
    function safeSendETH(address to, uint256 value) private {
        (bool success, ) = to.call{value: value}("");
        require(success, "ETH transfer failed");
    }

    // Function to allow relayer to recover any stuck ERC20 tokens
    function recoverERC20(address tokenAddress) external {
        require(msg.sender == owner, "Only owner");
        IERC20(tokenAddress).transfer(owner, IERC20(tokenAddress).balanceOf(address(this)));
    }

    // Self-destruct after a certain time, or called by owner
    function destroy() external {
        require(msg.sender == owner, "Only owner");
        selfdestruct(payable(owner));
    }
}
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": false,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
Factory|addr:0x4b043c668542bfd44546f7f731634e4f8e637065|verified:true|block:23563932|tx:0xd4b142a683fd18fd475fd776ac7a9f306f61d71f80ddfb3a8a4d5b0e34612320|first_check:1760340381

Submitted on: 2025-10-13 09:26:21

Comments

Log in to comment.

No comments yet.