Skip to content
Verified contractExactMIT

ProtocolFeeTreasury

Address0xc1c7492a9374affa4d2f5515f9b280d2eb06701d
Balance

0 ETH

 

Transactions

2

 

Compiler

solc 0.8.26

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,249,534
Creation transaction
0x3f801e2324…4d8345ce4b

LetheContracts/ProtocolFeeTreasury.sol

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

//=============================================================================
//  ProtocolFeeTreasury
//-----------------------------------------------------------------------------
//  Receives the protocol share of every withdrawal, in ETH.
//  The steward sets up to eight payees with weights in basis points that add
//  up to 10000. Anyone may call `release` and the balance is split by weight.
//  A payee that cannot receive ETH has its share parked and can claim it later.
//=============================================================================

contract ProtocolFeeTreasury {
    uint256 public constant MAX_PAYEES = 8;

    address public steward = msg.sender;
    uint256 public totalReceived;
    uint256 public totalReleased;
    uint256 public releaseCount;

    address[] public payees;
    mapping(address => uint16) public weightOf;
    mapping(address => uint256) public owed;
    bool private busy;

    event Received(address indexed from, uint256 amount);
    event Released(uint256 amount, uint256 payeeCount);
    event PayeesSet(address[] payees, uint16[] weights);
    event Parked(address indexed to, uint256 amount);
    event Swept(address indexed token, address indexed to, uint256 amount);
    event StewardChanged(address indexed previous, address indexed next);

    receive() external payable {
        totalReceived += msg.value;
        emit Received(msg.sender, msg.value);
    }

    function payeeCount() public view returns (uint256) {
        return payees.length;
    }

    function pending() public view returns (uint256) {
        return address(this).balance;
    }

    function setPayees(address[] calldata accounts, uint16[] calldata weights) public returns (bool) {
        if (msg.sender != steward || accounts.length == 0 || accounts.length > MAX_PAYEES) return false;
        if (accounts.length != weights.length) return false;
        uint256 sum;
        for (uint256 i = 0; i < accounts.length; i++) {
            if (accounts[i] == address(0) || weights[i] == 0) return false;
            for (uint256 j = 0; j < i; j++) {
                if (accounts[j] == accounts[i]) return false;
            }
            sum += weights[i];
        }
        if (sum != 10_000) return false;

        for (uint256 k = 0; k < payees.length; k++) weightOf[payees[k]] = 0;
        delete payees;
        for (uint256 m = 0; m < accounts.length; m++) {
            payees.push(accounts[m]);
            weightOf[accounts[m]] = weights[m];
        }
        emit PayeesSet(accounts, weights);
        return true;
    }

    function release() public returns (uint256 amount) {
        amount = address(this).balance;
        uint256 n = payees.length;
        if (busy || n == 0 || amount == 0) return 0;
        busy = true;
        uint256 sent;
        for (uint256 i = 0; i < n; i++) {
            address to = payees[i];
            uint256 share = i == n - 1 ? amount - sent : (amount * weightOf[to]) / 10_000;
            sent += share;
            if (share == 0) continue;
            (bool ok,) = to.call{value: share}("");
            if (!ok) {
                owed[to] += share;
                emit Parked(to, share);
            }
        }
        busy = false;
        totalReleased += amount;
        releaseCount += 1;
        emit Released(amount, n);
    }

    function claimOwed() public returns (uint256 amount) {
        amount = owed[msg.sender];
        if (amount == 0 || busy) return 0;
        owed[msg.sender] = 0;
        busy = true;
        (bool ok,) = msg.sender.call{value: amount}("");
        busy = false;
        if (!ok) {
            owed[msg.sender] = amount;
            return 0;
        }
    }

    /// Moves ERC-20 tokens that landed here to `to`. Steward only.
    function sweepToken(address token, address to, uint256 amount) public returns (bool) {
        if (msg.sender != steward || to == address(0) || token.code.length == 0) return false;
        (bool ok, bytes memory ret) = token.call(abi.encodeWithSelector(0xa9059cbb, to, amount));
        bool good = ok && (ret.length == 0 || (ret.length >= 32 && abi.decode(ret, (uint256)) == 1));
        if (good) emit Swept(token, to, amount);
        return good;
    }

    function transferSteward(address next) public returns (bool) {
        if (msg.sender != steward || next == address(0)) return false;
        emit StewardChanged(steward, next);
        steward = next;
        return true;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.