Skip to content

Commit

Permalink
feat: add 7702 account to deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed committed Dec 13, 2024
1 parent 16e8d3e commit d02704a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ENTRYPOINT=

# AccountFactory's initial owner
FACTORY_OWNER=
ACCOUNT_FACTORY_OWNER=

# Expected addresses

Expand All @@ -17,7 +17,7 @@ WEBAUTHN_VALIDATION_MODULE=
MODULAR_ACCOUNT_IMPL=
SEMI_MODULAR_ACCOUNT_7702_IMPL=
SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL=
SEMI_MODULAR_ACCOUNT_STORAGEONLY_IMPL=
SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL=

ACCOUNT_FACTORY=

Expand All @@ -40,7 +40,7 @@ ACCOUNT_FACTORY_SALT=

# Factory staking setup

# 1 ether required by bundlers
REQUIRED_STAKE_AMOUNT=1
# 0.1 ether required by bundlers
REQUIRED_STAKE_AMOUNT_WEI=100000000000000000
# 1 day required by bundlers
UNSTAKE_DELAY_SEC=86400
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Foundry build and cache directories
out/
out-optimized/
out-optimized-standalone/
out-optimized-sma-storage/
cache/
cache-optimized/
cache-optimized-standalone/
cache-optimized-sma-storage/
node_modules/

# Coverage
Expand Down
20 changes: 16 additions & 4 deletions script/DeployAccounts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ contract DeployAccountsScript is ScriptBase, Artifacts {
address public expectedSemiModularAccountBytecodeImpl;
uint256 public semiModularAccountBytecodeImplSalt;

address public expectedSemiModularAccountStorageOnlyImpl;
uint256 public semiModularAccountStorageOnlyImplSalt;
address public expectedSemiModularAccount7702Impl;
uint256 public semiModularAccount7702ImplSalt;

function setUp() public {
// Load the required addresses for the deployment from env vars.
Expand All @@ -39,8 +39,8 @@ contract DeployAccountsScript is ScriptBase, Artifacts {
expectedSemiModularAccountBytecodeImpl = _getSemiModularAccountBytecodeImpl();
semiModularAccountBytecodeImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL");

expectedSemiModularAccountStorageOnlyImpl = _getSemiModularAccountStorageOnlyImpl();
semiModularAccountStorageOnlyImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL");
expectedSemiModularAccount7702Impl = _getSemiModularAccount7702Impl();
semiModularAccount7702ImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_7702_IMPL");
}

function run() public onlyProfile("optimized-build") {
Expand Down Expand Up @@ -69,6 +69,14 @@ contract DeployAccountsScript is ScriptBase, Artifacts {
_wrappedDeploySemiModularAccountBytecode
);

_safeDeploy(
"Semi Modular Account 7702 Impl",
expectedSemiModularAccount7702Impl,
semiModularAccount7702ImplSalt,
_getSemiModularAccount7702Initcode(entryPoint, ExecutionInstallDelegate(executionInstallDelegate)),
_wrappedDeploySemiModularAccount7702
);

vm.stopBroadcast();

console.log("******** Account Implementations Deployed *********");
Expand All @@ -86,6 +94,10 @@ contract DeployAccountsScript is ScriptBase, Artifacts {
_deploySemiModularAccountBytecode(salt, entryPoint, ExecutionInstallDelegate(executionInstallDelegate));
}

function _wrappedDeploySemiModularAccount7702(bytes32 salt) internal returns (address) {
return _deploySemiModularAccount7702(salt, entryPoint, ExecutionInstallDelegate(executionInstallDelegate));
}

function _ensureNonzeroArgs() internal view {
bool shouldRevert;

Expand Down
4 changes: 4 additions & 0 deletions script/ScriptBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ abstract contract ScriptBase is Script {
return vm.envOr("SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL", address(0));
}

function _getSemiModularAccount7702Impl() internal view returns (address) {
return vm.envOr("SEMI_MODULAR_ACCOUNT_7702_IMPL", address(0));
}

function _getExecutionInstallDelegate() internal view returns (address) {
return vm.envOr("EXECUTION_INSTALL_DELEGATE", address(0));
}
Expand Down
17 changes: 11 additions & 6 deletions test/script/DeployAccounts.s.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {DeployAccountsScript} from "../../script/DeployAccounts.s.sol";
import {ModularAccount} from "../../src/account/ModularAccount.sol";
import {SemiModularAccountBytecode} from "../../src/account/SemiModularAccountBytecode.sol";
import {SemiModularAccountStorageOnly} from "../../src/account/SemiModularAccountStorageOnly.sol";
import {SemiModularAccount7702} from "../../src/account/SemiModularAccount7702.sol";

contract DeployAccountsTest is Test {
DeployAccountsScript internal _deployAccountsScript;
Expand All @@ -17,7 +17,7 @@ contract DeployAccountsTest is Test {
address public executionInstallDelegate;
address public modularAccountImpl;
address public semiModularAccountBytecodeImpl;
address public semiModularAccountStorageOnlyImpl;
address public semiModularAccount7702Impl;

function setUp() public {
_deployAccountsScript = new DeployAccountsScript();
Expand Down Expand Up @@ -46,11 +46,11 @@ contract DeployAccountsTest is Test {
CREATE2_FACTORY
);

semiModularAccountStorageOnlyImpl = Create2.computeAddress(
semiModularAccount7702Impl = Create2.computeAddress(
zeroSalt,
keccak256(
bytes.concat(
type(SemiModularAccountStorageOnly).creationCode,
type(SemiModularAccount7702).creationCode,
abi.encode(entryPoint, executionInstallDelegate)
)
),
Expand All @@ -61,13 +61,13 @@ contract DeployAccountsTest is Test {
vm.setEnv("EXECUTION_INSTALL_DELEGATE", vm.toString(executionInstallDelegate));
vm.setEnv("MODULAR_ACCOUNT_IMPL", vm.toString(modularAccountImpl));
vm.setEnv("SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL", vm.toString(semiModularAccountBytecodeImpl));
vm.setEnv("SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL", vm.toString(semiModularAccountStorageOnlyImpl));
vm.setEnv("SEMI_MODULAR_ACCOUNT_7702_IMPL", vm.toString(semiModularAccount7702Impl));

string memory zeroSaltString = vm.toString(zeroSalt);

vm.setEnv("MODULAR_ACCOUNT_IMPL_SALT", zeroSaltString);
vm.setEnv("SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL_SALT", zeroSaltString);
vm.setEnv("SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL_SALT", zeroSaltString);
vm.setEnv("SEMI_MODULAR_ACCOUNT_7702_IMPL_SALT", zeroSaltString);

// Spoof as though the profile is set to "optimized-build".
vm.setEnv("FOUNDRY_PROFILE", "optimized-build");
Expand All @@ -84,5 +84,10 @@ contract DeployAccountsTest is Test {
SemiModularAccountBytecode(payable(semiModularAccountBytecodeImpl)).accountId(),
"alchemy.sma-bytecode.1.0.0"
);

assertEq(
SemiModularAccount7702(payable(semiModularAccount7702Impl)).accountId(),
"alchemy.sma-7702.1.0.0"
);
}
}

0 comments on commit d02704a

Please sign in to comment.