Verified contractExactMIT
RevenueRouter
Address0xa91c9be387d1d82c75dbafdcc6d4e50e4f2379b9
- Balance
0 ETH
- Transactions
4
- 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
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,101,826
- Creation transaction
- 0xeaa8fcfdf7…2f53cf0dcb
src/Funding.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
/// @notice Splits ETH receipts 70% treasury / 20% creator / 10% protocol.
/// An AMM fee collector must explicitly send fees here; this does not collect fees itself.
/// Treasury and creator shares round down per receipt; the protocol receives the remaining wei.
contract RevenueRouter is ReentrancyGuard {
address public immutable treasury;
address public immutable creator;
address public immutable protocol;
uint16 public constant treasuryBps = 7_000;
uint16 public constant creatorBps = 2_000;
uint16 public constant protocolBps = 1_000;
mapping(address => uint256) public claimable;
event Revenue(
address indexed payer, uint256 amount, uint256 treasuryShare, uint256 creatorShare, uint256 protocolShare
);
event Claimed(address indexed beneficiary, address indexed destination, uint256 amount);
constructor(address treasury_, address creator_, address protocol_) {
require(treasury_ != address(0) && creator_ != address(0) && protocol_ != address(0), "zero recipient");
treasury = treasury_;
creator = creator_;
protocol = protocol_;
}
receive() external payable {
uint256 operating = msg.value * treasuryBps / 10_000;
uint256 human = msg.value * creatorBps / 10_000;
uint256 platform = msg.value - operating - human;
claimable[treasury] += operating;
claimable[creator] += human;
claimable[protocol] += platform;
emit Revenue(msg.sender, msg.value, operating, human, platform);
}
/// Anyone can deliver a beneficiary's share to that beneficiary, never redirect it.
function distribute(address payable beneficiary) external nonReentrant {
_pay(beneficiary, beneficiary);
}
/// A beneficiary can choose an alternate destination for its own share.
function claim(address payable destination) external nonReentrant {
require(destination != address(0), "zero destination");
_pay(msg.sender, destination);
}
function _pay(address beneficiary, address payable destination) private {
uint256 amount = claimable[beneficiary];
require(amount > 0, "nothing owed");
claimable[beneficiary] = 0;
(bool ok,) = destination.call{value: amount}("");
require(ok, "transfer failed");
emit Claimed(beneficiary, destination, amount);
}
}
/// @notice Simple customer-controlled job escrow. Hashes prove commitment, not correctness.
/// Customer acceptance pays the worker; after the agreed deadline the customer may refund.
/// This trades worker payment assurance for customer protection; no automatic arbitration.
contract JobEscrow is ReentrancyGuard {
struct Job {
address customer;
address worker;
uint256 value;
uint64 deadline;
bytes32 briefHash;
bytes32 resultHash;
bool closed;
}
mapping(bytes32 => Job) public jobs;
event Opened(
bytes32 indexed id,
address indexed customer,
address indexed worker,
uint256 value,
uint64 deadline,
bytes32 briefHash
);
event Submitted(bytes32 indexed id, bytes32 resultHash);
event Closed(bytes32 indexed id, bool accepted);
function open(bytes32 salt, address worker, uint64 deadline, bytes32 briefHash)
external
payable
returns (bytes32 id)
{
require(msg.value > 0 && worker != address(0) && briefHash != bytes32(0), "invalid job");
require(deadline > block.timestamp && deadline <= block.timestamp + 30 days, "invalid deadline");
id = keccak256(abi.encode(msg.sender, salt));
require(jobs[id].customer == address(0), "duplicate job");
jobs[id] = Job(msg.sender, worker, msg.value, deadline, briefHash, bytes32(0), false);
emit Opened(id, msg.sender, worker, msg.value, deadline, briefHash);
}
function submit(bytes32 id, bytes32 resultHash) external {
Job storage j = jobs[id];
require(msg.sender == j.worker && !j.closed, "worker only or closed");
require(block.timestamp < j.deadline && resultHash != bytes32(0), "invalid submission");
j.resultHash = resultHash;
emit Submitted(id, resultHash);
}
function accept(bytes32 id) external nonReentrant {
Job storage j = jobs[id];
require(msg.sender == j.customer && !j.closed, "customer only or closed");
require(j.resultHash != bytes32(0), "no result");
j.closed = true;
(bool ok,) = j.worker.call{value: j.value}("");
require(ok, "transfer failed");
emit Closed(id, true);
}
function refund(bytes32 id) external nonReentrant {
Job storage j = jobs[id];
require(msg.sender == j.customer && !j.closed, "customer only or closed");
require(block.timestamp >= j.deadline, "not expired");
j.closed = true;
(bool ok,) = j.customer.call{value: j.value}("");
require(ok, "transfer failed");
emit Closed(id, false);
}
}
lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*
* IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
* by the {ReentrancyGuardTransient} variant in v6.0.
*
* @custom:stateless
*/
abstract contract ReentrancyGuard {
using StorageSlot for bytes32;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
/**
* @dev A `view` only version of {nonReentrant}. Use to block view functions
* from being called, preventing reading from inconsistent contract state.
*
* CAUTION: This is a "view" modifier and does not change the reentrancy
* status. Use it only on view functions. For payable or non-payable functions,
* use the standard {nonReentrant} modifier instead.
*/
modifier nonReentrantView() {
_nonReentrantBeforeView();
_;
}
function _nonReentrantBeforeView() private view {
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
_nonReentrantBeforeView();
// Any calls to nonReentrant after this point will fail
_reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
}
function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
return REENTRANCY_GUARD_STORAGE;
}
}
lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/=lib/openzeppelin-contracts/",
"forge-std/=lib/forge-std/src/",
"v4-core/=lib/v4-core/",
"@uniswap/v4-core/=lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"solmate/=lib/solmate/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.