Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Code
Read Contract
Write Contract
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- FeeSplitter
- Optimization enabled
- true
- Compiler version
- v0.8.16+commit.07a7930e
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2023-07-17T12:20:47.862418Z
Contract source code
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.16;
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
/**
* @title FeeSplitter
*/
contract FeeSplitter {
address payable private recipient1;
address payable private recipient2;
address payable private recipient3;
bool private initialized;
constructor() {
// Contructor not used. Deploy script will call this.initialize()
initialized = false;
}
function initialize(
address payable _recipient1,
address payable _recipient2,
address payable _recipient3
)
public
{
require(initialized == false, "Already initialized");
recipient1 = _recipient1;
recipient2 = _recipient2;
recipient3 = _recipient3;
initialized = true;
}
receive() external payable {
_splitNative(msg.value);
}
error SplitNativeFailed(
bool recipient1,
bool recipient2,
bool recipient3
);
function _splitNative(uint256 value)
private
{
require(initialized == true, "Uninitialized");
uint256 prevBalance = address(this).balance - value;
// @dev any remainder will be included in next split
uint256 splitAmount = 0;
unchecked { splitAmount = (value + prevBalance) / 3; }
if (splitAmount > 0) {
(bool sent1,/* data */) = recipient1.call{value: splitAmount}("");
(bool sent2,/* data */) = recipient2.call{value: splitAmount}("");
(bool sent3,/* data */) = recipient3.call{value: splitAmount}("");
if (!(sent1 && sent2 && sent3)) revert SplitNativeFailed(sent1, sent2, sent3);
}
}
function splitERC20(address tokenAddress) public returns (bool) {
require(initialized == true, "Uninitialized");
require(tokenAddress.code.length > 0, "not a token");
IERC20 token = IERC20(tokenAddress);
uint256 balance = token.balanceOf(address(this));
uint256 splitAmount;
// @dev any remainder will be included in next split
unchecked { splitAmount = balance / 3; } // underflow/remainder acceptable
token.transfer(recipient1, splitAmount);
token.transfer(recipient2, splitAmount);
token.transfer(recipient3, splitAmount);
return true;
}
}
Contract ABI
[{"type":"constructor","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"_recipient1","internalType":"address payable"},{"type":"address","name":"_recipient2","internalType":"address payable"},{"type":"address","name":"_recipient3","internalType":"address payable"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"splitERC20","inputs":[{"type":"address","name":"tokenAddress","internalType":"address"}]},{"type":"error","name":"SplitNativeFailed","inputs":[{"type":"bool","name":"recipient1","internalType":"bool"},{"type":"bool","name":"recipient2","internalType":"bool"},{"type":"bool","name":"recipient3","internalType":"bool"}]},{"type":"receive"}]
Contract Creation Code
0x608060405234801561001057600080fd5b506002805460ff60a01b191690556106958061002d6000396000f3fe60806040526004361061002d5760003560e01c8063c0c53b8b14610042578063f6f697ab1461006257600080fd5b3661003d5761003b34610096565b005b600080fd5b34801561004e57600080fd5b5061003b61005d36600461058e565b610258565b34801561006e57600080fd5b5061008261007d3660046105d9565b6102f6565b604051901515815260200160405180910390f35b600254600160a01b900460ff1615156001146100e95760405162461bcd60e51b815260206004820152600d60248201526c155b9a5b9a5d1a585b1a5e9959609a1b60448201526064015b60405180910390fd5b60006100f582476105fd565b9050600382820104801561025357600080546040516001600160a01b039091169083908381818185875af1925050503d8060008114610150576040519150601f19603f3d011682016040523d82523d6000602084013e610155565b606091505b50506001546040519192506000916001600160a01b039091169084908381818185875af1925050503d80600081146101a9576040519150601f19603f3d011682016040523d82523d6000602084013e6101ae565b606091505b50506002546040519192506000916001600160a01b039091169085908381818185875af1925050503d8060008114610202576040519150601f19603f3d011682016040523d82523d6000602084013e610207565b606091505b505090508280156102155750815b801561021e5750805b61024f5760405163342e5f6f60e11b81528315156004820152821515602482015281151560448201526064016100e0565b5050505b505050565b600254600160a01b900460ff16156102a85760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60448201526064016100e0565b600080546001600160a01b039485166001600160a01b031991821617909155600180549385169390911692909217909155600280546001600160a81b0319169190921617600160a01b179055565b600254600090600160a01b900460ff1615156001146103475760405162461bcd60e51b815260206004820152600d60248201526c155b9a5b9a5d1a585b1a5e9959609a1b60448201526064016100e0565b6000826001600160a01b03163b1161038f5760405162461bcd60e51b815260206004820152600b60248201526a3737ba1030903a37b5b2b760a91b60448201526064016100e0565b6040516370a0823160e01b815230600482015282906000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156103d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103fc9190610624565b60005460405163a9059cbb60e01b81526001600160a01b03918216600482015260038304602482018190529293509084169063a9059cbb906044016020604051808303816000875af1158015610456573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047a919061063d565b5060015460405163a9059cbb60e01b81526001600160a01b039182166004820152602481018390529084169063a9059cbb906044016020604051808303816000875af11580156104ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f2919061063d565b5060025460405163a9059cbb60e01b81526001600160a01b039182166004820152602481018390529084169063a9059cbb906044016020604051808303816000875af1158015610546573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061056a919061063d565b50600195945050505050565b6001600160a01b038116811461058b57600080fd5b50565b6000806000606084860312156105a357600080fd5b83356105ae81610576565b925060208401356105be81610576565b915060408401356105ce81610576565b809150509250925092565b6000602082840312156105eb57600080fd5b81356105f681610576565b9392505050565b8181038181111561061e57634e487b7160e01b600052601160045260246000fd5b92915050565b60006020828403121561063657600080fd5b5051919050565b60006020828403121561064f57600080fd5b815180151581146105f657600080fdfea264697066735822122077866b076329b2b498833e83502d78b86cd80de1fb726fb1051d1912dbca07bf64736f6c63430008100033
Deployed ByteCode
0x60806040526004361061002d5760003560e01c8063c0c53b8b14610042578063f6f697ab1461006257600080fd5b3661003d5761003b34610096565b005b600080fd5b34801561004e57600080fd5b5061003b61005d36600461058e565b610258565b34801561006e57600080fd5b5061008261007d3660046105d9565b6102f6565b604051901515815260200160405180910390f35b600254600160a01b900460ff1615156001146100e95760405162461bcd60e51b815260206004820152600d60248201526c155b9a5b9a5d1a585b1a5e9959609a1b60448201526064015b60405180910390fd5b60006100f582476105fd565b9050600382820104801561025357600080546040516001600160a01b039091169083908381818185875af1925050503d8060008114610150576040519150601f19603f3d011682016040523d82523d6000602084013e610155565b606091505b50506001546040519192506000916001600160a01b039091169084908381818185875af1925050503d80600081146101a9576040519150601f19603f3d011682016040523d82523d6000602084013e6101ae565b606091505b50506002546040519192506000916001600160a01b039091169085908381818185875af1925050503d8060008114610202576040519150601f19603f3d011682016040523d82523d6000602084013e610207565b606091505b505090508280156102155750815b801561021e5750805b61024f5760405163342e5f6f60e11b81528315156004820152821515602482015281151560448201526064016100e0565b5050505b505050565b600254600160a01b900460ff16156102a85760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60448201526064016100e0565b600080546001600160a01b039485166001600160a01b031991821617909155600180549385169390911692909217909155600280546001600160a81b0319169190921617600160a01b179055565b600254600090600160a01b900460ff1615156001146103475760405162461bcd60e51b815260206004820152600d60248201526c155b9a5b9a5d1a585b1a5e9959609a1b60448201526064016100e0565b6000826001600160a01b03163b1161038f5760405162461bcd60e51b815260206004820152600b60248201526a3737ba1030903a37b5b2b760a91b60448201526064016100e0565b6040516370a0823160e01b815230600482015282906000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156103d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103fc9190610624565b60005460405163a9059cbb60e01b81526001600160a01b03918216600482015260038304602482018190529293509084169063a9059cbb906044016020604051808303816000875af1158015610456573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047a919061063d565b5060015460405163a9059cbb60e01b81526001600160a01b039182166004820152602481018390529084169063a9059cbb906044016020604051808303816000875af11580156104ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f2919061063d565b5060025460405163a9059cbb60e01b81526001600160a01b039182166004820152602481018390529084169063a9059cbb906044016020604051808303816000875af1158015610546573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061056a919061063d565b50600195945050505050565b6001600160a01b038116811461058b57600080fd5b50565b6000806000606084860312156105a357600080fd5b83356105ae81610576565b925060208401356105be81610576565b915060408401356105ce81610576565b809150509250925092565b6000602082840312156105eb57600080fd5b81356105f681610576565b9392505050565b8181038181111561061e57634e487b7160e01b600052601160045260246000fd5b92915050565b60006020828403121561063657600080fd5b5051919050565b60006020828403121561064f57600080fd5b815180151581146105f657600080fdfea264697066735822122077866b076329b2b498833e83502d78b86cd80de1fb726fb1051d1912dbca07bf64736f6c63430008100033