Verified contractExactMIT
AuthorRoyalties
Address0xf2cfffaef8a78e3b5a5ea3daa7b14761cae5522a
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.37
- Same code
Only this contract
Details
- Compiler
- solc 0.8.37+commit.f401782d
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- osaka
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,984,046
- Creation transaction
- 0xa9989e6619…a7b6a9e5cf
9 files
- src/treasury/AuthorRoyalties.solmain3.98 KB
- src/common/ServiceClient.sol2.38 KB
- src/common/Stewarded.sol1.73 KB
- src/common/TransientLock.sol1.35 KB
- src/interfaces/IAuthorRoyalties.sol493 B
- src/interfaces/IPluginCatalog.sol1.55 KB
- src/interfaces/ISystemDirectory.sol498 B
- src/libraries/Keys.sol1.88 KB
- src/types/PluginTypes.sol1.06 KB
src/treasury/AuthorRoyalties.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
import {ServiceClient} from "../common/ServiceClient.sol";
import {TransientLock} from "../common/TransientLock.sol";
import {IAuthorRoyalties} from "../interfaces/IAuthorRoyalties.sol";
import {IPluginCatalog} from "../interfaces/IPluginCatalog.sol";
import {Keys} from "../libraries/Keys.sol";
/// @title AuthorRoyalties
/// @notice The authors' share of revenue, and the ledger that pays it out.
///
/// Allocation is a governed act over on-chain evidence. The catalog
/// records every unit of fuel each plugin burns; this contract keeps a
/// fuel mark per plugin, so `fuelSinceMark` is exactly the work a pool
/// consumed since the plugin was last paid. The steward allocates against
/// that figure and the mark advances in the same call.
///
/// Paying pro-rata inside the swap path would put a write on every run;
/// doing it here keeps the hot path clean and the arithmetic auditable.
contract AuthorRoyalties is ServiceClient, TransientLock, IAuthorRoyalties {
mapping(address => uint256) public owedTo;
mapping(bytes32 => uint256) public fuelMark;
uint256 public override totalOwed;
event RoyaltiesFunded(address indexed from, uint256 amount);
event RoyaltyAllocated(bytes32 indexed pluginId, address indexed author, uint256 amount, uint256 fuelMark);
event RoyaltyClaimed(address indexed author, uint256 amount);
error LengthMismatch();
error ExceedsUnallocated(uint256 requested, uint256 available);
error UnknownPlugin();
error NothingOwed();
error TransferFailed();
constructor(address steward_, address directory_) ServiceClient(steward_, directory_) {}
function _serviceKeys() internal pure override returns (bytes32[] memory keys) {
keys = new bytes32[](1);
keys[0] = Keys.CATALOG;
}
receive() external payable {
emit RoyaltiesFunded(msg.sender, msg.value);
}
function fund() external payable override {
emit RoyaltiesFunded(msg.sender, msg.value);
}
function unallocated() public view override returns (uint256) {
return address(this).balance - totalOwed;
}
function allocate(bytes32[] calldata pluginIds, uint256[] calldata amounts) external onlySteward {
if (pluginIds.length != amounts.length) revert LengthMismatch();
IPluginCatalog catalog = IPluginCatalog(_service(Keys.CATALOG));
uint256 sum;
for (uint256 i; i < amounts.length; ++i) {
sum += amounts[i];
}
uint256 free = unallocated();
if (sum > free) revert ExceedsUnallocated(sum, free);
for (uint256 i; i < pluginIds.length; ++i) {
IPluginCatalog.PluginRecord memory r = catalog.recordOf(pluginIds[i]);
if (r.plugin == address(0)) revert UnknownPlugin();
owedTo[r.author] += amounts[i];
fuelMark[pluginIds[i]] = r.fuelBurned;
emit RoyaltyAllocated(pluginIds[i], r.author, amounts[i], r.fuelBurned);
}
totalOwed += sum;
}
function claim() external guarded {
uint256 amount = owedTo[msg.sender];
if (amount == 0) revert NothingOwed();
owedTo[msg.sender] = 0;
totalOwed -= amount;
(bool ok,) = msg.sender.call{value: amount}("");
if (!ok) revert TransferFailed();
emit RoyaltyClaimed(msg.sender, amount);
}
function fuelSinceMark(bytes32 pluginId) external view returns (uint256) {
uint256 burned = IPluginCatalog(_service(Keys.CATALOG)).recordOf(pluginId).fuelBurned;
uint256 mark = fuelMark[pluginId];
return burned > mark ? burned - mark : 0;
}
}
src/common/ServiceClient.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
import {Stewarded} from "./Stewarded.sol";
import {ISystemDirectory} from "../interfaces/ISystemDirectory.sol";
/// @title ServiceClient
/// @notice Base for every EVH contract that talks to its peers.
///
/// Each client declares the directory keys it depends on. `syncServices`
/// copies those bindings into local storage, so the hot path reads one
/// warm slot instead of making an external call to the directory on
/// every swap.
abstract contract ServiceClient is Stewarded {
ISystemDirectory public immutable directory;
mapping(bytes32 => address) internal _services;
event ServicesSynced(uint256 count);
error CallerNotService(bytes32 key);
error ServiceUnbound(bytes32 key);
constructor(address steward_, address directory_) Stewarded(steward_) {
if (directory_ == address(0)) revert NullAddress();
directory = ISystemDirectory(directory_);
}
/// @notice Pull this contract's dependencies from the directory.
/// @dev Permissionless: it can only copy what the directory's steward has
/// already bound.
function syncServices() external {
bytes32[] memory keys = _serviceKeys();
for (uint256 i; i < keys.length; ++i) {
_services[keys[i]] = directory.resolve(keys[i]);
}
emit ServicesSynced(keys.length);
}
function serviceAt(bytes32 key) public view returns (address) {
return _services[key];
}
/// @dev The keys this contract resolves. Implemented by each client.
function _serviceKeys() internal pure virtual returns (bytes32[] memory);
function _service(bytes32 key) internal view returns (address addr) {
addr = _services[key];
if (addr == address(0)) revert ServiceUnbound(key);
}
function _isService(bytes32 key) internal view returns (bool) {
return msg.sender == _services[key] && msg.sender != address(0);
}
modifier onlyService(bytes32 key) {
if (!_isService(key)) revert CallerNotService(key);
_;
}
}
src/common/Stewarded.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
/// @title Stewarded
/// @notice Two-step stewardship. Every EVH system contract carries one steward,
/// so the whole system can be handed to the Chronolock in a single sweep.
/// @dev A nomination never moves control on its own; the nominee has to pull
/// it. That makes a typo'd address a no-op instead of a lost protocol.
abstract contract Stewarded {
address public steward;
address public nominee;
event StewardNominated(address indexed from, address indexed to);
event StewardshipTransferred(address indexed from, address indexed to);
error CallerNotSteward();
error CallerNotNominee();
error NullAddress();
modifier onlySteward() {
if (msg.sender != steward) revert CallerNotSteward();
_;
}
constructor(address steward_) {
if (steward_ == address(0)) revert NullAddress();
steward = steward_;
emit StewardshipTransferred(address(0), steward_);
}
function nominateSteward(address to) external onlySteward {
if (to == address(0)) revert NullAddress();
nominee = to;
emit StewardNominated(steward, to);
}
function acceptStewardship() external {
if (msg.sender != nominee) revert CallerNotNominee();
address previous = steward;
steward = msg.sender;
nominee = address(0);
emit StewardshipTransferred(previous, msg.sender);
}
}
src/common/TransientLock.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
/// @title TransientLock
/// @notice Reentrancy lock held in transient storage (EIP-1153). Costs two
/// warm transient writes per guarded call and clears itself at the end
/// of the transaction even if a frame forgets to.
abstract contract TransientLock {
/// @dev keccak256("evh.lock.transient") - 1
bytes32 private constant _LOCK_SLOT = 0x24dc93f72c2c43fa63b6f76577aa82241526419fddf297282b1808bcc7c72b79;
error Reentered();
modifier guarded() {
bytes32 slot = _LOCK_SLOT;
uint256 held;
assembly ("memory-safe") {
held := tload(slot)
}
if (held != 0) revert Reentered();
assembly ("memory-safe") {
tstore(slot, 1)
}
_;
assembly ("memory-safe") {
tstore(slot, 0)
}
}
function _lockHeld() internal view returns (bool held) {
bytes32 slot = _LOCK_SLOT;
uint256 v;
assembly ("memory-safe") {
v := tload(slot)
}
held = v != 0;
}
}
src/interfaces/IAuthorRoyalties.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
interface IAuthorRoyalties {
function fund() external payable;
function totalOwed() external view returns (uint256);
function unallocated() external view returns (uint256);
}
src/interfaces/IPluginCatalog.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
import {PluginState} from "../types/PluginTypes.sol";
interface IPluginCatalog {
struct PluginRecord {
address plugin;
address author;
bytes32 codehash;
uint16 phaseMask;
uint32 fuelCap;
uint8 permits;
PluginState state;
uint8 strikes;
uint64 enrolledAt;
uint256 runs;
uint256 faults;
uint256 fuelBurned;
}
function pluginIdOf(address plugin) external view returns (bytes32);
function recordOf(bytes32 pluginId) external view returns (PluginRecord memory);
function labelsOf(bytes32 pluginId)
external
view
returns (string memory label, string memory semver, string memory sourceURI);
function isRunnable(bytes32 pluginId) external view returns (bool);
function runnableMask(bytes32[] calldata pluginIds) external view returns (bool[] memory);
function logRun(bytes32 pluginId, uint256 fuel, bool ok) external;
function penalize(bytes32 pluginId, bytes calldata revertData) external;
function pluginCount() external view returns (uint256);
function pluginIdAt(uint256 index) external view returns (bytes32);
function totalFuelBurned() external view returns (uint256);
}
src/interfaces/ISystemDirectory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
interface ISystemDirectory {
function resolve(bytes32 key) external view returns (address);
function entries() external view returns (bytes32[] memory keys, address[] memory addrs);
}
src/libraries/Keys.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
/// @title Keys
/// @notice SystemDirectory binding keys. The deploy script and the frontend
/// derive the same values as `keccak256("evh.service.<NAME>")`.
library Keys {
bytes32 internal constant TOKEN = keccak256("evh.service.TOKEN");
bytes32 internal constant SCANNER = keccak256("evh.service.SCANNER");
bytes32 internal constant ACCESS = keccak256("evh.service.ACCESS");
bytes32 internal constant STAKE_VAULT = keccak256("evh.service.STAKE_VAULT");
bytes32 internal constant BONDS = keccak256("evh.service.BONDS");
bytes32 internal constant FUEL = keccak256("evh.service.FUEL");
bytes32 internal constant MEMORY = keccak256("evh.service.MEMORY");
bytes32 internal constant CATALOG = keccak256("evh.service.CATALOG");
bytes32 internal constant BOARD = keccak256("evh.service.BOARD");
bytes32 internal constant RUNTIME = keccak256("evh.service.RUNTIME");
bytes32 internal constant JOBS = keccak256("evh.service.JOBS");
bytes32 internal constant SPLITTER = keccak256("evh.service.SPLITTER");
bytes32 internal constant BUYBACK = keccak256("evh.service.BUYBACK");
bytes32 internal constant ROYALTIES = keccak256("evh.service.ROYALTIES");
bytes32 internal constant FORGE = keccak256("evh.service.FORGE");
bytes32 internal constant HYPERVISOR = keccak256("evh.service.HYPERVISOR");
bytes32 internal constant CHRONOLOCK = keccak256("evh.service.CHRONOLOCK");
bytes32 internal constant COUNCIL = keccak256("evh.service.COUNCIL");
bytes32 internal constant LENS = keccak256("evh.service.LENS");
}
src/types/PluginTypes.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.37;
// ▄▄▄▄▄ ▄ ▄ ▄ ▄
// █▄▄▄ ▀▄ ▄▀ █▄▄▄█ EVH · Ethereum Virtual Hook
// █▄▄▄▄ ▀ █ █ plugin hypervisor for Uniswap V4
//
// ethereumvirtualhook.xyz · x.com/VirtualHookETH
/// @notice Lifecycle of an enrolled plugin.
enum PluginState {
None, // 0 never enrolled
Probation, // 1 runs; open permits only
Certified, // 2 Council-approved; every asked permit granted
Suspended, // 3 skipped at dispatch, recoverable
Slashed, // 4 struck out; bond seized; unseated everywhere
Exiled // 5 terminal, Council-imposed
}
/// @notice What a plugin says about itself. `PluginCatalog.enroll` requires the
/// caller's declaration to match this byte for byte.
struct PluginSpec {
string label;
string semver;
uint16 phaseMask; // bit i => Phase(i)
uint32 fuelCap; // per-run gas ceiling the plugin asks for
uint8 permits; // asked permit mask, see Permits
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "osaka",
"remappings": [
"v4-core/=lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"@uniswap/v4-core/=lib/v4-core/",
"forge-std/=lib/forge-std/src/",
"solmate/=lib/v4-core/lib/solmate/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"permit2/=lib/v4-periphery/lib/permit2/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.