Verified contractExactGPL-3.0
IncomeForwarder
Address0xc0de8f70834546717e0e5ce172bb66906fe2c66f
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 10,000 runs
- EVM version
- cancun
- License
- GPL-3.0
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,355,042
- Creation transaction
- 0xd11d7aa300…1cc2de992a
src/IncomeForwarder.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.24;
interface IOwesByAddress {
/// auctions and editions of generation 8: pays owed[to] to `to`, callable by anyone
function withdraw(address to) external;
}
interface IOwesBySender {
/// ListingBookV4: pays owed[msg.sender] to msg.sender
function withdraw() external;
}
/// Where the press's one percent goes from generation 8 on, and nothing else.
///
/// Every sale template of generation 8 (Auction1of1V4, AuctionAllowlistV4,
/// EditionSaleV3, EditionSaleAllowlistV3) and ListingBookV4 name THIS
/// address as the press's share on Ethereum (FeeV2.sol). This contract passes
/// every wei it receives to one address, the payee, and the house can name a
/// new payee later. That is the whole of it:
///
/// - It only ever pays the payee. It has exactly two sends of value, both
/// to `payee` read in the same frame; no function takes a recipient.
/// - receive() never reverts for a sender giving it a 2,300 gas stipend or
/// more, whatever the payee does. A forward that fails or that there is
/// not gas for leaves the ETH here, logged, for sweep() to send on, so
/// no sale ever breaks on the press's account.
/// - Only HOUSE can name a new payee, and the new payee must accept. The
/// payee itself cannot start a change. HOUSE is a constant.
/// - Anyone can pull what a generation 8 sale or a ListingBookV4 owes this
/// contract (collect, collectBook, collectMany), and anyone can sweep:
/// both only ever end at the payee.
/// - No other powers: no owner beyond HOUSE's proposal, no upgrade, no
/// proxy, no delegatecall, no selfdestruct, no token handling, and no
/// way to reach an artist's or a seller's money in any sale or book
/// (a sale pays this contract only what it owes this contract: the
/// press's one percent).
///
/// No constructor arguments: its creation code is the same everywhere, so
/// deployed through the public CREATE2 proxy with a fixed salt it lands at
/// one address, known before it is deployed (FeeV2.FORWARDER, held to this
/// file by test/FeeV2Address.t.sol and scripts/verify-forwarder-address.mjs).
/// Any edit to this file, a comment included, moves that address.
///
/// Fees still owed inside sales and books, or held here, go to whoever is
/// the payee when they are sent. Before a payee change, run collectMany and
/// sweep if the old payee should have them (docs/mainnet-runbook.md).
contract IncomeForwarder {
/// The only hand that may name a new payee: the house wallet. A constant, no setter.
address public constant HOUSE = 0xfC57C0c2638162689B0C0394Ef5d22c92C507E77;
/// The payee on the day this is deployed.
address public constant FIRST_PAYEE = 0xB5fFC9D4cE78b40FcA05FaC21CbF330C8f0166a7;
/// Below this much gas on arrival, receive() keeps the ETH without trying
/// to forward it (a 2,300 stipend lands here and only logs Kept).
uint256 public constant FORWARD_MIN_GAS = 20_000;
/// What the CALL itself charges the caller: a warm account (the payee is
/// warmed by the EXTCODEHASH before it) plus a transfer of value.
uint256 private constant CALL_COST = 100 + 9_000;
/// What a CALL with value to an empty account charges on top.
uint256 private constant NEW_ACCOUNT_COST = 25_000;
/// Gas kept back past the payee's call, whatever the payee does, so this
/// frame always unlocks, logs and returns.
uint256 private constant POST = 5_000;
/// The current payee: the only address this contract ever pays.
address public payee;
/// Named by HOUSE; becomes the payee only when it accepts.
address public pendingPayee;
/// Re-entry guard for the duration of a payment (transient: ends with the transaction).
bool private transient paying;
/// `amount` (the whole balance) reached `payee`.
event Forwarded(address indexed payee, uint256 amount);
/// A forward to `payee` failed or there was not gas for it: `amount` stays here.
event Held(address indexed payee, uint256 amount);
/// ETH arrived with too little gas to try a forward, or during a payment: it stays here.
event Kept(uint256 amount);
event PayeeProposed(address indexed current, address indexed proposed);
event PayeeChanged(address indexed previous, address indexed next);
error NotHouse();
error NotPending();
error BadPayee();
error NothingHere();
error PayeeRefused();
error Busy();
constructor() {
payee = FIRST_PAYEE;
emit PayeeChanged(address(0), FIRST_PAYEE);
}
/// Forwards the WHOLE balance (anything held earlier goes along) when
/// there is gas for it; otherwise keeps it. Never reverts.
receive() external payable {
if (gasleft() < FORWARD_MIN_GAS || paying) {
emit Kept(msg.value);
return;
}
_forward();
}
/// Anyone: pull what a generation 8 auction or edition owes this
/// contract. The ETH arrives through receive() and goes on from there.
/// Reverts as the sale does when it owes nothing.
function collect(address sale) external {
IOwesByAddress(sale).withdraw(address(this));
}
/// Anyone: pull what a ListingBookV4 owes this contract (its withdraw
/// pays msg.sender, which is this contract).
function collectBook(address book) external {
IOwesBySender(book).withdraw();
}
/// Anyone: many at once. A source that owes nothing, reverts or has no
/// code is skipped, never fatal; nothing it returns is copied.
function collectMany(address[] calldata sales, address[] calldata books) external {
bytes memory bySale = abi.encodeWithSelector(IOwesByAddress.withdraw.selector, address(this));
bytes memory byBook = abi.encodeWithSelector(IOwesBySender.withdraw.selector);
for (uint256 i; i < sales.length; ++i) _tryCall(sales[i], bySale);
for (uint256 i; i < books.length; ++i) _tryCall(books[i], byBook);
}
/// Anyone: send everything held here to the payee, with all the gas there
/// is. Reverts if the payee refuses (the ETH stays here, nothing is lost),
/// so the caller learns it.
function sweep() external {
if (paying) revert Busy();
uint256 amount = address(this).balance;
if (amount == 0) revert NothingHere();
address to = payee;
paying = true;
bool ok;
assembly ("memory-safe") {
ok := call(gas(), to, amount, 0, 0, 0, 0)
}
paying = false;
if (!ok) revert PayeeRefused();
emit Forwarded(to, amount);
}
/// HOUSE names the next payee; address(0) withdraws a proposal. The payee cannot do this.
function proposePayee(address next) external {
if (msg.sender != HOUSE) revert NotHouse();
if (paying) revert Busy();
if (next == address(this) || (next != address(0) && next == payee)) revert BadPayee();
pendingPayee = next;
emit PayeeProposed(payee, next);
}
/// The proposed address accepts, proving it is the address meant and that it can act.
function acceptPayee() external {
address next = pendingPayee;
if (next == address(0) || msg.sender != next) revert NotPending();
if (paying) revert Busy();
address prev = payee;
payee = next;
pendingPayee = address(0);
emit PayeeChanged(prev, next);
}
function _forward() private {
uint256 amount = address(this).balance;
if (amount == 0) return;
address to = payee;
uint256 cost = CALL_COST;
bytes32 h;
assembly ("memory-safe") {
h := extcodehash(to) // warms the payee; zero for an empty account
}
if (h == bytes32(0)) cost += NEW_ACCOUNT_COST;
if (gasleft() < cost + POST + 2_000) {
emit Held(to, amount);
return;
}
paying = true;
uint256 g = gasleft() - cost - POST;
bool ok;
assembly ("memory-safe") {
ok := call(g, to, amount, 0, 0, 0, 0) // nothing the payee returns is copied
}
paying = false;
if (ok) emit Forwarded(to, amount);
else emit Held(to, amount);
}
function _tryCall(address target, bytes memory data) private {
assembly ("memory-safe") {
pop(call(gas(), target, 0, add(data, 0x20), mload(data), 0, 0))
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 10000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.