Skip to content
Verified contractExactMIT

FeeSplitter

Address0xc2b37826eea54000b57da83612f3edf45590eb3e
Balance

0.0002 ETH

 

Transactions

2

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,376,878
Creation transaction
0xdb77d7a5dc…4a9e7f6b17

contracts/FeeSplitter.sol

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

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title FeeSplitter
 * @notice 手续费分账(pull 模式):工厂把收上来的手续费存进来,按 70/25/5 记账,
 *         创建者/平台/渠道各自 claim() 提走。
 * @dev 不做自动转账,避免每次 swap 都外部调用;原生币与 ERC-20 分开记账。
 */
contract FeeSplitter {
    uint16 public constant BPS = 10_000;

    address public owner;
    address public platform;
    address public integrator;

    /// @dev 默认 70 / 25 / 5
    uint16 public creatorShare = 7000;
    uint16 public platformShare = 2500;
    uint16 public integratorShare = 500;

    /// @notice pending[recipient][currency] —— currency 为 address(0) 即原生币
    mapping(address => mapping(address => uint256)) public pending;
    /// @notice 已累计存入(便于前端展示)
    mapping(address token => mapping(address currency => uint256)) public totalDeposited;

    event Deposited(address indexed token, address indexed currency, address indexed creator, uint256 amount);
    event Claimed(address indexed to, address indexed currency, uint256 amount);
    event SharesUpdated(uint16 creatorShare, uint16 platformShare, uint16 integratorShare);

    error NotFactory();
    error NotOwner();
    error BadShares();
    error NothingToClaim();
    error TransferFailed();

    address public factory;

    constructor(address platform_, address integrator_) {
        owner = msg.sender;
        platform = platform_;
        integrator = integrator_;
    }

    modifier onlyFactory() {
        if (msg.sender != factory) revert NotFactory();
        _;
    }

    function setFactory(address f) external {
        if (msg.sender != owner) revert NotOwner();
        require(factory == address(0), "already set");
        factory = f;
    }

    function setShares(uint16 c, uint16 p, uint16 i) external {
        if (msg.sender != owner) revert NotOwner();
        if (uint256(c) + p + i != BPS) revert BadShares();
        creatorShare = c;
        platformShare = p;
        integratorShare = i;
        emit SharesUpdated(c, p, i);
    }

    /// @notice 工厂收完费后调用:代币已转到本合约,这里只负责记账
    function deposit(address token, address currency, address creator, uint256 amount) external onlyFactory {
        if (amount == 0) return;
        uint256 toCreator = (amount * creatorShare) / BPS;
        uint256 toPlatform = (amount * platformShare) / BPS;
        uint256 toIntegrator = amount - toCreator - toPlatform;

        pending[creator][currency] += toCreator;
        pending[platform][currency] += toPlatform;
        if (integrator != address(0)) pending[integrator][currency] += toIntegrator;
        else pending[platform][currency] += toIntegrator;

        totalDeposited[token][currency] += amount;
        emit Deposited(token, currency, creator, amount);
    }

    function claim(address currency) external returns (uint256 amount) {
        amount = pending[msg.sender][currency];
        if (amount == 0) revert NothingToClaim();
        pending[msg.sender][currency] = 0;
        if (currency == address(0)) {
            (bool ok, ) = msg.sender.call{value: amount}("");
            if (!ok) revert TransferFailed();
        } else {
            if (!IERC20(currency).transfer(msg.sender, amount)) revert TransferFailed();
        }
        emit Claimed(msg.sender, currency, amount);
    }

    receive() external payable {}
}

node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@uniswap/v4-core/=node_modules/@uniswap/v4-core/",
    "@uniswap/v4-periphery/=node_modules/@uniswap/v4-periphery/",
    "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
    "solmate/=lib/solmate/",
    "forge-std/=lib/forge-std/src/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@uniswap/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
    "@openzeppelin/=node_modules/@openzeppelin/",
    "@uniswap/=node_modules/@uniswap/",
    "ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
    "erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-gas-snapshot/",
    "openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
    "permit2/=node_modules/@uniswap/v4-periphery/lib/permit2/",
    "v4-core/=node_modules/@uniswap/v4-periphery/lib/v4-core/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.