Verified contractExactUNLICENSED
CiretaSaleFactory
Address0x43fbf3bca3107e46cb1f71c17df14d1734769cfd
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 100 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,388,510
- Creation transaction
- 0x1db925c53b…92bd2ff122
53 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/platform/CiretaSaleFactory.solmain19.17 KB
- @openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol8.28 KB
- @openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol3.51 KB
- @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol4.05 KB
- @openzeppelin/contracts-upgradeable/access/extensions/AccessControlDefaultAdminRulesUpgradeable.sol17.23 KB
- @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol144 B
- @openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol148 B
- @openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol17.14 KB
- @openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol12.15 KB
- @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol1.22 KB
- @openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol1.17 KB
- @openzeppelin/contracts/access/IAccessControl.sol3.34 KB
- @openzeppelin/contracts/access/extensions/IAccessControlDefaultAdminRules.sol8.18 KB
- @openzeppelin/contracts/interfaces/IERC1363.sol4.45 KB
- @openzeppelin/contracts/interfaces/IERC165.sol193 B
- @openzeppelin/contracts/interfaces/IERC1967.sol637 B
- @openzeppelin/contracts/interfaces/IERC20.sol182 B
- @openzeppelin/contracts/interfaces/IERC5313.sol435 B
- @openzeppelin/contracts/interfaces/draft-IERC1822.sol882 B
- @openzeppelin/contracts/interfaces/draft-IERC6093.sol6.54 KB
- @openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol2.64 KB
- @openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol6.26 KB
- @openzeppelin/contracts/proxy/Proxy.sol2.7 KB
- @openzeppelin/contracts/proxy/beacon/IBeacon.sol473 B
- @openzeppelin/contracts/proxy/utils/Initializable.sol9.28 KB
- @openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol6.32 KB
- @openzeppelin/contracts/token/ERC1155/IERC1155.sol4.75 KB
- @openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol2.6 KB
- @openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol677 B
- @openzeppelin/contracts/token/ERC1155/utils/ERC1155Utils.sol3.55 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.78 KB
- @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol13.31 KB
- @openzeppelin/contracts/utils/Address.sol6.8 KB
- @openzeppelin/contracts/utils/Arrays.sol35.17 KB
- @openzeppelin/contracts/utils/Comparators.sol443 B
- @openzeppelin/contracts/utils/Errors.sol896 B
- @openzeppelin/contracts/utils/LowLevelCall.sol5.55 KB
- @openzeppelin/contracts/utils/Panic.sol1.97 KB
- @openzeppelin/contracts/utils/ReentrancyGuard.sol4.77 KB
- @openzeppelin/contracts/utils/SlotDerivation.sol5.32 KB
- @openzeppelin/contracts/utils/StorageSlot.sol4.18 KB
- @openzeppelin/contracts/utils/introspection/IERC165.sol871 B
- @openzeppelin/contracts/utils/math/Math.sol32.66 KB
- @openzeppelin/contracts/utils/math/SafeCast.sol34.94 KB
- src/access/SingleAdminAccessControlUpgradeable.sol6.7 KB
- src/fraction/CiretaFractionToken1155.sol13.46 KB
- src/interfaces/ICiretaIdentityRegistry.sol1.39 KB
- src/otc/IssuerOTCToken.sol13.84 KB
- src/platform/CiretaFractionFactory.sol10.82 KB
- src/platform/IssuerRegistry.sol16.49 KB
- src/sale/Sale.sol74.14 KB
- src/vault/CiretaVault.sol29.48 KB
src/platform/CiretaSaleFactory.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../sale/Sale.sol";
import "./CiretaFractionFactory.sol";
import "./IssuerRegistry.sol";
/// @dev CiretaTokenFactory surface (tokenIssuer is added by the token fix group).
interface ISaleTokenFactoryView {
function isDeployedToken(address token) external view returns (bool);
function tokenIssuer(address token) external view returns (address);
}
/// @dev IssuerOTCTokenFactory surface (isDeployedOTCToken is added by the OTC fix group).
interface ISaleOTCFactoryView {
function isDeployedOTCToken(address otc) external view returns (bool);
}
/// @dev IssuerOTCToken surface.
interface ISaleOTCTokenView {
function issuerWallet() external view returns (address);
}
/// @dev PlatformFeeManager surface: rotation-aware fee bps and absolute fee cap.
interface ISaleFeeManagerView {
function getFeeForIssuer(address issuer) external view returns (uint256);
function getFeeCapForIssuer(address issuer) external view returns (uint256);
}
/// @dev Project-token surface used to pin the token to the platform identity registry.
interface ISaleProjectTokenView {
function identityRegistry() external view returns (address);
}
/**
* @title CiretaSaleFactory
* @notice Deploys Sale proxies (and, for vested sales, their vault + fraction pair) for active
* issuers, after verifying EVERY security-relevant initialize() parameter:
* token (platform-deployed, issued by the caller, on the platform IR), payment token
* (governance allowlist, 6 decimals), identity registry (platform IR), fee manager / fee
* bps / fee cap (platform PFM), and OTC token (platform-deployed, issued by the caller).
*
* Roles (platform role model):
* - governance = owner() — TimelockController (Ownable2Step, renounce disabled). Upgrades
* this factory, sets config, and is the upgrade authority of every Sale it deploys.
* - operator — Ops Safe: approve / reject / unpause / force-fail sales, recover fractions,
* settle a failed sale's OTC holders.
* - guardian — pause-only Safe / bot; may also engage the operator kill switch
* (suspendOperator), which only governance lifts.
* Sales, vaults and fractions resolve these live through governance() / operator() /
* guardian(). Vested deploys snapshot governance into the vault / fraction, so they
* revert while governance is not a contract.
* @custom:security-contact [email protected]
*/
contract CiretaSaleFactory is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable {
address public saleImplementation;
CiretaFractionFactory public fractionFactory;
mapping(address => address[]) public tokenSales;
address[] public allSales;
// Issuer-centric deployment
IssuerRegistry public issuerRegistry;
address public platformFeeManager;
mapping(address => address[]) public issuerSales;
/// @dev Platform operator (Ops Safe); read through operator() (zero while suspended).
address private _operator;
/// @notice Platform guardian — may pause sales, never unpause.
address public guardian;
/// @notice Platform identity registry every sale, vault and fraction must use.
address public identityRegistry;
/// @notice CiretaTokenFactory — sale tokens must be deployed by it for the calling issuer.
address public tokenFactory;
/// @notice IssuerOTCTokenFactory — OTC tokens must be deployed by it for the calling issuer.
address public otcTokenFactory;
/// @notice Governance allowlist of payment tokens (6 decimals enforced).
mapping(address => bool) public allowedPaymentToken;
/// @notice Incremented on every UUPS upgrade.
uint256 public upgradeNonce;
/// @dev Guardian / governance kill switch: while true, operator() is address(0).
bool private _operatorSuspended;
/// @dev Reserved storage gap for future upgrades
uint256[99] private __gap;
event SaleDeployed(
address indexed token,
address indexed sale,
address indexed issuer
);
event SaleImplementationUpdated(address indexed oldImpl, address indexed newImpl);
event FractionFactoryUpdated(address indexed oldFactory, address indexed newFactory);
event IssuerRegistrySet(address indexed registry);
event PlatformFeeManagerSet(address indexed feeManager);
event OperatorUpdated(address indexed oldOperator, address indexed newOperator);
event GuardianUpdated(address indexed oldGuardian, address indexed newGuardian);
event IdentityRegistrySet(address indexed registry);
event TokenFactorySet(address indexed tokenFactory);
event OTCTokenFactorySet(address indexed otcTokenFactory);
event PaymentTokenAllowed(address indexed paymentToken, bool allowed);
event OperatorSuspended(address indexed operator, address indexed by);
/// @notice Emitted on every UUPS upgrade.
event ImplementationUpgraded(address indexed newImplementation, uint256 nonce);
error NotActiveIssuer();
error FeeMismatch();
error IssuerMismatch();
error FactoryMismatch();
error TokenMismatch();
error RegistryMismatch();
error PaymentTokenNotAllowed();
error InvalidPaymentTokenDecimals();
error InvalidOTCToken();
error NotConfigured();
error ZeroAddress();
error NotAContract();
error RenounceDisabled();
error GovernanceNotContract(address owner);
error NotGuardian(address caller);
error SeatHolderIsIssuer(address account);
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() { _disableInitializers(); }
/// @param initialOwner Platform governance (timelock).
function initialize(
address initialOwner,
address _saleImplementation
) public initializer {
__Ownable_init(initialOwner);
__Ownable2Step_init();
if (_saleImplementation.code.length == 0) revert NotAContract();
saleImplementation = _saleImplementation;
}
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
upgradeNonce++;
emit ImplementationUpgraded(newImplementation, upgradeNonce);
}
/// @notice Contract version.
function version() external pure returns (string memory) { return "7.1.0"; }
/// @notice Platform governance (= owner). Upgrade authority of every Sale.
function governance() external view returns (address) {
return owner();
}
/// @notice Disabled: renouncing would orphan every Sale's upgrade path.
function renounceOwnership() public pure override {
revert RenounceDisabled();
}
// ── Configuration (governance-only) ─────────────────────────────────────
function setSaleImplementation(address impl) external onlyOwner {
if (impl.code.length == 0) revert NotAContract();
address old = saleImplementation;
saleImplementation = impl;
emit SaleImplementationUpdated(old, impl);
}
function setFractionFactory(address _fractionFactory) external onlyOwner {
if (_fractionFactory.code.length == 0) revert NotAContract();
address old = address(fractionFactory);
fractionFactory = CiretaFractionFactory(_fractionFactory);
emit FractionFactoryUpdated(old, _fractionFactory);
}
function setIssuerRegistry(address _registry) external onlyOwner {
if (_registry.code.length == 0) revert NotAContract();
issuerRegistry = IssuerRegistry(_registry);
emit IssuerRegistrySet(_registry);
}
function setPlatformFeeManager(address _feeManager) external onlyOwner {
if (_feeManager.code.length == 0) revert NotAContract();
platformFeeManager = _feeManager;
emit PlatformFeeManagerSet(_feeManager);
}
/// @notice Set the platform operator (Ops Safe). Takes effect on every Sale, vault and fraction
/// immediately; clears an operator suspension.
function setOperator(address newOperator) external onlyOwner {
if (newOperator == address(0)) revert ZeroAddress();
_requireNotIssuer(newOperator);
emit OperatorUpdated(_operator, newOperator);
_operator = newOperator;
_operatorSuspended = false;
}
/// @notice The live platform operator of every Sale (zero while suspended).
function operator() public view returns (address) {
return _operatorSuspended ? address(0) : _operator;
}
/// @notice True while the guardian kill switch is engaged.
function isOperatorSuspended() external view returns (bool) {
return _operatorSuspended;
}
/// @notice Instant containment of a compromised operator: every Sale, vault and fraction
/// stops recognizing it at once. Guardian or governance; only governance lifts it
/// (setOperator). Part of the guardian's kill-switch batch with the TokenFactory switch and
/// the registries' guardianRevoke.
function suspendOperator() external {
if (msg.sender != guardian && msg.sender != owner()) revert NotGuardian(msg.sender);
_operatorSuspended = true;
emit OperatorSuspended(_operator, msg.sender);
}
/// @notice Set the platform guardian (pause-only). Takes effect on every Sale immediately.
function setGuardian(address _guardian) external onlyOwner {
if (_guardian == address(0)) revert ZeroAddress();
_requireNotIssuer(_guardian);
emit GuardianUpdated(guardian, _guardian);
guardian = _guardian;
}
/// @dev An issuer never holds the operator or guardian seat of its own sales.
function _requireNotIssuer(address account) private view {
if (address(issuerRegistry) != address(0)
&& issuerRegistry.statusOf(account) != IssuerRegistry.IssuerStatus.None) {
revert SeatHolderIsIssuer(account);
}
}
/// @notice Pin the platform identity registry used by every new sale, vault and fraction.
function setIdentityRegistry(address _registry) external onlyOwner {
if (_registry.code.length == 0) revert NotAContract();
identityRegistry = _registry;
emit IdentityRegistrySet(_registry);
}
/// @notice Set the CiretaTokenFactory whose tokens may be sold.
function setTokenFactory(address _tokenFactory) external onlyOwner {
if (_tokenFactory.code.length == 0) revert NotAContract();
tokenFactory = _tokenFactory;
emit TokenFactorySet(_tokenFactory);
}
/// @notice Set the IssuerOTCTokenFactory whose OTC tokens sales may accept.
function setOTCTokenFactory(address _otcTokenFactory) external onlyOwner {
if (_otcTokenFactory.code.length == 0) revert NotAContract();
otcTokenFactory = _otcTokenFactory;
emit OTCTokenFactorySet(_otcTokenFactory);
}
/// @notice Allow or disallow a payment token (production: the chain's canonical USDC only).
/// Allowed tokens must have 6 decimals.
function setPaymentTokenAllowed(address paymentToken, bool allowed) external onlyOwner {
if (paymentToken.code.length == 0) revert NotAContract();
if (allowed && IERC20Metadata(paymentToken).decimals() != 6) revert InvalidPaymentTokenDecimals();
allowedPaymentToken[paymentToken] = allowed;
emit PaymentTokenAllowed(paymentToken, allowed);
}
// ── Modifiers ───────────────────────────────────────────────────────────
modifier onlyActiveIssuer() {
if (address(issuerRegistry) == address(0) || !issuerRegistry.isActiveIssuer(msg.sender)) {
revert NotActiveIssuer();
}
_;
}
// ── Sale Deployment (issuer-initiated) ──────────────────────────────────
/**
* @notice Deploy a new Direct-mode Sale proxy for `token`.
* @dev initData must encode Sale.initialize(); every security-relevant field is verified
* after deployment (see _verifySale) and the whole deploy reverts on any mismatch.
*/
function deploySale(
address token,
bytes calldata initData
) external onlyActiveIssuer returns (address sale) {
sale = address(new ERC1967Proxy(saleImplementation, initData));
_verifySale(sale, token);
_registerSystemContract(identityRegistry, sale);
_record(token, sale);
}
/**
* @notice Deploy a new Vested-mode Sale proxy with its vault + fraction token.
* @dev The vault and fraction use the platform identity registry and the verified
* Sale.token(); the vault's issuer is the sale issuer; per-instance admin powers go to
* governance / operator (never to an EOA snapshot). Fraction decimals follow the token.
* @param cliffDuration Seconds after finalization before any vesting.
* @param vestingDuration Seconds after finalization until fully vested (>= cliff).
*/
function deploySaleVested(
address token,
bytes calldata initData,
string memory fractionName,
string memory fractionSymbol,
uint256 cliffDuration,
uint256 vestingDuration
) external onlyActiveIssuer returns (address sale, address vaultAddr, address fractionAddr) {
if (address(fractionFactory) == address(0) || operator() == address(0)) revert NotConfigured();
address gov = owner();
if (!_isContractAccount(gov)) revert GovernanceNotContract(gov);
sale = address(new ERC1967Proxy(saleImplementation, initData));
_verifySale(sale, token);
(fractionAddr, vaultAddr) = fractionFactory.deployVaultAndFraction(
fractionName, fractionSymbol,
token, identityRegistry, sale, msg.sender,
cliffDuration, vestingDuration,
gov
);
// Only this factory may configure vested mode (Sale checks msg.sender == factory).
Sale(sale).setVestedMode(vaultAddr, fractionAddr);
_registerSystemContract(identityRegistry, sale);
_record(token, sale);
}
// ── Views used by Sale ──────────────────────────────────────────────────
/// @notice True when `otc` was deployed by the platform OTC factory for `issuer`.
function isValidOTCToken(address otc, address issuer) public view returns (bool) {
if (otcTokenFactory == address(0) || otc.code.length == 0) return false;
if (!ISaleOTCFactoryView(otcTokenFactory).isDeployedOTCToken(otc)) return false;
return ISaleOTCTokenView(otc).issuerWallet() == issuer;
}
// ── Internal Helpers ────────────────────────────────────────────────────
function _record(address token, address sale) private {
tokenSales[token].push(sale);
allSales.push(sale);
issuerSales[msg.sender].push(sale);
emit SaleDeployed(token, sale, msg.sender);
}
/// @dev Register `contractAddr` as a platform system contract. Reverts (failing the whole
/// deployment) if the registry is unset or this factory lacks SYSTEM_REGISTRAR_ROLE:
/// an unregistered escrow could not hold or deliver permissioned tokens.
function _registerSystemContract(address registry, address contractAddr) private {
if (registry == address(0)) revert NotConfigured();
ISimpleIdentityRegistry(registry).registerSystemContract(contractAddr);
}
/// @dev Verify every security-relevant field of a freshly initialized Sale.
function _verifySale(address sale, address token) internal view {
address pfm = platformFeeManager;
address ir = identityRegistry;
address tf = tokenFactory;
if (pfm == address(0) || ir == address(0) || tf == address(0)) revert NotConfigured();
Sale s = Sale(sale);
if (s.issuer() != msg.sender) revert IssuerMismatch();
if (s.factory() != address(this)) revert FactoryMismatch();
// Token: argument == Sale.token(), deployed by the platform token factory for this
// issuer, and bound to the platform identity registry.
if (s.token() != token) revert TokenMismatch();
if (!ISaleTokenFactoryView(tf).isDeployedToken(token)) revert TokenMismatch();
if (ISaleTokenFactoryView(tf).tokenIssuer(token) != msg.sender) revert TokenMismatch();
if (ISaleProjectTokenView(token).identityRegistry() != ir) revert RegistryMismatch();
// KYC gate.
if (address(s.identityRegistry()) != ir) revert RegistryMismatch();
// Fees: platform PFM, PFM bps, PFM cap (a hard call, never a silent fallback).
if (s.feeManager() != pfm) revert FeeMismatch();
if (s.feeBasisPoints() != ISaleFeeManagerView(pfm).getFeeForIssuer(msg.sender)) revert FeeMismatch();
if (s.feeCapUsdc() != ISaleFeeManagerView(pfm).getFeeCapForIssuer(msg.sender)) revert FeeMismatch();
// Payment token: governance allowlist, 6 decimals.
address pay = address(s.paymentToken());
if (!allowedPaymentToken[pay]) revert PaymentTokenNotAllowed();
if (IERC20Metadata(pay).decimals() != 6) revert InvalidPaymentTokenDecimals();
// OTC token: none, or platform-deployed for this issuer.
address otc = address(s.otcToken());
if (otc != address(0) && !isValidOTCToken(otc, msg.sender)) revert InvalidOTCToken();
}
/// @dev True if `account` has code that is not an EIP-7702 delegation designator.
function _isContractAccount(address account) private view returns (bool) {
uint256 size = account.code.length;
if (size == 0) return false;
if (size == 23 && bytes3(account.code) == 0xef0100) return false;
return true;
}
// ── View ────────────────────────────────────────────────────────────────
function getSalesForToken(address token) external view returns (address[] memory) {
return tokenSales[token];
}
function getSalesForIssuer(address issuerAddr) external view returns (address[] memory) {
return issuerSales[issuerAddr];
}
function totalSales() external view returns (uint256) {
return allSales.length;
}
}
Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 100,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.