-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-reamde
- Loading branch information
Showing
37 changed files
with
486 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ node_modules/ | |
|
||
# era-test-node | ||
era_test_node.log | ||
anvil-zksync.log | ||
|
||
package-lock.json | ||
yarn.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
"build": "pnpm hardhat compile", | ||
"clean": "pnpm hardhat clean", | ||
"test": "pnpm hardhat test", | ||
"deploy": "pnpm hardhat deploy" | ||
"deploy": "pnpm hardhat deploy", | ||
"upgrade": "pnpm hardhat upgrade" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "19.5.0", | ||
|
@@ -64,7 +65,7 @@ | |
"eslint-plugin-simple-import-sort": "12.1.1", | ||
"ethers": "6.13.2", | ||
"globals": "15.9.0", | ||
"hardhat": "^2.22.12", | ||
"hardhat": "^2.22.17", | ||
"husky": "9.1.6", | ||
"ini": "5.0.0", | ||
"lint-staged": "15.2.10", | ||
|
@@ -74,14 +75,14 @@ | |
"nx": "19.8.6", | ||
"prettier": "3.3.3", | ||
"prettier-plugin-solidity": "^1.4.1", | ||
"solady": "^0.0.273", | ||
"ts-node": "10.9.2", | ||
"typechain": "8.3.2", | ||
"typescript": "5.6.2", | ||
"typescript-eslint": "8.7.0", | ||
"viem": "^2.21.14", | ||
"zksync-ethers": "6.15.0", | ||
"zksync-sso": "0.0.0-beta.2", | ||
"solady": "^0.0.273" | ||
"zksync-sso": "0.0.0-beta.2" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { task } from "hardhat/config"; | ||
import { Wallet } from "zksync-ethers"; | ||
import { ethers } from "ethers"; | ||
|
||
// TODO: add support for constructor args | ||
task("upgrade", "Upgrades ZKsync SSO contracts") | ||
.addParam("proxy", "address of the proxy to upgrade") | ||
.addParam("beaconAddress", "address of the beacon proxy for the upgrade") | ||
.addPositionalParam("artifactName", "name of the artifact to upgrade to") | ||
.setAction(async (cmd, hre) => { | ||
const { LOCAL_RICH_WALLETS, getProvider, deployFactory, create2, ethersStaticSalt } = require("../test/utils"); | ||
|
||
let privateKey: string; | ||
if (hre.network.name == "inMemoryNode" || hre.network.name == "dockerizedNode") { | ||
console.log("Using local rich wallet"); | ||
privateKey = LOCAL_RICH_WALLETS[0].privateKey; | ||
cmd.fund = "1"; | ||
} else { | ||
if (!process.env.WALLET_PRIVATE_KEY) throw "Wallet private key wasn't found in .env file!"; | ||
privateKey = process.env.WALLET_PRIVATE_KEY; | ||
} | ||
|
||
const wallet = new Wallet(privateKey, getProvider()); | ||
let newImpl; | ||
|
||
console.log("Deploying new implementation of", cmd.artifactName, "contract..."); | ||
if (cmd.artifactName == "AAFactory") { | ||
if (!cmd.beaconAddress) throw "Deploying the AAFactory requires a Beacon Address '--beacon-address <value>'"; | ||
newImpl = await deployFactory(wallet, cmd.beaconAddress); | ||
} else { | ||
newImpl = await create2(cmd.artifactName, wallet, ethersStaticSalt, []); | ||
} | ||
console.log("New implementation deployed at:", await newImpl.getAddress()); | ||
|
||
console.log("Upgrading proxy at", cmd.proxy, "to new implementation..."); | ||
const abi = ["function upgradeTo(address newImplementation)"]; | ||
const proxy = new ethers.Contract(cmd.proxy, abi, wallet); | ||
const tx = await proxy.upgradeTo(await newImpl.getAddress()); | ||
await tx.wait(); | ||
console.log("Proxy upgraded successfully"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import { UpgradeableBeacon } from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; | ||
import { DEPLOYER_SYSTEM_CONTRACT, IContractDeployer } from "@matterlabs/zksync-contracts/l2/system-contracts/Constants.sol"; | ||
import { SystemContractsCaller } from "@matterlabs/zksync-contracts/l2/system-contracts/libraries/SystemContractsCaller.sol"; | ||
|
||
|
@@ -11,38 +10,42 @@ import { ISsoAccount } from "./interfaces/ISsoAccount.sol"; | |
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @dev This contract is used to deploy SSO accounts as beacon proxies. | ||
contract AAFactory is UpgradeableBeacon { | ||
contract AAFactory { | ||
/// @notice Emitted when a new account is successfully created. | ||
/// @param accountAddress The address of the newly created account. | ||
/// @param uniqueAccountId A unique identifier for the account. | ||
event AccountCreated(address indexed accountAddress, string uniqueAccountId); | ||
|
||
/// @dev The bytecode hash of the beacon proxy, used for deploying proxy accounts. | ||
bytes32 private immutable beaconProxyBytecodeHash; | ||
bytes32 public immutable beaconProxyBytecodeHash; | ||
address public immutable beacon; | ||
|
||
/// @notice A mapping from unique account IDs to their corresponding deployed account addresses. | ||
mapping(string => address) public accountMappings; | ||
|
||
/// @notice Constructor that initializes the factory with a beacon proxy bytecode hash and implementation contract address. | ||
/// @param _beaconProxyBytecodeHash The bytecode hash of the beacon proxy. | ||
/// @param _implementation The address of the implementation contract used by the beacon. | ||
constructor(bytes32 _beaconProxyBytecodeHash, address _implementation) UpgradeableBeacon(_implementation) { | ||
/// @param _beacon The address of the UpgradeableBeacon contract used for the SSO accounts' beacon proxies. | ||
constructor(bytes32 _beaconProxyBytecodeHash, address _beacon) { | ||
beaconProxyBytecodeHash = _beaconProxyBytecodeHash; | ||
beacon = _beacon; | ||
} | ||
|
||
function getEncodedBeacon() external view returns (bytes memory) { | ||
return abi.encode(beacon); | ||
} | ||
|
||
/// @notice Deploys a new SSO account as a beacon proxy with the specified parameters. | ||
/// @dev Uses `create2` to deploy a proxy account, allowing for deterministic addresses based on the provided salt. | ||
/// @param _salt The salt used for the `create2` deployment to make the address deterministic. | ||
/// @param _uniqueAccountId A unique identifier for the new account. | ||
/// @param _initialValidators An array of initial validators for the new account. | ||
/// @param _initialModules An array of initial modules to be added to the new account. | ||
/// @param _initialK1Owners An array of initial owners of the K1 key for the new account. | ||
/// @return accountAddress The address of the newly deployed SSO account. | ||
function deployProxySsoAccount( | ||
bytes32 _salt, | ||
string calldata _uniqueAccountId, | ||
bytes[] calldata _initialValidators, | ||
bytes[] calldata _initialModules, | ||
address[] calldata _initialK1Owners | ||
) external returns (address accountAddress) { | ||
require(accountMappings[_uniqueAccountId] == address(0), "Account already exists"); | ||
|
@@ -53,19 +56,14 @@ contract AAFactory is UpgradeableBeacon { | |
uint128(0), | ||
abi.encodeCall( | ||
DEPLOYER_SYSTEM_CONTRACT.create2Account, | ||
( | ||
_salt, | ||
beaconProxyBytecodeHash, | ||
abi.encode(address(this)), | ||
IContractDeployer.AccountAbstractionVersion.Version1 | ||
) | ||
(_salt, beaconProxyBytecodeHash, abi.encode(beacon), IContractDeployer.AccountAbstractionVersion.Version1) | ||
) | ||
); | ||
require(success, "Deployment failed"); | ||
(accountAddress) = abi.decode(returnData, (address)); | ||
|
||
// Initialize the newly deployed account with validators, modules, and K1 owners. | ||
ISsoAccount(accountAddress).initialize(_initialValidators, _initialModules, _initialK1Owners); | ||
// Initialize the newly deployed account with validators, hooks and K1 owners. | ||
ISsoAccount(accountAddress).initialize(_initialValidators, _initialK1Owners); | ||
|
||
accountMappings[_uniqueAccountId] = accountAddress; | ||
|
||
|
Oops, something went wrong.