Skip to content

Commit

Permalink
Merge pull request #201 from bcnmy/feat/helper_config_for_deployment
Browse files Browse the repository at this point in the history
feat: helper config for deployment and cleanup
  • Loading branch information
livingrockrises authored Oct 14, 2024
2 parents e8ba67f + 5b8723c commit dc5d4bf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 15 deletions.
32 changes: 25 additions & 7 deletions scripts/foundry/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
31 changes: 31 additions & 0 deletions scripts/foundry/HelperConfig.s.sol
Original file line number Diff line number Diff line change
@@ -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);
}

}
6 changes: 3 additions & 3 deletions test/foundry/utils/TestHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// -----------------------------------------
Expand Down Expand Up @@ -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));
Expand Down
7 changes: 2 additions & 5 deletions test/hardhat/smart-account/Nexus.Factory.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
AddressLike,
Signer,
ZeroAddress,
ZeroHash,
keccak256,
solidityPacked,
zeroPadBytes,
} from "ethers";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import {
Expand All @@ -28,15 +26,14 @@ import {
deployContractsAndSAFixture,
deployContractsFixture,
} from "../utils/deployment";
import { encodeData, to18 } from "../utils/encoding";
import { to18 } from "../utils/encoding";
import {
MODE_VALIDATION,
buildPackedUserOp,
getNonce,
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dc5d4bf

Please sign in to comment.