Skip to content

Commit

Permalink
chore: update deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
howydev committed Feb 1, 2024
1 parent 9c9c6c3 commit 8d258c2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
13 changes: 10 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ UNSTAKE_DELAY_SEC=86400
ENTRYPOINT=
# MA_IMPL=
# OWNER_FACTORY=
# OWNER_TOKEN_RECEIVER_FACTORY=

# OWNER_PLUGIN=
# TOKEN_RECEIVER_PLUGIN=
# SESSION_KEY_PLUGIN=

# MA_IMPL_SALT=0x4e59b44847b379578588920ca78fbf26c0b4956c0e9a227681db5000003dbbde
# FACTORY_SALT=0x4e59b44847b379578588920ca78fbf26c0b4956cd08fc11e11982000000a3661
# MULTI_OWNER_PLUGIN_SALT=0x4e59b44847b379578588920ca78fbf26c0b4956c1860b9a3abb9300000558ee2
# SESSION_KEY_PLUGIN_SALT=0x4e59b44847b379578588920ca78fbf26c0b4956c06c5e21a560f400000414c18

# EXPECTED_MA_IMPL=
# EXPECTED_FACTORY=
# EXPECTED_OWNER_PLUGIN=
# EXPECTED_SESSION_KEY_PLUGIN=

RPC_URL=
50 changes: 37 additions & 13 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ contract Deploy is Script {
bytes32 public multiOwnerPluginManifestHash;
address public sessionKeyPlugin = vm.envOr("SESSION_KEY_PLUGIN", address(0));

// Load optional salts for create2
bytes32 public maImplSalt = vm.envOr("MA_IMPL_SALT", bytes32(0));
bytes32 public factorySalt = vm.envOr("FACTORY_SALT", bytes32(0));
bytes32 public multiOwnerPluginSalt = vm.envOr("MULTI_OWNER_PLUGIN_SALT", bytes32(0));
bytes32 public sessionKeyPluginSalt = vm.envOr("SESSION_KEY_PLUGIN_SALT", bytes32(0));

// Load optional expected addresses during creation, if any
address public expectedMaImpl = vm.envOr("EXPECTED_MA_IMPL", address(0));
address public expectedFactory = vm.envOr("EXPECTED_FACTORY", address(0));
address public expectedMultiOwnerPlugin = vm.envOr("EXPECTED_OWNER_PLUGIN", address(0));
address public expectedSessionKeyPlugin = vm.envOr("EXPECTED_SESSION_KEY_PLUGIN", address(0));

function run() public {
console.log("******** Deploying *********");
console.log("Chain: ", block.chainid);
Expand All @@ -58,41 +70,53 @@ contract Deploy is Script {

// Deploy ma impl
if (maImpl == address(0)) {
UpgradeableModularAccount ma = new UpgradeableModularAccount(entryPoint);
maImpl = address(ma);
maImpl = address(new UpgradeableModularAccount{salt: maImplSalt}(entryPoint));

if (expectedMaImpl != address(0)) {
require(maImpl == expectedMaImpl, "MA impl address mismatch");
}
console.log("New MA impl: ", maImpl);
} else {
console.log("Exist MA impl: ", maImpl);
}

// Deploy multi owner plugin, and set plugin hash
if (multiOwnerPlugin == address(0)) {
MultiOwnerPlugin mop = new MultiOwnerPlugin();
multiOwnerPlugin = address(mop);
multiOwnerPlugin = address(new MultiOwnerPlugin{salt: multiOwnerPluginSalt}());

if (expectedMultiOwnerPlugin != address(0)) {
require(multiOwnerPlugin == expectedMultiOwnerPlugin, "Multi owner plugin address mismatch");
}
console.log("New MultiOwnerPlugin: ", multiOwnerPlugin);
} else {
console.log("Exist MultiOwnerPlugin: ", multiOwnerPlugin);
}
multiOwnerPluginManifestHash = keccak256(abi.encode(BasePlugin(multiOwnerPlugin).pluginManifest()));

// Deploy MultiOwnerModularAccountFactory, and add stake with EP

// Deploy owner factory
if (ownerFactoryAddr == address(0)) {
ownerFactory = new MultiOwnerModularAccountFactory(
owner, multiOwnerPlugin, maImpl, multiOwnerPluginManifestHash, entryPoint
ownerFactoryAddr = address(
new MultiOwnerModularAccountFactory{salt: factorySalt}(
owner, multiOwnerPlugin, maImpl, multiOwnerPluginManifestHash, entryPoint
)
);

ownerFactoryAddr = address(ownerFactory);
if (expectedFactory != address(0)) {
require(ownerFactoryAddr == expectedFactory, "Factory address mismatch");
}
console.log("New MultiOwnerModularAccountFactory: ", ownerFactoryAddr);
} else {
console.log("Exist MultiOwnerModularAccountFactory: ", ownerFactoryAddr);
}
_addStakeForFactory(ownerFactoryAddr, entryPoint);

// Deploy SessionKeyPlugin impl
// Deploy SessionKeyPlugin
if (sessionKeyPlugin == address(0)) {
SessionKeyPlugin skp = new SessionKeyPlugin();
sessionKeyPlugin = address(skp);
sessionKeyPlugin = address(new SessionKeyPlugin{salt: sessionKeyPluginSalt}());

if (expectedSessionKeyPlugin != address(0)) {
require(sessionKeyPlugin == expectedSessionKeyPlugin, "SessionKeyPlugin address mismatch");
}
console.log("New SessionKeyPlugin: ", sessionKeyPlugin);
} else {
console.log("Exist SessionKeyPlugin: ", sessionKeyPlugin);
Expand All @@ -103,7 +127,7 @@ contract Deploy is Script {
}

function _addStakeForFactory(address factoryAddr, IEntryPoint anEntryPoint) internal {
uint32 unstakeDelaySec = uint32(vm.envOr("UNSTAKE_DELAY_SEC", uint32(60)));
uint32 unstakeDelaySec = uint32(vm.envOr("UNSTAKE_DELAY_SEC", uint32(86400)));
uint256 requiredStakeAmount = vm.envUint("REQUIRED_STAKE_AMOUNT") * 1 ether;
uint256 currentStakedAmount = I4337EntryPoint(address(anEntryPoint)).getDepositInfo(factoryAddr).stake;
uint256 stakeAmount = requiredStakeAmount - currentStakedAmount;
Expand Down

0 comments on commit 8d258c2

Please sign in to comment.