Verified contractExactMIT
FeeSplitFactory
Address0x7ef481668884b6069b8dfbb843a287d34278dfb5
- Balance
0 ETH
- Transactions
5
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,256,462
- Creation transaction
- 0xa2b7d77f65…bda1a794cd
FeeSplit.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @title Find My Funds — FeeSplit (one per owner) and its factory
/// @notice For withdrawals only the owner can send but that let him name the receiver (GMX: GLV compensation, V2 funding
/// fees and referral rewards, GLP redemption). The owner sends his own withdrawal with receiver = his FeeSplit
/// address; release() then pays FEE_BPS of every token to FEE_TO and the rest to the owner, in one call.
/// The owner and FEE_TO are fixed in each FeeSplit's code (its CREATE2 address is derived from the owner), so the
/// money can only go to those two. Anyone may call release() — it can only pay them.
/// @dev No owner/admin, no upgrade, no other way out. FeeSplit is deployed by the factory on first release; tokens can
/// arrive at its address before that.
contract FeeSplit {
address public immutable OWNER;
address payable public immutable FEE_TO;
uint256 public immutable FEE_BPS;
event Released(address indexed token, uint256 toOwner, uint256 fee);
error TransferFailed(address token);
constructor(address owner, address payable feeTo, uint256 feeBps) {
OWNER = owner;
FEE_TO = feeTo;
FEE_BPS = feeBps;
}
/// @notice Splits everything this contract holds of each token (address(0) = ETH): fee to FEE_TO, the rest to OWNER.
function release(address[] calldata tokens) external {
for (uint256 i; i < tokens.length; ++i) {
address t = tokens[i];
uint256 bal = t == address(0) ? address(this).balance : _balanceOf(t);
if (bal == 0) continue;
uint256 fee = bal * FEE_BPS / 10_000;
uint256 rest = bal - fee;
if (t == address(0)) {
(bool a, ) = OWNER.call{value: rest}("");
bool b = true;
if (fee > 0) (b, ) = FEE_TO.call{value: fee}("");
if (!a || !b) revert TransferFailed(t);
} else {
_transfer(t, OWNER, rest);
if (fee > 0) _transfer(t, FEE_TO, fee);
}
emit Released(t, rest, fee);
}
}
function _balanceOf(address t) private view returns (uint256) {
(bool ok, bytes memory r) = t.staticcall(abi.encodeWithSelector(0x70a08231, address(this)));
if (!ok || r.length < 32) revert TransferFailed(t);
return abi.decode(r, (uint256));
}
function _transfer(address t, address to, uint256 v) private {
(bool ok, bytes memory r) = t.call(abi.encodeWithSelector(0xa9059cbb, to, v)); // transfer, tolerating tokens without a return value
if (!ok || (r.length != 0 && !abi.decode(r, (bool)))) revert TransferFailed(t);
}
receive() external payable {}
}
contract FeeSplitFactory {
address payable public immutable FEE_TO;
uint256 public immutable FEE_BPS;
event Deployed(address indexed owner, address split);
error BadFee();
constructor(address payable feeTo, uint256 feeBps) {
if (feeBps > 1_000) revert BadFee(); // never more than 10%
FEE_TO = feeTo;
FEE_BPS = feeBps;
}
function _initCode(address owner) private view returns (bytes memory) {
return abi.encodePacked(type(FeeSplit).creationCode, abi.encode(owner, FEE_TO, FEE_BPS));
}
/// @notice The owner's FeeSplit address (deployed or not yet): the receiver to put in his withdrawal.
function splitOf(address owner) public view returns (address) {
bytes32 h = keccak256(abi.encodePacked(bytes1(0xff), address(this), bytes32(uint256(uint160(owner))), keccak256(_initCode(owner))));
return address(uint160(uint256(h)));
}
/// @notice Deploys the owner's FeeSplit if needed, then splits the given tokens. Anyone may call it.
function release(address owner, address[] calldata tokens) external {
address s = splitOf(owner);
if (s.code.length == 0) {
bytes memory code = _initCode(owner);
address d;
assembly { d := create2(0, add(code, 32), mload(code), owner) }
require(d == s, "deploy failed");
emit Deployed(owner, s);
}
FeeSplit(payable(s)).release(tokens);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.