Verified contractPartialMIT
SocialFeeRegistry
Address0x331f75d8858ba31105182626eb2d0cb4612a3ca0
- Balance
0 ETH
- Transactions
6
- 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
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,346,634
- Creation transaction
- 0x6992e5b9d2…6dcb7393c6
src/SocialFeeRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface ICreatorFeeNFT {
function transferFrom(address from, address to, uint256 id) external;
function ownerOf(uint256 id) external view returns (address);
}
interface ISa1tHookFees {
function claimCreatorFees(uint256 tokenId, address to) external;
function creatorFees(uint256 tokenId) external view returns (uint256);
}
/// Holds the CreatorFeeNFT for TWEET-LAUNCHED sa1t coins.
///
/// In the deferred / tweet-to-launch flow a coin is launched from a tweet — its creator never
/// transacts. `Sa1tFactory.launchAndBuy` mints that coin's CreatorFeeNFT (the transferable 0.5%
/// fee stream, keyed by poolId) to THIS contract and records which X account it belongs to. The
/// fees then accrue safely in the hook, claimable by this contract, until the account owner shows up:
/// they connect X (off-chain OAuth) and the platform signer produces an EIP-712 attestation
/// `handle -> wallet`. `claim` verifies it, sweeps the accrued ETH to the wallet, and hands over the
/// NFT(s) so all future fees flow to them directly.
///
/// Trust model: the platform signer is the authority on X ownership (off-chain). Blast radius is
/// bounded to unclaimed handles; `forceBind` is the owner's clawback for disputes. Mirrors the
/// xsa1t FeeVault handle-bucket design, but on the flagship's NFT fee model.
contract SocialFeeRegistry {
address public immutable nft; // CreatorFeeNFT
address public immutable hook; // Sa1tHook (claimCreatorFees / creatorFees)
address public owner;
address public pendingOwner; // Ownable2Step: hand ownership to a timelock/multisig
address public factory; // one-shot; records handle launches
address public socialSigner; // platform key attesting handle -> wallet
mapping(uint256 => uint256[]) private _handlePools; // X user id -> poolIds whose NFT we hold
mapping(uint256 => uint256) public poolHandle; // poolId -> X user id
mapping(uint256 => address) public boundWallet; // X user id -> claimed wallet
uint256 private immutable _CACHED_CHAIN_ID; // domain separator rebuilds on a chain fork
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
bytes32 private constant CLAIM_TYPEHASH = keccak256("Claim(uint256 handleId,address wallet,uint256 deadline)");
uint256 public constant MAX_SWEEP = 64; // gas-bound the per-call sweep (defense-in-depth vs a bloated handle)
uint256 private constant _HALF_N = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0;
uint256 private _lock = 1;
event FactorySet(address factory);
event SocialSignerSet(address signer);
event HandleLaunch(uint256 indexed handleId, uint256 indexed poolId);
event Claimed(uint256 indexed handleId, address indexed wallet, uint256 count);
event Bound(uint256 indexed handleId, address indexed wallet);
event ForceBound(uint256 indexed handleId, address indexed wallet); // owner clawback (distinct for monitoring)
event OwnershipTransferStarted(address indexed from, address indexed to);
event OwnershipTransferred(address indexed from, address indexed to);
error NotOwner();
error NotFactory();
error AlreadySet();
error NotBound();
error ZeroWallet();
error Expired();
error NoSigner();
error BadAttestation();
error AlreadyBound();
error Reentrant();
modifier onlyOwner() { if (msg.sender != owner) revert NotOwner(); _; }
modifier nonReentrant() { if (_lock != 1) revert Reentrant(); _lock = 2; _; _lock = 1; }
constructor(address _nft, address _hook, address _owner) {
nft = _nft;
hook = _hook;
owner = _owner;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator();
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256("sa1tSocialFee"), keccak256("1"), block.chainid, address(this)
));
}
/// cached, but rebuilt if the chain forks so a pre-fork attestation can't replay onto the new chain.
function _domainSeparator() private view returns (bytes32) {
return block.chainid == _CACHED_CHAIN_ID ? _CACHED_DOMAIN_SEPARATOR : _buildDomainSeparator();
}
// ── config ──
function setFactory(address f) external onlyOwner {
if (factory != address(0)) revert AlreadySet();
factory = f;
emit FactorySet(f);
}
function setSocialSigner(address s) external onlyOwner { socialSigner = s; emit SocialSignerSet(s); }
/// Ownable2Step — hand ownership to a timelock/multisig (they must acceptOwnership).
function transferOwnership(address to) external onlyOwner { pendingOwner = to; emit OwnershipTransferStarted(owner, to); }
function acceptOwnership() external {
if (msg.sender != pendingOwner) revert NotOwner();
emit OwnershipTransferred(owner, msg.sender);
owner = msg.sender;
pendingOwner = address(0);
}
/// dispute / takeover clawback — owner re-points a handle's payout wallet. (Should sit behind a
/// timelock/multisig in prod — this is the dominant trust assumption.) Never to the zero address.
function forceBind(uint256 handleId, address wallet) external onlyOwner {
if (wallet == address(0)) revert ZeroWallet();
boundWallet[handleId] = wallet;
emit Bound(handleId, wallet);
emit ForceBound(handleId, wallet);
}
// ── factory hook ──
/// Records a tweet-launched pool (the NFT was just minted to this contract by the factory).
/// nonReentrant so _handlePools can't be mutated mid-sweep via a reentrant launch (self-contained,
/// not reliant on the external v4 unlock-lock).
function onLaunch(uint256 poolId, uint256 handleId) external nonReentrant {
if (msg.sender != factory) revert NotFactory();
poolHandle[poolId] = handleId;
_handlePools[handleId].push(poolId);
emit HandleLaunch(handleId, poolId);
}
// ── views ──
function handlePools(uint256 handleId) external view returns (uint256[] memory) { return _handlePools[handleId]; }
function handleOwed(uint256 handleId) external view returns (uint256 total) {
uint256[] storage ps = _handlePools[handleId];
for (uint256 i; i < ps.length; i++) total += ISa1tHookFees(hook).creatorFees(ps[i]);
}
function digest(uint256 handleId, address wallet, uint256 deadline) external view returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", _domainSeparator(),
keccak256(abi.encode(CLAIM_TYPEHASH, handleId, wallet, deadline))));
}
// ── claim ──
/// Verify the X-ownership attestation, then sweep accrued ETH + hand over the fee NFT(s).
/// Submittable by anyone — funds/NFTs only ever go to the attested `wallet`.
/// One-shot: once a handle is bound to a wallet it stays bound; a fresh attestation cannot
/// re-point it (blocks stolen-session re-binds + attestation replay). The only re-point path
/// is the owner's `forceBind` clawback for genuine disputes. Future coins for an already-bound
/// handle are collected by that wallet via `sweepBound`, not `claim`.
function claim(uint256 handleId, address wallet, uint256 deadline, bytes calldata sig) external nonReentrant {
if (wallet == address(0)) revert ZeroWallet();
if (block.timestamp > deadline) revert Expired();
if (socialSigner == address(0)) revert NoSigner();
if (boundWallet[handleId] != address(0)) revert AlreadyBound();
bytes32 d = keccak256(abi.encodePacked("\x19\x01", _domainSeparator(),
keccak256(abi.encode(CLAIM_TYPEHASH, handleId, wallet, deadline))));
if (_recover(d, sig) != socialSigner) revert BadAttestation();
uint256 n = _sweep(handleId, wallet, MAX_SWEEP);
boundWallet[handleId] = wallet;
emit Bound(handleId, wallet);
emit Claimed(handleId, wallet, n);
}
/// After binding, the bound wallet collects up to MAX_SWEEP more of the handle's coins (newest
/// first). Callable repeatedly until drained. For surgical control use `sweepBoundPools`.
function sweepBound(uint256 handleId, address to) external nonReentrant returns (uint256) {
if (msg.sender != boundWallet[handleId] || msg.sender == address(0)) revert NotBound();
if (to == address(0)) revert ZeroWallet();
return _sweep(handleId, to, MAX_SWEEP);
}
/// Surgical sweep: the bound wallet names exactly which pools to collect, so a handle bloated
/// with junk pools can never block extraction of the real ones. Each pid must belong to the handle.
function sweepBoundPools(uint256 handleId, address to, uint256[] calldata poolIds)
external nonReentrant returns (uint256 n)
{
if (msg.sender != boundWallet[handleId] || msg.sender == address(0)) revert NotBound();
if (to == address(0)) revert ZeroWallet();
for (uint256 i; i < poolIds.length; i++) {
uint256 pid = poolIds[i];
if (poolHandle[pid] != handleId) continue;
if (ICreatorFeeNFT(nft).ownerOf(pid) != address(this)) continue;
if (ISa1tHookFees(hook).creatorFees(pid) > 0) ISa1tHookFees(hook).claimCreatorFees(pid, to);
ICreatorFeeNFT(nft).transferFrom(address(this), to, pid);
n++;
}
}
/// Pops up to `maxCount` pools off the end of the handle's list, sweeping each. Bounded so a
/// single call can never exceed the block gas limit; stale (already-moved) entries are skipped.
function _sweep(uint256 handleId, address to, uint256 maxCount) internal returns (uint256 n) {
uint256[] storage ps = _handlePools[handleId];
uint256 toDo = (maxCount == 0 || maxCount > ps.length) ? ps.length : maxCount;
for (uint256 i; i < toDo; i++) {
uint256 pid = ps[ps.length - 1];
ps.pop();
if (ICreatorFeeNFT(nft).ownerOf(pid) != address(this)) continue;
if (ISa1tHookFees(hook).creatorFees(pid) > 0) ISa1tHookFees(hook).claimCreatorFees(pid, to);
ICreatorFeeNFT(nft).transferFrom(address(this), to, pid);
n++;
}
}
// minimal ECDSA recover (flagship has no OZ crypto)
function _recover(bytes32 d, bytes calldata sig) internal pure returns (address) {
if (sig.length != 65) return address(0);
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := calldataload(sig.offset)
s := calldataload(add(sig.offset, 32))
v := byte(0, calldataload(add(sig.offset, 64)))
}
if (uint256(s) > _HALF_N) return address(0); // EIP-2 low-s: reject malleable signatures
if (v < 27) v += 27;
if (v != 27 && v != 28) return address(0);
return ecrecover(d, v, r, s);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@prb/math/=lib/prb-math/",
"v4-core/=lib/v4-core/",
"@uniswap/v4-core/=lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"solmate/=lib/solmate/",
"forge-std/=lib/forge-std/src/",
"permit2/=lib/v4-periphery/lib/permit2/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"prb-math/=lib/prb-math/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.