Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts/proxy/Clones.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/Clones.sol)
pragma solidity ^0.8.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*
* _Available since v3.4._
*/
library Clones {
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create(0, 0x09, 0x37)
}
require(instance != address(0), "ERC1167: create failed");
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create2(0, 0x09, 0x37, salt)
}
require(instance != address(0), "ERC1167: create2 failed");
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := keccak256(add(ptr, 0x43), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddress(implementation, salt, address(this));
}
}
"
},
"@openzeppelin/contracts/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/Address.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
"
},
"contracts/common/UniversalFactory.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Admin, Address, LibErrors, LibAdmin} from "../utils/Admin.sol";
import {UpgradeableProxy} from "./UpgradeableProxy.sol";
import {LibTransferType} from "../utils/LibTransferType.sol";
interface IWithdrawable {
/**
* @notice Withdraws specified tokens from the clone contract to a recipient.
* @param token Address of the token to withdraw (address(0) for ETH).
* @param recipient Address of the recipient.
* @param amount Amount of tokens to withdraw.
* @param transferType The type of transfer (normal, safe, or custom).
* @return success True if the withdrawal is successful.
*/
function universalTransfer(
address token,
address recipient,
uint256 amount,
LibTransferType.TransferType transferType
) external returns (bool success);
}
/**
* @title UniversalFactory
* @dev A contract for creating and managing clones of a proxy contract with deterministic addresses.
* Extends the Admin contract for access control and withdrawal management.
*/
contract UniversalFactory is Admin {
using Address for address;
/// @notice Address of the proxy contract used as the implementation for clones.
address public immutable PROXY;
/**
* @notice Constructor that initializes the factory contract.
* @param withdrawal_ The address used for withdrawals.
*/
constructor(address withdrawal_) {
super._initAdmin(msg.sender, address(this), withdrawal_);
address proxy = address(new UpgradeableProxy());
if (proxy == address(0)) revert LibErrors.CreatedProxyFailed();
PROXY = proxy;
}
/**
* @notice Fallback function to receive ETH.
* @dev Emits a `Received` event for logging received ETH.
*/
receive() external payable {
emit Received(msg.sender, msg.value);
}
/**
* @notice Creates a deterministic clone of the proxy contract.
* @param _salt Unique salt used for deterministic address generation.
* @return cloneAddress The address of the created clone.
* @dev Emits `CloneCreated` event upon success.
*/
function createClone(bytes32 _salt) external onlyOwner returns (address cloneAddress) {
// Access withdrawal from the storage
address withdrawal_ = LibAdmin._storage().withdrawal;
// Create a deterministic clone of the proxy contract
cloneAddress = Clones.cloneDeterministic(PROXY, _salt);
if (cloneAddress == address(0)) revert LibErrors.CreatedCloneFailed();
UpgradeableProxy(payable(cloneAddress)).initProxy(msg.sender, address(this), withdrawal_);
// Emit an event for clone creation
emit CloneCreated(cloneAddress, withdrawal_, owner());
}
/**
* @notice Withdraws assets from multiple clones to a recipient.
* @param clones Array of clone addresses.
* @param amounts Array of amounts to withdraw from each clone.
* @param recipient The address receiving the withdrawn funds.
* @param token Address of the token to withdraw (address(0) for ETH).
* @dev Emits a `Withdrawn` event for each withdrawal.
*/
function withdrawAssetsFromClones(
address[] calldata clones,
uint256[] calldata amounts,
address recipient,
address token,
LibTransferType.TransferType transferType
) external onlyOwner {
if (recipient == address(0)) revert LibErrors.InvalidAddressRecipient();
uint256 length = clones.length;
if (length == 0 || length != amounts.length) revert LibErrors.ArrayLengthMismatch();
for (uint256 i = 0; i < length; ) {
address cloneAddress = clones[i];
if (cloneAddress == address(0)) revert LibErrors.InvalidAddressClone();
bool success = IWithdrawable(cloneAddress).universalTransfer(token, recipient, amounts[i], transferType);
if (!success) revert LibErrors.WithdrawFailed(recipient, amounts[i]);
unchecked {
++i;
}
}
}
/**
* @notice Predicts the address of a deterministic clone before it is created.
* @param _salt The salt used for address generation.
* @return predictedAddress The predicted address of the clone.
*/
function predictAddress(bytes32 _salt) external view returns (address predictedAddress) {
return Clones.predictDeterministicAddress(PROXY, _salt, address(this));
}
}
"
},
"contracts/common/UpgradeableProxy.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import {Admin, Address, LibAdmin, LibErrors} from "../utils/Admin.sol";
/**
* @title UpgradeableProxy
* @dev A proxy contract that forwards calls to an implementation (withdrawal) address.
* The implementation address can be updated by the owner.
*/
contract UpgradeableProxy is Admin {
using Address for address;
/**
* @notice Fallback function to handle ETH transfers.
* @dev Emits a `Received` event for logging received ETH.
*/
receive() external payable {
emit Received(msg.sender, msg.value);
}
/**
* @notice Fallback function to delegate calls to the withdrawal implementation.
* @dev This function delegates all calls to the withdrawal address using `_delegate`.
*/
fallback() external payable {
LibAdmin._checkAdmin(msg.sender);
_delegate();
}
/**
* @notice Initializes the proxy with the withdrawal implementation and sets the owner.
* @param owner_ The address of the owner.
* @param factory_ The address of the factory contract.
* @param withdrawal_ The address of the withdrawals contract for proxy.
* @dev Can only be called once. Emits a `ProxyInitialized` event.
*/
function initProxy(address owner_, address factory_, address withdrawal_) external returns (bool) {
super._initAdmin(owner_, factory_, withdrawal_);
LibAdmin._checkFactory(msg.sender);
emit ProxyInitialized(address(this), withdrawal_, owner_);
return true;
}
/**
* @notice Delegates the current call to the withdrawal implementation.
* @dev Private function that delegates the call using inline assembly.
*/
function _delegate() private {
address impl = LibAdmin._storage().withdrawal;
if (impl == address(0)) revert LibErrors.InvalidAddressWithdrawal();
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
}
"
},
"contracts/utils/Admin.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {LibAdmin, IEvents, LibErrors} from "./LibAdmin.sol";
/**
* @title Admin
* @dev This contract manages access control for the system by leveraging the LibAdmin library.
* It provides functionality for owner, factory, and admin roles, as well as updating key configuration fields.
*/
contract Admin is Initializable, IEvents {
using Address for address;
/**
* @dev Modifier to restrict access to the owner of the contract.
*/
modifier onlyOwner() {
LibAdmin._checkOwner(msg.sender);
_;
}
/**
* @notice Sets admin status for a list of accounts.
* @dev Only the owner can call this function.
* Emits an event for each account's admin status change.
* @param accounts_ List of addresses to update admin status for.
* @param isAdmin_ True to grant admin rights, false to revoke.
* @return True if the operation is successful.
*/
function setAdmin(address[] calldata accounts_, bool isAdmin_) public onlyOwner returns (bool) {
return LibAdmin._setAdmin(accounts_, isAdmin_);
}
/**
* @notice Updates the factory address.
* @dev Only the owner can call this function.
* Emits a `FieldUpdated` event upon success.
* @param factory_ New address for the factory.
* @return True if the operation is successful.
*/
function updateFactory(address factory_) public onlyOwner returns (bool) {
return LibAdmin._updateField(factory_, LibAdmin.Field.Factory);
}
/**
* @notice Updates the withdrawal address.
* @dev Only the owner can call this function.
* Emits a `FieldUpdated` event upon success.
* @param withdrawal_ New address for withdrawals.
* @return True if the operation is successful.
*/
function updateWithdrawal(address withdrawal_) public onlyOwner returns (bool) {
return LibAdmin._updateField(withdrawal_, LibAdmin.Field.Withdrawal);
}
/**
* @notice Returns the owner of the contract.
* @dev This function fetches the owner from the LibAdmin storage.
* @return Address of the current owner.
*/
function owner() public view returns (address) {
return LibAdmin._owner();
}
/**
* @notice Returns the factory address.
* @dev This function fetches the factory address from the LibAdmin storage.
* @return Address of the current factory.
*/
function factory() public view returns (address) {
return LibAdmin._factory();
}
/**
* @notice Returns the withdrawal address.
* @dev This function fetches the withdrawal address from the LibAdmin storage.
* @return Address of the current withdrawal.
*/
function withdrawal() public view returns (address) {
return LibAdmin._withdrawal();
}
/**
* @notice Checks if an account is an admin.
* @param account_ The address to check for admin status.
* @return True if the account is an admin, otherwise false.
*/
function isAdmined(address account_) public view returns (bool) {
return LibAdmin._isAdmined(account_);
}
/**
* @dev Initializes the Admin contract with owner, factory, and withdrawal addresses.
* @param owner_ Address of the contract owner.
* @param factory_ Address of the factory contract.
* @param withdrawal_ Address for withdrawal of funds.
*/
function _initAdmin(address owner_, address factory_, address withdrawal_) internal initializer {
LibAdmin._initialize(owner_, factory_, withdrawal_);
}
}
"
},
"contracts/utils/IEvents.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
/**
* @title IEvents
* @dev This library defines events used across the system for logging key actions and changes.
*/
interface IEvents {
/**
* @notice Emitted when the admin system is initialized.
* @param owner The address of the owner.
* @param factory The address of the factory contract.
* @param withdrawal The address of the withdrawals contract for proxy.
*/
event AdminInitialized(address indexed owner, address indexed factory, address indexed withdrawal);
/**
* @notice Emitted when an account's admin status is changed.
* @param account The address of the account whose status is changed.
* @param status The new admin status (true = granted, false = revoked).
*/
event AdminStatusChanged(address indexed account, bool status);
/**
* @notice Emitted when a new clone contract is created.
* @param clone The address of the newly created clone contract.
* @param withdrawal The withdrawal address used by the clone.
* @param owner The owner of the clone.
*/
event CloneCreated(address indexed clone, address indexed withdrawal, address indexed owner);
/**
* @notice Emitted when a specific field is updated.
* @param field The updated field (e.g., "Factory" or "Withdrawal").
* @param oldValue The old address value of the field.
* @param newValue The new address value of the field.
*/
event FieldUpdated(bytes32 field, address indexed oldValue, address indexed newValue);
/**
* @notice Emitted when the contract receives ETH.
* @param sender The address that sent the ETH.
* @param amount The amount of ETH received.
*/
event Received(address indexed sender, uint256 indexed amount);
/**
* @notice Emitted when a proxy contract is initialized.
* @param proxy The address of the proxy contract.
* @param withdrawal The withdrawal address used by the proxy.
* @param owner The owner of the proxy.
*/
event ProxyInitialized(address indexed proxy, address indexed withdrawal, address indexed owner);
/**
* @notice Emitted when the factory address is updated.
* @param oldFactory The previous factory address.
* @param newFactory The new factory address.
*/
event UpdateFactory(address indexed oldFactory, address indexed newFactory);
/**
* @notice Emitted when a withdrawal is made from the contract.
* @param token The address of the token being withdrawn (address(0) for ETH).
* @param recipient The address receiving the withdrawn funds.
* @param amount The amount withdrawn.
*/
event Withdrawn(address indexed token, address indexed recipient, uint256 indexed amount);
/**
* @notice Emitted when the withdrawal address is updated.
* @param old The previous withdrawal address.
* @param newWithdrawal The new withdrawal address.
*/
event WithdrawalUpdated(address indexed old, address indexed newWithdrawal);
}
"
},
"contracts/utils/LibAdmin.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {LibErrors} from "./LibErrors.sol";
import {IEvents} from "./IEvents.sol";
/**
* @title LibAdmin
* @dev A library for managing admin roles, ownership, and key configuration fields. This library provides reusable
* storage access and validation methods for roles and permissions.
*/
library LibAdmin {
using Address for address;
/**
* @dev Storage structure for admin-related data.
* @param owner The address of the owner.
* @param factory The address of the factory contract.
* @param withdrawal The address of the withdrawals contract for proxy.
* @param admins A mapping of addresses with admin privileges.
*/
struct Storage {
address owner;
address factory;
address withdrawal;
mapping(address => bool) admins;
}
/**
* @dev Enum representing fields that can be updated via `_updateField`.
*/
enum Field {
Factory,
Withdrawal
}
/// @dev The storage slot used for storing the admin-related data.
bytes32 private constant STORAGE_SLOT = keccak256("create2.admin.storage");
/**
* @notice Initializes the admin system with specified owner, factory, and withdrawal addresses.
* @param owner_ The address of the owner.
* @param factory_ The address of the factory contract.
* @param withdrawal_ The address of the withdrawals contract for proxy.
* @dev Emits `AdminInitialized` event.
*/
function _initialize(address owner_, address factory_, address withdrawal_) internal {
if (owner_ == address(0)) revert LibErrors.InvalidAddressOwner();
if (factory_ == address(0)) revert LibErrors.InvalidAddressFactory();
if (withdrawal_ == address(0)) revert LibErrors.InvalidAddressWithdrawal();
Storage storage s = _storage();
s.owner = owner_;
s.factory = factory_;
s.withdrawal = withdrawal_;
s.admins[owner_] = true;
s.admins[factory_] = true;
emit IEvents.AdminInitialized(owner_, factory_, withdrawal_);
}
/**
* @notice Updates admin privileges for a list of accounts.
* @param accounts_ The list of accounts to update.
* @param isAdmin_ True to grant admin rights, false to revoke.
* @return True if the operation is successful.
* @dev Emits `AdminStatusChanged` for each account updated.
* @dev Reverts with `CannotRemoveOwner` if attempting to revoke admin rights from the owner.
*/
function _setAdmin(address[] calldata accounts_, bool isAdmin_) internal returns (bool) {
uint256 length = accounts_.length;
if (length == 0) revert LibErrors.ArrayAccountsCantBeZero();
Storage storage s = _storage();
for (uint256 i = 0; i < length; ) {
address account = accounts_[i];
if (account == address(0)) revert LibErrors.InvalidAddressAdmin();
if (account == s.owner && !isAdmin_) revert LibErrors.CannotRemoveOwner();
if (s.admins[account] != isAdmin_) {
s.admins[account] = isAdmin_;
emit IEvents.AdminStatusChanged(account, isAdmin_);
}
unchecked {
++i;
}
}
return true;
}
/**
* @notice Updates a specific field (factory or withdrawal).
* @param newValue_ The new address value for the field.
* @param field The field to update (Factory or Withdrawal).
* @return True if the update is successful.
* @dev Emits `FieldUpdated` event on success.
* @dev Reverts with `InvalidAddressField` for an invalid address or `InvalidField` for an unknown field.
*/
function _updateField(address newValue_, Field field) internal returns (bool) {
if (newValue_ == address(0)) revert LibErrors.InvalidAddressField();
Storage storage s = _storage();
address oldValue;
if (field == Field.Factory) {
oldValue = s.factory;
s.factory = newValue_;
} else if (field == Field.Withdrawal) {
oldValue = s.withdrawal;
s.withdrawal = newValue_;
} else {
revert LibErrors.InvalidField(keccak256(abi.encodePacked(field)));
}
emit IEvents.FieldUpdated(keccak256(abi.encodePacked(field)), oldValue, newValue_);
return true;
}
/**
* @notice Validates that the caller is the owner.
* @param owner_ The address to validate as the owner.
* @dev Reverts with `OnlyOwner` if the validation fails.
*/
function _checkOwner(address owner_) internal view {
if (_owner() != owner_) revert LibErrors.OnlyOwner(owner_);
}
/**
* @notice Validates that the caller is the factory.
* @param factory_ The address to validate as the factory.
* @dev Reverts with `OnlyFactory` if the validation fails.
*/
function _checkFactory(address factory_) internal view {
if (_factory() != factory_) revert LibErrors.OnlyFactory(factory_);
}
/**
* @notice Validates that the caller is an admin.
* @param admin_ The address to validate as an admin.
* @dev Reverts with `OnlyAdmin` if the validation fails.
*/
function _checkAdmin(address admin_) internal view {
if (!_isAdmined(admin_)) revert LibErrors.OnlyAdmin(admin_);
}
/**
* @notice Returns the owner of the system.
* @return The address of the current owner.
*/
function _owner() internal view returns (address) {
return _storage().owner;
}
/**
* @notice Returns the factory address.
* @return The address of the factory contract.
*/
function _factory() internal view returns (address) {
return _storage().factory;
}
/**
* @notice Returns the withdrawal address.
* @return The address used for withdrawals.
*/
function _withdrawal() internal view returns (address) {
return _storage().withdrawal;
}
/**
* @notice Checks if an account has admin privileges.
* @param account_ The account to check.
* @return True if the account is an admin, otherwise false.
*/
function _isAdmined(address account_) internal view returns (bool) {
return _storage().admins[account_];
}
/**
* @notice Returns the storage structure for admin-related data.
* @return s The `Storage` structure for managing admin data.
*/
function _storage() internal pure returns (Storage storage s) {
bytes32 slot = STORAGE_SLOT;
assembly {
s.slot := slot
}
}
}
"
},
"contracts/utils/LibErrors.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
/**
* @title LibErrors
* @dev This library defines custom errors used across the system, grouped by category for better organization.
*/
library LibErrors {
// ========================
// System errors
// ========================
error Revert43();
// ========================
// Address-related errors
// ========================
/**
* @notice Thrown when an invalid admin address is provided.
*/
error InvalidAddressAdmin();
/**
* @notice Thrown when an invalid clone address is provided.
*/
error InvalidAddressClone();
/**
* @notice Thrown when an invalid factory address is provided.
*/
error InvalidAddressFactory();
/**
* @notice Thrown when an invalid field address is provided.
*/
error InvalidAddressField();
/**
* @notice Thrown when an invalid owner address is provided.
*/
error InvalidAddressOwner();
/**
* @notice Thrown when an invalid recipient address is provided.
*/
error InvalidAddressRecipient();
/**
* @notice Thrown when an invalid token address is provided.
*/
error InvalidAddressToken();
/**
* @notice Thrown when an invalid withdrawal address is provided.
*/
error InvalidAddressWithdrawal();
// ========================
// Access control errors
// ========================
/**
* @notice Thrown when the caller is not an admin.
*/
error OnlyAdmin(address caller);
/**
* @notice Thrown when the caller is not the factory.
*/
error OnlyFactory(address caller);
/**
* @notice Thrown when the caller is not the owner.
*/
error OnlyOwner(address caller);
/**
* @notice Thrown when attempting to remove the owner as an admin.
*/
error CannotRemoveOwner();
// ========================
// Array-related errors
// ========================
/**
* @notice Thrown when the length of two arrays does not match.
*/
error ArrayLengthMismatch();
/**
* @notice Thrown when the array of accounts is empty.
*/
error ArrayAccountsCantBeZero();
/**
* @notice Thrown when the array of recipients is empty.
*/
error ArrayRecipientsCantBeZero();
// ========================
// Token and amount errors
// ========================
/**
* @notice Thrown when the amount is zero or less.
*/
error AmountMustBeGreaterThanZero();
/**
* @dev Error to be thrown when transfer parameters are invalid, such as zero amount or invalid address.
*/
error InvalidTransferParameters();
/**
* @notice Thrown when the token amounts provided are zero.
*/
error TokenAmountsCantBeZero();
/**
* @notice Thrown when the transfer type is unsupported.
*/
error UnsupportedTransferType();
/**
* @notice Thrown when the transfer type is TransferType.Transfer and not returns true
*/
error TokenTransferFailed1();
/**
* @notice Thrown when the transfer type is TransferType.UnsafeTransferNoCheckBool
or UnsafeTransferNoCheckResultLength and not return true
*/
error TokenTransferFailed2();
/**
* @notice Thrown when the transfer type is TransferType.UnsafeTransferNoCheckBool and result length is not 0
*/
error TokenTransferFailed3();
/**
* @notice Thrown when the universal transfer fails.
*/
error UniversalTransferFailed(address token, address to, uint256 amount);
/**
* @notice Thrown when a withdrawal fails.
*/
error WithdrawFailed(address recipient, uint256 amount);
// ========================
// Clone-related errors
// ========================
/**
* @notice Thrown when no clones are provided.
*/
error NoClonesProvided();
/**
* @notice Thrown when the number of clones and amounts does not match.
*/
error ClonesNotEqualAmounts();
/**
* @notice Thrown when the creation of a proxy contract fails.
*/
error CreatedProxyFailed();
/**
* @notice Thrown when the creation of a clone contract fails.
*/
error CreatedCloneFailed();
// ========================
// General errors
// ========================
/**
* @notice Thrown when an invalid field is provided.
*/
error InvalidField(bytes32 provided);
/**
* @notice Thrown when there is an insufficient balance for an operation.
*/
error InsufficientBalance(uint256 balance, uint256 required);
/**
* @notice Thrown when withdrawal amounts do not match the expected total.
*/
error WithdrawalNotEqual();
}
"
},
"contracts/utils/LibTransferType.sol": {
"content": "// TransferTypeLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
library LibTransferType {
/// @notice Enum for transfer types.
enum TransferType {
Transfer, // = 0 - Standard ERC20 transfer (returns bool)
SafeTransfer, // = 1 - OpenZeppelin SafeERC20 safeTransfer. Should prefer use this for most tokens
UnsafeTransferNoCheckBool, // = 2 - For tokens like USDT TRC20 that do not return a boolean
UnsafeTransferNoCheckResultLength // = 3 If token not returns any value in transfer method.
// WARNING: NoCheckResultLength transfer will NOT fail even if transfer method or contract not exist!
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
}
}
}}
Submitted on: 2025-10-01 17:20:06
Comments
Log in to comment.
No comments yet.