Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Rename contracts and function to be 'AGW' instead of 'Clave' (#18)
Browse files Browse the repository at this point in the history
* Rename contracts and function to be 'AGW' instead of 'Clave'

Leave attribution for original Clave contracts, but rename anything referencing Clave in the actual contract code to ensure that these are clearly AGW contracts onchain.

* fix test
  • Loading branch information
coffeexcoin authored Dec 18, 2024
1 parent a34c603 commit f33c24c
Show file tree
Hide file tree
Showing 36 changed files with 153 additions and 144 deletions.
14 changes: 8 additions & 6 deletions contracts/ClaveImplementation.sol → contracts/AGWAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ import {SignatureDecoder} from './libraries/SignatureDecoder.sol';
import {ERC1271Handler} from './handlers/ERC1271Handler.sol';
import {Call} from './batch/BatchCaller.sol';

import {IClaveAccount} from './interfaces/IClave.sol';
import {IAGWAccount} from './interfaces/IAGWAccount.sol';
import {AccountFactory} from './AccountFactory.sol';
import {BatchCaller} from './batch/BatchCaller.sol';

/**
* @title Main account contract for the Clave wallet infrastructure, forked for Abstract
* @title Main account contract for the Abstract Global Wallet infrastructure
* @dev Forked from Clave for Abstract
* @dev The Abstract fork uses a K1 signer and validator initially
* @author https://getclave.io
* @author https://abs.xyz
*/
contract ClaveImplementation is
contract AGWAccount is
Initializable,
UpgradeManager,
HookManager,
ModuleManager,
ERC1271Handler,
TokenCallbackHandler,
BatchCaller,
IClaveAccount
IAGWAccount
{
// Helper library for the Transaction struct
using TransactionHelper for Transaction;
Expand Down Expand Up @@ -237,12 +239,12 @@ contract ClaveImplementation is
transaction.processPaymasterInput();
}

/// @dev type(IClave).interfaceId indicates Clave accounts
/// @dev type(IAGWAccount).interfaceId indicates AGW accounts
function supportsInterface(
bytes4 interfaceId
) public view override(IERC165, TokenCallbackHandler) returns (bool) {
return
interfaceId == type(IClaveAccount).interfaceId || super.supportsInterface(interfaceId);
interfaceId == type(IAGWAccount).interfaceId || super.supportsInterface(interfaceId);
}

function _validateTransaction(
Expand Down
24 changes: 12 additions & 12 deletions contracts/ClaveRegistry.sol → contracts/AGWRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pragma solidity ^0.8.17;
import {Ownable, Ownable2Step} from '@openzeppelin/contracts/access/Ownable2Step.sol';

import {Errors} from './libraries/Errors.sol';
import {IClaveRegistry} from './interfaces/IClaveRegistry.sol';
import {IAGWRegistry} from './interfaces/IAGWRegistry.sol';

contract ClaveRegistry is Ownable2Step, IClaveRegistry {
contract AGWRegistry is Ownable2Step, IAGWRegistry {
mapping(address => bool) public isFactory;
// Mapping of Clave accounts
mapping(address => bool) public isClave;
// Mapping of AGW accounts
mapping(address => bool) public isAGW;

/**
* @notice Event emmited when a factory contract is set
Expand All @@ -27,7 +27,7 @@ contract ClaveRegistry is Ownable2Step, IClaveRegistry {
constructor(address _owner) Ownable(_owner) {}

/**
* @notice Registers an account as a Clave account
* @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
*/
Expand All @@ -36,11 +36,11 @@ contract ClaveRegistry is Ownable2Step, IClaveRegistry {
revert Errors.NOT_FROM_FACTORY();
}

isClave[account] = true;
isAGW[account] = true;
}

/**
* @notice Registers multiple accounts as Clave accounts
* @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
*/
Expand All @@ -50,12 +50,12 @@ contract ClaveRegistry is Ownable2Step, IClaveRegistry {
}

for (uint256 i = 0; i < accounts.length; i++) {
isClave[accounts[i]] = true;
isAGW[accounts[i]] = true;
}
}

/**
* @notice Unregisters an account as a Clave account
* @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
*/
Expand All @@ -64,11 +64,11 @@ contract ClaveRegistry is Ownable2Step, IClaveRegistry {
revert Errors.NOT_FROM_FACTORY();
}

isClave[account] = false;
isAGW[account] = false;
}

/**
* @notice Unregisters multiple accounts as Clave accounts
* @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
*/
Expand All @@ -78,7 +78,7 @@ contract ClaveRegistry is Ownable2Step, IClaveRegistry {
}

for (uint256 i = 0; i < accounts.length; i++) {
isClave[accounts[i]] = false;
isAGW[accounts[i]] = false;
}
}

Expand Down
52 changes: 27 additions & 25 deletions contracts/AccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {SystemContractsCaller} from '@matterlabs/zksync-contracts/l2/system-cont
import {Ownable, Ownable2Step} from '@openzeppelin/contracts/access/Ownable2Step.sol';

import {Errors} from './libraries/Errors.sol';
import {IClaveRegistry} from './interfaces/IClaveRegistry.sol';
import {IAGWRegistry} from './interfaces/IAGWRegistry.sol';

