From 5b8723c0f4d858b32114ee81197b84ca6542dae1 Mon Sep 17 00:00:00 2001 From: VGabriel45 Date: Sun, 13 Oct 2024 14:59:42 +0300 Subject: [PATCH] feat: helper config for deployment and cleanup --- scripts/foundry/Deploy.s.sol | 32 +++++++++++++++---- scripts/foundry/HelperConfig.s.sol | 31 ++++++++++++++++++ test/foundry/utils/TestHelper.t.sol | 6 ++-- .../smart-account/Nexus.Factory.specs.ts | 7 ++-- 4 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 scripts/foundry/HelperConfig.s.sol diff --git a/scripts/foundry/Deploy.s.sol b/scripts/foundry/Deploy.s.sol index c5316bba..9388d437 100644 --- a/scripts/foundry/Deploy.s.sol +++ b/scripts/foundry/Deploy.s.sol @@ -5,15 +5,33 @@ pragma solidity >=0.8.0 <0.9.0; import { Nexus } from "../../contracts/Nexus.sol"; import { BaseScript } from "./Base.s.sol"; +import { K1ValidatorFactory } from "../../contracts/factory/K1ValidatorFactory.sol"; +import { K1Validator } from "../../contracts/modules/validators/K1Validator.sol"; +import { BootstrapLib } from "../../contracts/lib/BootstrapLib.sol"; +import { NexusBootstrap } from "../../contracts/utils/NexusBootstrap.sol"; +import { MockRegistry } from "../../contracts/mocks/MockRegistry.sol"; +import { HelperConfig } from "./HelperConfig.s.sol"; -/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting contract Deploy is BaseScript { - address private constant _ENTRYPOINT = 0x0000000071727De22E5E9d8BAf0edAc6f37da032; - function run() public broadcast returns (Nexus smartAccount) { - smartAccount = new Nexus(_ENTRYPOINT); - } + K1ValidatorFactory private k1ValidatorFactory; + K1Validator private k1Validator; + NexusBootstrap private bootstrapper; + MockRegistry private registry; + HelperConfig private helperConfig; - function test() public { - // This is a test function to exclude this script from the coverage report. + function run() public broadcast returns (Nexus smartAccount) { + helperConfig = new HelperConfig(); + require(address(helperConfig.ENTRYPOINT()) != address(0), "ENTRYPOINT is not set"); + smartAccount = new Nexus(address(helperConfig.ENTRYPOINT())); + k1Validator = new K1Validator(); + bootstrapper = new NexusBootstrap(); + registry = new MockRegistry(); + k1ValidatorFactory = new K1ValidatorFactory( + address(smartAccount), + msg.sender, + address(k1Validator), + bootstrapper, + registry + ); } } diff --git a/scripts/foundry/HelperConfig.s.sol b/scripts/foundry/HelperConfig.s.sol new file mode 100644 index 00000000..7ed3d999 --- /dev/null +++ b/scripts/foundry/HelperConfig.s.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity >=0.8.0 <0.9.0; +pragma solidity >=0.8.0 <0.9.0; + +import { EntryPoint } from "account-abstraction/core/EntryPoint.sol"; +import { IEntryPoint } from "account-abstraction/interfaces/IEntryPoint.sol"; + +import {Script} from "forge-std/Script.sol"; + +contract HelperConfig is Script { + IEntryPoint public ENTRYPOINT; + address private constant MAINNET_ENTRYPOINT_ADDRESS = 0x0000000071727De22E5E9d8BAf0edAc6f37da032; + + constructor() { + if (block.chainid == 31337) { + setupAnvilConfig(); + } else { + ENTRYPOINT = IEntryPoint(MAINNET_ENTRYPOINT_ADDRESS); + } + } + + function setupAnvilConfig() public { + if(address(ENTRYPOINT) != address(0)){ + return; + } + ENTRYPOINT = new EntryPoint(); + vm.etch(address(MAINNET_ENTRYPOINT_ADDRESS), address(ENTRYPOINT).code); + ENTRYPOINT = IEntryPoint(MAINNET_ENTRYPOINT_ADDRESS); + } + +} \ No newline at end of file diff --git a/test/foundry/utils/TestHelper.t.sol b/test/foundry/utils/TestHelper.t.sol index 694a7e95..5419eb08 100644 --- a/test/foundry/utils/TestHelper.t.sol +++ b/test/foundry/utils/TestHelper.t.sol @@ -25,6 +25,7 @@ import { NexusAccountFactory } from "../../../contracts/factory/NexusAccountFact import { BootstrapLib } from "../../../contracts/lib/BootstrapLib.sol"; import { MODE_VALIDATION } from "../../../contracts/types/Constants.sol"; import { MockRegistry } from "../../../contracts/mocks/MockRegistry.sol"; +import { HelperConfig } from "../../../scripts/foundry/HelperConfig.s.sol"; contract TestHelper is CheatCodes, EventsAndErrors { // ----------------------------------------- @@ -103,9 +104,8 @@ contract TestHelper is CheatCodes, EventsAndErrors { } function deployTestContracts() internal { - ENTRYPOINT = new EntryPoint(); - vm.etch(address(0x0000000071727De22E5E9d8BAf0edAc6f37da032), address(ENTRYPOINT).code); - ENTRYPOINT = IEntryPoint(0x0000000071727De22E5E9d8BAf0edAc6f37da032); + HelperConfig helperConfig = new HelperConfig(); + ENTRYPOINT = helperConfig.ENTRYPOINT(); ACCOUNT_IMPLEMENTATION = new Nexus(address(ENTRYPOINT)); FACTORY = new NexusAccountFactory(address(ACCOUNT_IMPLEMENTATION), address(FACTORY_OWNER.addr)); META_FACTORY = new BiconomyMetaFactory(address(FACTORY_OWNER.addr)); diff --git a/test/hardhat/smart-account/Nexus.Factory.specs.ts b/test/hardhat/smart-account/Nexus.Factory.specs.ts index a7f79fd5..6774fab2 100644 --- a/test/hardhat/smart-account/Nexus.Factory.specs.ts +++ b/test/hardhat/smart-account/Nexus.Factory.specs.ts @@ -4,10 +4,8 @@ import { AddressLike, Signer, ZeroAddress, - ZeroHash, keccak256, solidityPacked, - zeroPadBytes, } from "ethers"; import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; import { @@ -28,7 +26,7 @@ import { deployContractsAndSAFixture, deployContractsFixture, } from "../utils/deployment"; -import { encodeData, to18 } from "../utils/encoding"; +import { to18 } from "../utils/encoding"; import { MODE_VALIDATION, buildPackedUserOp, @@ -36,7 +34,6 @@ import { numberTo3Bytes, } from "../utils/operationHelpers"; import { BootstrapConfigStruct } from "../../../typechain-types/contracts/lib/BootstrapLib"; -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; describe("Nexus Factory Tests", function () { let factory: K1ValidatorFactory; @@ -470,7 +467,7 @@ describe("Nexus Factory Tests", function () { let smartAccount: Nexus; let entryPoint: EntryPoint; let factory: RegistryFactory; - let bootstrap: Bootstrap; + let bootstrap: NexusBootstrap; let validatorModule: MockValidator; let executorModule: MockExecutor; let BootstrapLib: BootstrapLib;