Contract Name:
AGWRegistry
Contract Source Code:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
import {Ownable, Ownable2Step} from '@openzeppelin/contracts/access/Ownable2Step.sol';
import {Errors} from './libraries/Errors.sol';
import {IAGWRegistry} from './interfaces/IAGWRegistry.sol';
contract AGWRegistry is Ownable2Step, IAGWRegistry {
mapping(address => bool) public isFactory;
// Mapping of AGW accounts
mapping(address => bool) public isAGW;
/**
* @notice Event emmited when a factory contract is set
* @param factory address - Address of the factory contract
*/
event FactorySet(address indexed factory);
/**
* @notice Event emmited when a factory contract is unset
* @param factory address - Address of the factory contract
*/
event FactoryUnset(address indexed factory);
// Constructor function of the contracts
constructor(address _owner) Ownable(_owner) {}
/**
* @notice Registers an account as a AGW account
* @dev Can only be called by the factory or owner
* @param account address - Address of the account to register
*/
function register(address account) external override {
if (!isFactory[msg.sender] && msg.sender != owner()) {
revert Errors.NOT_FROM_FACTORY();
}
isAGW[account] = true;
}
/**
* @notice Registers multiple accounts as AGW accounts
* @dev Can only be called by the factory or owner
* @param accounts address[] - Array of addresses to register
*/
function registerMultiple(address[] calldata accounts) external {
if (!isFactory[msg.sender] && msg.sender != owner()) {
revert Errors.NOT_FROM_FACTORY();
}
for (uint256 i = 0; i < accounts.length; i++) {
isAGW[accounts[i]] = true;
}
}
/**
* @notice Unregisters an account as a AGW account
* @dev Can only be called by the factory or owner
* @param account address - Address of the account to unregister
*/
function unregister(address account) external {
if (!isFactory[msg.sender] && msg.sender != owner()) {
revert Errors.NOT_FROM_FACTORY();
}
isAGW[account] = false;
}
/**
* @notice Unregisters multiple accounts as AGW accounts
* @dev Can only be called by the factory or owner
* @param accounts address[] - Array of addresses to unregister
*/
function unregisterMultiple(address[] calldata accounts) external {
if (!isFactory[msg.sender] && msg.sender != owner()) {
revert Errors.NOT_FROM_FACTORY();
}
for (uint256 i = 0; i < accounts.length; i++) {
isAGW[accounts[i]] = false;
}
}
/**
* @notice Sets a new factory contract
* @dev Can only be called by the owner
* @param factory_ address - Address of the new factory
*/
function setFactory(address factory_) external onlyOwner {
isFactory[factory_] = true;
emit FactorySet(factory_);
}
/**
* @notice Unsets a factory contract
* @dev Can only be called by the owner
* @param factory_ address - Address of the factory
*/
function unsetFactory(address factory_) external onlyOwner {
isFactory[factory_] = false;
emit FactoryUnset(factory_);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
library Errors {
/*//////////////////////////////////////////////////////////////
AGW
//////////////////////////////////////////////////////////////*/
error INSUFFICIENT_FUNDS(); // 0xe7931438
error FEE_PAYMENT_FAILED(); // 0x3d40a3a3
error UNAUTHORIZED_OUTSIDE_TRANSACTION(); // 0xfc82da4e
error VALIDATION_HOOK_FAILED(); // 0x52c9d27a
/*//////////////////////////////////////////////////////////////
LINKED LIST
//////////////////////////////////////////////////////////////*/
error INVALID_PREV(); // 0x5a4c0eb3
// Bytes
error INVALID_BYTES(); // 0xb6dfaaff
error BYTES_ALREADY_EXISTS(); // 0xdf6cac6b
error BYTES_NOT_EXISTS(); // 0x689908a6
// Address
error INVALID_ADDRESS(); // 0x5963709b
error ADDRESS_ALREADY_EXISTS(); // 0xf2d4d191
error ADDRESS_NOT_EXISTS(); // 0xad6ab975
/*//////////////////////////////////////////////////////////////
OWNER MANAGER
//////////////////////////////////////////////////////////////*/
error EMPTY_OWNERS(); // 0xc957eb7e
error INVALID_PUBKEY_LENGTH(); // 0x04c4d8f7
/*//////////////////////////////////////////////////////////////
VALIDATOR MANAGER
//////////////////////////////////////////////////////////////*/
error EMPTY_VALIDATORS(); // 0xd7c64d89
error VALIDATOR_ERC165_FAIL(); // 0x5d5273ad
/*//////////////////////////////////////////////////////////////
UPGRADE MANAGER
//////////////////////////////////////////////////////////////*/
error SAME_IMPLEMENTATION(); // 0x5e741005
/*//////////////////////////////////////////////////////////////
HOOK MANAGER
//////////////////////////////////////////////////////////////*/
error EMPTY_HOOK_ADDRESS(); // 0x413348ae
error HOOK_ERC165_FAIL(); // 0x9f93f87d
error INVALID_KEY(); // 0xce7045bd
/*//////////////////////////////////////////////////////////////
MODULE MANAGER
//////////////////////////////////////////////////////////////*/
error EMPTY_MODULE_ADDRESS(); // 0x912fe2f2
error RECUSIVE_MODULE_CALL(); // 0x2cf7b9c8
error MODULE_ERC165_FAIL(); // 0xc1ad2a50
/*//////////////////////////////////////////////////////////////
AUTH
//////////////////////////////////////////////////////////////*/
error NOT_FROM_BOOTLOADER(); // 0x93887e3b
error NOT_FROM_MODULE(); // 0x574a805d
error NOT_FROM_HOOK(); // 0xd675a4f1
error NOT_FROM_SELF(); // 0xa70c28d1
error NOT_FROM_SELF_OR_MODULE(); // 0x22a1259f
/*//////////////////////////////////////////////////////////////
R1 VALIDATOR
//////////////////////////////////////////////////////////////*/
error INVALID_SIGNATURE(); // 0xa3402a38
/*//////////////////////////////////////////////////////////////
SOCIAL RECOVERY
//////////////////////////////////////////////////////////////*/
error INVALID_RECOVERY_CONFIG(); // 0xf774f439
error INVALID_RECOVERY_NONCE(); // 0x098c9f8e
error INVALID_GUARDIAN(); // 0x11a2a82b
error INVALID_GUARDIAN_SIGNATURE(); // 0xcc117c1c
error ZERO_ADDRESS_GUARDIAN(); // 0x6de9b401
error GUARDIANS_MUST_BE_SORTED(); // 0xc52b41f7
error RECOVERY_TIMELOCK(); // 0x1506ac5a
error RECOVERY_NOT_STARTED(); // 0xa6a4a3aa
error RECOVERY_NOT_INITED(); // 0xd0f6fdbf
error RECOVERY_IN_PROGRESS(); // 0x8daa42a9
error INSUFFICIENT_GUARDIANS(); // 0x7629075d
error ALREADY_INITED(); // 0xdb0c77c8
/*//////////////////////////////////////////////////////////////
FACTORY
//////////////////////////////////////////////////////////////*/
error DEPLOYMENT_FAILED(); // 0x0f02d218
error INITIALIZATION_FAILED(); // 0x5b101091
error INVALID_INITIALIZER(); // 0x350366d7
error INVALID_SALT(); // 0x8b3152e6
error ALREADY_CREATED(); // 0x26ebf2e8
/*//////////////////////////////////////////////////////////////
PAYMASTER
//////////////////////////////////////////////////////////////*/
error UNSUPPORTED_FLOW(); // 0xd721e389
error UNAUTHORIZED_WITHDRAW(); // 0x7809a0b4
error INVALID_TOKEN(); // 0xd0995cf2
error SHORT_PAYMASTER_INPUT(); // 0x48d170f6
error UNSUPPORTED_TOKEN(); // 0xce706f70
error LESS_ALLOWANCE_FOR_PAYMASTER(); // 0x11f7d13f
error FAILED_FEE_TRANSFER(); // 0xf316e09d
error INVALID_MARKUP(); // 0x4af7ffe3
error USER_LIMIT_REACHED(); // 0x07235346
error INVALID_USER_LIMIT(); // 0x2640fa41
error NOT_AGW_ACCOUNT(); // 0x1ae1d6fd
error EXCEEDS_MAX_SPONSORED_ETH(); // 0x3f379f40
/*//////////////////////////////////////////////////////////////
REGISTRY
//////////////////////////////////////////////////////////////*/
error NOT_FROM_FACTORY(); // 0x238438ed
error NOT_FROM_DEPLOYER(); // 0x83f090e3
/*//////////////////////////////////////////////////////////////
BatchCaller
//////////////////////////////////////////////////////////////*/
error ONLY_DELEGATECALL(); // 0x43d22ee9
error CALL_FAILED(); // 0x84aed38d
/*//////////////////////////////////////////////////////////////
INITABLE
//////////////////////////////////////////////////////////////*/
error MODULE_NOT_ADDED_CORRECTLY(); // 0xb66e8ec4
error MODULE_NOT_REMOVED_CORRECTLY(); // 0x680c8744
error MsgValueMismatch(uint256 actualValue, uint256 expectedValue);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
interface IAGWRegistry {
function register(address account) external;
function isAGW(address account) external view returns (bool);
}
// 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);
}
}
// 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);
}
}
// 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.
*/
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;
}
}