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": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
// A standard interface for ERC20 tokens
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
}
/**
* @title EIP7702Splitter
* @notice A single-use contract that receives assets from a user's EIP-7702 transaction.
* A trusted relayer then calls `executeSplit` to distribute the funds before the contract is destroyed.
*/
contract EIP7702Splitter {
address public immutable owner; // Your relayer wallet address
modifier onlyOwner() {
require(msg.sender == owner, "EIP7702Splitter: Caller is not the owner");
_;
}
constructor(address _owner) {
owner = _owner;
}
receive() external payable {}
/**
* @notice Called by the relayer to split the funds held by this contract.
* @param token The address of the token to split. Use address(0) for native ETH.
* @param mainRecipient The primary address receiving 70%.
* @param houseRecipient The address for the house's share (20% or 30%).
* @param affiliateRecipient The affiliate's address (10%). Can be address(0).
*/
function executeSplit(
address token,
address mainRecipient,
address houseRecipient,
address affiliateRecipient
) external onlyOwner {
// Determine the total balance of the specified asset held by this contract
uint256 totalBalance = (token == address(0))
? address(this).balance
: IERC20(token).balanceOf(address(this));
if (totalBalance > 0) {
// Calculate the 70/20/10 split
uint256 amount70 = (totalBalance * 70) / 100;
uint256 amount20 = (totalBalance * 20) / 100;
uint256 amount10 = totalBalance - amount70 - amount20; // Remainder to avoid dust
// Distribute the funds
if (token == address(0)) { // Handle native ETH transfers
payable(mainRecipient).transfer(amount70);
if (affiliateRecipient != address(0)) {
payable(houseRecipient).transfer(amount20);
payable(affiliateRecipient).transfer(amount10);
} else {
// If no affiliate, house gets the combined 30%
payable(houseRecipient).transfer(amount20 + amount10);
}
} else { // Handle ERC20 token transfers
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);
}
}
}
}
/**
* @notice A recovery function in case a token gets stuck in the contract.
* Allows the relayer to withdraw any specified ERC20 token.
*/
function recoverERC20(address tokenAddress) external onlyOwner {
IERC20(tokenAddress).transfer(owner, IERC20(tokenAddress).balanceOf(address(this)));
}
/**
* @notice Allows the relayer to destroy the contract and recover any remaining gas/ETH.
*/
function destroy() external onlyOwner {
selfdestruct(payable(owner));
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}
}}
Submitted on: 2025-10-20 12:33:01
Comments
Log in to comment.
No comments yet.