/**
* @title Factory contract to create Clave accounts in zkSync Era
* @title Factory contract to create AGW accounts
* @dev Forked from Clave for Abstract
* @author https://abs.xyz
* @author https://getclave.io
*/
contract AccountFactory is Ownable2Step {
Expand All @@ -23,22 +25,22 @@ contract AccountFactory is Ownable2Step {

// Account creation bytecode hash
bytes32 public proxyBytecodeHash;
// Account authorized to deploy Clave accounts
// Account authorized to deploy AGW accounts
address public deployer;
// Mapping to store the deployer of each account
mapping (address => address) public accountToDeployer;

/**
* @notice Event emmited when a new Clave account is created
* @param accountAddress Address of the newly created Clave account
* @notice Event emmited when a new AGW account is created
* @param accountAddress Address of the newly created AGW account
*/
event ClaveAccountCreated(address indexed accountAddress);
event AGWAccountCreated(address indexed accountAddress);

/**
* @notice Event emmited when a new Clave account is deployed
* @param accountAddress Address of the newly deployed Clave account
* @notice Event emmited when a new AGW account is deployed
* @param accountAddress Address of the newly deployed AGW account
*/
event ClaveAccountDeployed(address indexed accountAddress);
event AGWAccountDeployed(address indexed accountAddress);

/**
* @notice Event emmited when the deployer account is changed
Expand All @@ -62,8 +64,8 @@ contract AccountFactory is Ownable2Step {
* @notice Constructor function of the factory contract
* @param _implementation address - Address of the implementation contract
* @param _registry address - Address of the registry contract
* @param _proxyBytecodeHash address - Hash of the bytecode of the clave proxy contract
* @param _deployer address - Address of the account authorized to deploy Clave accounts
* @param _proxyBytecodeHash address - Hash of the bytecode of the AGW proxy contract
* @param _deployer address - Address of the account authorized to deploy AGW accounts
*/
constructor(
address _implementation,
Expand All @@ -81,11 +83,11 @@ contract AccountFactory is Ownable2Step {
}

/**
* @notice Deploys a new Clave account
* @notice Deploys a new AGW account
* @dev Account address depends only on salt
* @param salt bytes32 - Salt to be used for the account creation
* @param initializer bytes memory - Initializer data for the account
* @return accountAddress address - Address of the newly created Clave account
* @return accountAddress address - Address of the newly created AGW account
*/
function deployAccount(
bytes32 salt,
Expand Down Expand Up @@ -149,26 +151,26 @@ contract AccountFactory is Ownable2Step {
revert Errors.INITIALIZATION_FAILED();
}

IClaveRegistry(registry).register(accountAddress);
IAGWRegistry(registry).register(accountAddress);

emit ClaveAccountDeployed(accountAddress);
emit AGWAccountDeployed(accountAddress);
}

/**
* @notice To emit an event when a Clave account is created but not yet deployed
* @notice To emit an event when a AGW account is created but not yet deployed
* @dev This event is so that we can index accounts that are created but not yet deployed
* @param accountAddress address - Address of the Clave account that was created
* @param accountAddress address - Address of the AGW account that was created
*/
function claveAccountCreated(address accountAddress) external {
function agwAccountCreated(address accountAddress) external {
if (msg.sender != deployer) {
revert Errors.NOT_FROM_DEPLOYER();
}
emit ClaveAccountCreated(accountAddress);
emit AGWAccountCreated(accountAddress);
}

/**
* @notice Changes the account authorized to deploy Clave accounts
* @param newDeployer address - Address of the new account authorized to deploy Clave accounts
* @notice Changes the account authorized to deploy AGW accounts
* @param newDeployer address - Address of the new account authorized to deploy AGW accounts
*/
function changeDeployer(address newDeployer) external onlyOwner {
deployer = newDeployer;
Expand Down Expand Up @@ -198,9 +200,9 @@ contract AccountFactory is Ownable2Step {
}

/**
* @notice Returns the address of the Clave account that would be created with the given salt
* @notice Returns the address of the AGW account that would be created with the given salt
* @param salt bytes32 - Salt to be used for the account creation
* @return accountAddress address - Address of the Clave account that would be created with the given salt
* @return accountAddress address - Address of the AGW account that would be created with the given salt
*/
function getAddressForSalt(bytes32 salt) external view returns (address accountAddress) {
accountAddress = IContractDeployer(DEPLOYER_SYSTEM_CONTRACT).getNewAddressCreate2(
Expand All @@ -212,10 +214,10 @@ contract AccountFactory is Ownable2Step {
}

/**
* @notice Returns the address of the Clave account that would be created with the given salt and implementation
* @notice Returns the address of the AGW account that would be created with the given salt and implementation
* @param salt bytes32 - Salt to be used for the account creation
* @param _implementation address - Address of the implementation contract
* @return accountAddress address - Address of the Clave account that would be created with the given salt and implementation
* @return accountAddress address - Address of the AGW account that would be created with the given salt and implementation
*/
function getAddressForSaltAndImplementation(
bytes32 salt,
Expand Down
2 changes: 1 addition & 1 deletion contracts/ClaveProxy.sol → contracts/AccountProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import {EfficientCall} from '@matterlabs/zksync-contracts/l2/system-contracts/libraries/EfficientCall.sol';

contract ClaveProxy {
contract AccountProxy {
event Upgraded(address indexed implementation);

//keccak-256 of "eip1967.proxy.implementation" subtracted by 1
Expand Down
28 changes: 15 additions & 13 deletions contracts/handlers/ERC1271Handler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import {EIP712Upgradeable} from '@openzeppelin/contracts-upgradeable/utils/crypt
/**
* @title ERC1271Handler
* @notice Contract which provides ERC1271 signature validation
* @dev Forked from Clave for Abstract
* @author https://getclave.io
* @author https://abs.xyz
*/
abstract contract ERC1271Handler is
IERC1271,
EIP712Upgradeable,
ValidationHandler
{
struct ClaveMessage {
struct AGWMessage {
bytes32 signedHash;
}

bytes32 constant _CLAVE_MESSAGE_TYPEHASH = keccak256('ClaveMessage(bytes32 signedHash)');
bytes32 constant _AGW_MESSAGE_TYPEHASH = keccak256('AGWMessage(bytes32 signedHash)');

bytes4 private constant _ERC1271_MAGIC = 0x1626ba7e;

Expand All @@ -43,31 +45,31 @@ abstract contract ERC1271Handler is
signatureAndValidator
);

bytes32 eip712Hash = _hashTypedDataV4(_claveMessageHash(ClaveMessage(signedHash)));
bytes32 eip712Hash = _hashTypedDataV4(_agwMessageHash(AGWMessage(signedHash)));

bool valid = _handleValidation(validator, eip712Hash, signature);

magicValue = valid ? _ERC1271_MAGIC : bytes4(0);
}

/**
* @notice Returns the EIP-712 hash of the Clave message
* @param claveMessage ClaveMessage calldata - The message containing signedHash
* @notice Returns the EIP-712 hash of the AGW message
* @param agwMessage AGWMessage calldata - The message containing signedHash
* @return bytes32 - EIP712 hash of the message
*/
function getEip712Hash(ClaveMessage calldata claveMessage) external view returns (bytes32) {
return _hashTypedDataV4(_claveMessageHash(claveMessage));
function getEip712Hash(AGWMessage calldata agwMessage) external view returns (bytes32) {
return _hashTypedDataV4(_agwMessageHash(agwMessage));
}

/**
* @notice Returns the typehash for the clave message struct
* @return bytes32 - Clave message typehash
* @notice Returns the typehash for the AGW message struct
* @return bytes32 - AGW message typehash
*/
function claveMessageTypeHash() external pure returns (bytes32) {
return _CLAVE_MESSAGE_TYPEHASH;
function agwMessageTypeHash() external pure returns (bytes32) {
return _AGW_MESSAGE_TYPEHASH;
}

function _claveMessageHash(ClaveMessage memory claveMessage) internal pure returns (bytes32) {
return keccak256(abi.encode(_CLAVE_MESSAGE_TYPEHASH, claveMessage.signedHash));
function _agwMessageHash(AGWMessage memory agwMessage) internal pure returns (bytes32) {
return keccak256(abi.encode(_AGW_MESSAGE_TYPEHASH, agwMessage.signedHash));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import {IUpgradeManager} from './IUpgradeManager.sol';
import {IValidatorManager} from './IValidatorManager.sol';

/**
* @title IClave
* @notice Interface for the Clave contract
* @dev Implementations of this interface are contract that can be used as a Clave
* @title IAGWAccount
* @notice Interface for the AGW contract
* @dev Implementations of this interface are contracts that can be used as an AGW account
* @dev Forked from Clave for Abstract
* @author https://getclave.io
* @author https://abs.xyz
*/
interface IClaveAccount is
interface IAGWAccount is
IERC1271,
IERC721Receiver,
IERC1155Receiver,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;

interface IClaveRegistry {
interface IAGWRegistry {
function register(address account) external;

function isClave(address account) external view returns (bool);
function isAGW(address account) external view returns (bool);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;

library ClaveStorage {
//keccak256('clave.contracts.ClaveStorage') - 1
bytes32 private constant CLAVE_STORAGE_SLOT =
0x3248da1aeae8bd923cbf26901dc4bfc6bb48bb0fbc5b6102f1151fe7012884f4;
library AGWStorage {
//keccak256('agw.contracts.AGWStorage') - 1
bytes32 private constant AGW_STORAGE_SLOT =
0x67641650ff26a63f6b1fb8b1cb96de5bac5c28fcfcca35c9518ea6966d32d42d;

struct Layout {
// ┌───────────────────┐
Expand Down Expand Up @@ -44,7 +44,7 @@ library ClaveStorage {
}

function layout() internal pure returns (Layout storage l) {
bytes32 slot = CLAVE_STORAGE_SLOT;
bytes32 slot = AGW_STORAGE_SLOT;
assembly {
l.slot := slot
}
Expand Down
Loading

0 comments on commit f33c24c

Please sign in to comment.