Verified contractExactMIT
CauseRegistry
Address0xaa4ca19493ced06267c7dc25f55f8f84933655ea
- 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
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,359,853
- Creation transaction
- 0xf145fa9d04…99c0dba274
6 files
- src/CauseRegistry.solmain7.1 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol2.48 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol1.39 KB
- src/interfaces/ICauseRegistry.sol4.27 KB
- src/interfaces/external/IEndaomentOrgFundFactory.sol724 B
src/CauseRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {Ownable, Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {ICauseRegistry} from "./interfaces/ICauseRegistry.sol";
import {IEndaomentOrgFundFactory} from "./interfaces/external/IEndaomentOrgFundFactory.sol";
/// @title CauseRegistry
/// @notice Allowlist of nonprofit causes. Causes are never removed, only deactivated, so
/// historical epoch results always resolve to an org. The owner adds or blocks causes
/// directly; the epoch governor materializes catalogue orgs (`CauseCatalog`) on demand
/// when one wins an epoch.
/// @dev Each cause stores the Endaoment org id and the org's CREATE2 address. The address is
/// checked against the Endaoment factory's `computeOrgAddress` whenever it is written, so a
/// mistyped address can never be registered. The org itself may not be deployed yet; the
/// distributor deploys it on first donation.
contract CauseRegistry is ICauseRegistry, Ownable2Step {
/// @notice Endaoment OrgFundFactory used to derive and verify org addresses.
IEndaomentOrgFundFactory public immutable endaomentFactory;
error ZeroAddress();
error OrgAddressMismatch(bytes32 orgId, address expected, address actual);
mapping(bytes32 causeId => Cause) private _causes;
/// @dev Distinguishes "never added" from "added then deactivated".
mapping(bytes32 causeId => bool) private _exists;
bytes32[] private _ids;
mapping(address account => bool) private _materializers;
constructor(address initialOwner, IEndaomentOrgFundFactory endaomentFactory_)
Ownable(initialOwner)
{
if (address(endaomentFactory_) == address(0)) revert ZeroAddress();
endaomentFactory = endaomentFactory_;
}
/// @inheritdoc ICauseRegistry
function addCause(
bytes32 causeId,
bytes32 orgId,
address orgAddress,
string calldata metadataURI
) external onlyOwner {
if (orgId == bytes32(0)) revert ZeroOrgId();
if (orgAddress == address(0)) revert ZeroPayout();
if (_exists[causeId]) revert CauseAlreadyExists(causeId);
_verifyOrg(orgId, orgAddress);
_store(causeId, orgId, orgAddress, true);
if (bytes(metadataURI).length != 0) _causes[causeId].metadataURI = metadataURI;
emit CauseAdded(causeId, orgAddress);
}
/// @inheritdoc ICauseRegistry
function deactivateCause(bytes32 causeId) external onlyOwner {
if (!_exists[causeId]) revert CauseNotFound(causeId);
// Idempotent: deactivating twice is a no-op and emits nothing.
if (!_causes[causeId].active) return;
_causes[causeId].active = false;
emit CauseDeactivated(causeId);
}
/// @inheritdoc ICauseRegistry
function blockOrg(bytes32 orgId) external onlyOwner returns (bytes32 causeId) {
if (orgId == bytes32(0)) revert ZeroOrgId();
causeId = causeIdOf(orgId);
if (_exists[causeId]) {
if (_causes[causeId].active) {
_causes[causeId].active = false;
emit CauseDeactivated(causeId);
}
return causeId;
}
address orgAddress = endaomentFactory.computeOrgAddress(orgId);
_store(causeId, orgId, orgAddress, false);
emit CauseAdded(causeId, orgAddress);
emit CauseDeactivated(causeId);
}
/// @inheritdoc ICauseRegistry
function setMaterializer(address account, bool allowed) external onlyOwner {
if (account == address(0)) revert ZeroAddress();
_materializers[account] = allowed;
emit MaterializerSet(account, allowed);
}
/// @inheritdoc ICauseRegistry
function materialize(bytes32 orgId) external returns (bytes32 causeId) {
if (!_materializers[msg.sender]) revert NotMaterializer(msg.sender);
if (orgId == bytes32(0)) revert ZeroOrgId();
causeId = causeIdOf(orgId);
if (_exists[causeId]) return causeId;
address orgAddress = endaomentFactory.computeOrgAddress(orgId);
_store(causeId, orgId, orgAddress, true);
emit CauseAdded(causeId, orgAddress);
emit CauseMaterialized(causeId, orgId, orgAddress);
}
/// @inheritdoc ICauseRegistry
/// @dev Sets the org address. It must equal the factory's `computeOrgAddress` for the stored
/// org id. Works on deactivated causes too.
function updatePayout(bytes32 causeId, address newPayout) external onlyOwner {
if (!_exists[causeId]) revert CauseNotFound(causeId);
if (newPayout == address(0)) revert ZeroPayout();
bytes32 orgId = _causes[causeId].orgId;
if (orgId == bytes32(0)) revert ZeroOrgId();
_verifyOrg(orgId, newPayout);
address oldPayout = _causes[causeId].orgAddress;
_causes[causeId].orgAddress = newPayout;
emit PayoutUpdated(causeId, oldPayout, newPayout);
}
/// @inheritdoc ICauseRegistry
function getCause(bytes32 causeId) external view returns (Cause memory) {
if (!_exists[causeId]) revert CauseNotFound(causeId);
return _causes[causeId];
}
/// @inheritdoc ICauseRegistry
function orgOf(bytes32 causeId) external view returns (bytes32 orgId, address orgAddress) {
if (!_exists[causeId]) revert CauseNotFound(causeId);
Cause storage c = _causes[causeId];
return (c.orgId, c.orgAddress);
}
/// @inheritdoc ICauseRegistry
function isActive(bytes32 causeId) external view returns (bool) {
return _causes[causeId].active;
}
/// @inheritdoc ICauseRegistry
function exists(bytes32 causeId) external view returns (bool) {
return _exists[causeId];
}
/// @inheritdoc ICauseRegistry
function isBlocked(bytes32 causeId) external view returns (bool) {
return _exists[causeId] && !_causes[causeId].active;
}
/// @inheritdoc ICauseRegistry
function isMaterializer(address account) external view returns (bool) {
return _materializers[account];
}
/// @notice Cause id of a catalogue org: `keccak256` of its 32-byte org id.
function causeIdOf(bytes32 orgId) public pure returns (bytes32) {
return keccak256(abi.encode(orgId));
}
/// @inheritdoc ICauseRegistry
function causeCount() external view returns (uint256) {
return _ids.length;
}
/// @inheritdoc ICauseRegistry
function causeIdAt(uint256 index) external view returns (bytes32) {
return _ids[index];
}
function _store(bytes32 causeId, bytes32 orgId, address orgAddress, bool active) private {
_exists[causeId] = true;
_causes[causeId] =
Cause({orgId: orgId, orgAddress: orgAddress, metadataURI: "", active: active});
_ids.push(causeId);
}
function _verifyOrg(bytes32 orgId, address orgAddress) private view {
address expected = endaomentFactory.computeOrgAddress(orgId);
if (expected != orgAddress) revert OrgAddressMismatch(orgId, expected, orgAddress);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*
* IMPORTANT: Deprecated in favor of accessing `msg.sender` and `msg.data` directly. This contract, along with its
* `_msgSender`, `_msgData` and `_contextSuffixLength` functions, will be removed in v6.0, where contracts read
* `msg.sender` and `msg.data` directly. Contracts that override `_msgSender`/`_msgData` (e.g. to support
* meta-transactions) will lose that extension point; plan the migration before upgrading.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/interfaces/ICauseRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
/// @title ICauseRegistry
/// @notice Allowlist of nonprofit causes eligible to receive funds.
interface ICauseRegistry {
/// @notice A registered cause.
/// @param orgId Endaoment org id: bytes32 of the EIN digits (no hyphen), left-aligned.
/// @param orgAddress CREATE2 address of the Endaoment org entity (may not be deployed yet).
/// @param metadataURI Cause metadata URI.
/// @param active Whether the cause can currently be voted for and paid.
struct Cause {
bytes32 orgId;
address orgAddress;
string metadataURI;
bool active;
}
/// @notice Emitted when a cause is added.
event CauseAdded(bytes32 indexed causeId, address payout);
/// @dev `payout` in CauseAdded/PayoutUpdated is the org's CREATE2 address.
/// @notice Emitted when a cause is deactivated.
event CauseDeactivated(bytes32 indexed causeId);
/// @notice Emitted when a cause's payout address changes.
event PayoutUpdated(bytes32 indexed causeId, address oldPayout, address newPayout);
/// @notice Emitted when an account is allowed or disallowed to materialize causes.
event MaterializerSet(address indexed account, bool allowed);
/// @notice Emitted when a catalogue org is written to the registry on demand (as active).
event CauseMaterialized(bytes32 indexed causeId, bytes32 indexed orgId, address payout);
error NotMaterializer(address caller);
error CauseAlreadyExists(bytes32 causeId);
error CauseNotFound(bytes32 causeId);
error ZeroPayout();
error ZeroOrgId();
/// @notice Adds a cause. `causeId` is the keccak256 of the nonprofit's organization id string.
/// `orgAddress` is the org's CREATE2 address (factory.computeOrgAddress(orgId)).
function addCause(
bytes32 causeId,
bytes32 orgId,
address orgAddress,
string calldata metadataURI
) external;
/// @notice Deactivates a cause.
function deactivateCause(bytes32 causeId) external;
/// @notice Records `orgId` as a deactivated cause whether or not it was ever added, so a
/// catalogue org that must not receive funds can never be drawn, pinned or
/// materialized. Owner only. Returns its cause id.
function blockOrg(bytes32 orgId) external returns (bytes32 causeId);
/// @notice Allows or disallows `account` (the epoch governor) to materialize causes.
function setMaterializer(address account, bool allowed) external;
/// @notice Writes catalogue org `orgId` as an active cause with its factory-computed address,
/// unless a cause with its id already exists (active or not), which is left untouched.
/// Materializers only. Returns the cause id, `keccak256(abi.encode(orgId))`.
function materialize(bytes32 orgId) external returns (bytes32 causeId);
/// @notice Whether `causeId` was ever added, materialized or blocked.
function exists(bytes32 causeId) external view returns (bool);
/// @notice Whether `causeId` exists and is deactivated (blocked from ballots and payouts).
function isBlocked(bytes32 causeId) external view returns (bool);
/// @notice Whether `account` may materialize causes.
function isMaterializer(address account) external view returns (bool);
/// @notice Changes a cause's org address (for example if the org was re-derived).
function updatePayout(bytes32 causeId, address newPayout) external;
/// @notice Returns a cause.
function getCause(bytes32 causeId) external view returns (Cause memory);
/// @notice Endaoment org id and org address of a cause, without its metadata string. Reverts
/// `CauseNotFound` for an unknown cause (deactivated causes still resolve).
function orgOf(bytes32 causeId) external view returns (bytes32 orgId, address orgAddress);
/// @notice Whether `causeId` exists and is active.
function isActive(bytes32 causeId) external view returns (bool);
/// @notice Number of causes ever added.
function causeCount() external view returns (uint256);
/// @notice Cause id at `index` in insertion order.
function causeIdAt(uint256 index) external view returns (bytes32);
}
src/interfaces/external/IEndaomentOrgFundFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
/// @notice Minimal view of the Endaoment OrgFundFactory (Ethereum mainnet).
interface IEndaomentOrgFundFactory {
/// @notice CREATE2 address of the org for `orgId`, whether or not it is deployed.
function computeOrgAddress(bytes32 orgId) external view returns (address);
/// @notice Deploys the org (reverts if already deployed), pulls `amount` USDC from the caller
/// (allowance spender is the factory) and credits the org.
function deployOrgAndDonate(bytes32 orgId, uint256 amount) external returns (address org);
function registry() external view returns (address);
function baseToken() external view returns (address);
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@uniswap/v4-core/=lib/v4-core/",
"@uniswap/v4-periphery/=lib/v4-periphery/",
"v4-core/=lib/v4-core/src/",
"v4-periphery/=lib/v4-periphery/src/",
"solmate/=lib/v4-core/lib/solmate/",
"permit2/=lib/v4-periphery/lib/permit2/",
"@fhevm/solidity/=node_modules/@fhevm/solidity/",
"encrypted-types/=node_modules/encrypted-types/",
"@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/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.