Skip to content

Commit

Permalink
Merge pull request #217 from bcnmy/feat/change-library-func-visibility
Browse files Browse the repository at this point in the history
feat: make bootstrap lib functions internal
  • Loading branch information
livingrockrises authored Nov 15, 2024
2 parents 72499c9 + aca6343 commit 28dbede
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 73 deletions.
6 changes: 3 additions & 3 deletions contracts/lib/BootstrapLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ library BootstrapLib {
/// @param module The address of the module.
/// @param data The initialization data for the module.
/// @return config A BootstrapConfig structure containing the module and its data.
function createSingleConfig(address module, bytes memory data) public pure returns (BootstrapConfig memory config) {
function createSingleConfig(address module, bytes memory data) internal pure returns (BootstrapConfig memory config) {
config.module = module;
config.data = data;
}
Expand All @@ -24,7 +24,7 @@ library BootstrapLib {
/// @param module The address of the module.
/// @param data The initialization data for the module.
/// @return config An array containing a single BootstrapConfig structure.
function createArrayConfig(address module, bytes memory data) public pure returns (BootstrapConfig[] memory config) {
function createArrayConfig(address module, bytes memory data) internal pure returns (BootstrapConfig[] memory config) {
config = new BootstrapConfig[](1);
config[0].module = module;
config[0].data = data;
Expand All @@ -34,7 +34,7 @@ library BootstrapLib {
/// @param modules An array of module addresses.
/// @param datas An array of initialization data for each module.
/// @return configs An array of BootstrapConfig structures.
function createMultipleConfigs(address[] memory modules, bytes[] memory datas) public pure returns (BootstrapConfig[] memory configs) {
function createMultipleConfigs(address[] memory modules, bytes[] memory datas) internal pure returns (BootstrapConfig[] memory configs) {
require(modules.length == datas.length, "BootstrapLib: length mismatch");
configs = new BootstrapConfig[](modules.length);

Expand Down
7 changes: 1 addition & 6 deletions scripts/hardhat/deploy-fresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ async function main() {
await mockRegistry.waitForDeployment();

const K1ValidatorFactory = await ethers.getContractFactory(
"K1ValidatorFactory",
{
libraries: {
BootstrapLib: await bootstrapLib.getAddress(),
},
},
"K1ValidatorFactory"
);

const k1ValidatorFactory = await K1ValidatorFactory.deploy(
Expand Down
5 changes: 1 addition & 4 deletions scripts/hardhat/deployToMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ export async function deployToMainnet() {
K1Validator.address,
NexusBootstrap.address,
Registry.address,
],
libraries: {
BootstrapLib: BootstrapLib.address,
},
]
});
const BiconomyMetaFactory = await deployments.deploy("BiconomyMetaFactory", {
...deployOptions,
Expand Down
91 changes: 46 additions & 45 deletions test/hardhat/smart-account/Nexus.Factory.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,23 @@ describe("Nexus Factory Tests", function () {

ownerAddress = await owner.getAddress();

const validator = await BootstrapLib.createSingleConfig(
await validatorModule.getAddress(),
solidityPacked(["address"], [ownerAddress]),
);
const hook = await BootstrapLib.createSingleConfig(
await hookModule.getAddress(),
"0x",
);
const validator = {
module: await validatorModule.getAddress(),
data: solidityPacked(["address"], [ownerAddress]),
}

const hook = {
module: await hookModule.getAddress(),
data: "0x",
}

parsedValidator = {
module: validator[0],
data: validator[1],
module: validator.module,
data: validator.data,
};
parsedHook = {
module: hook[0],
data: hook[1],
module: hook.module,
data: hook.data,
};
});

Expand Down Expand Up @@ -331,33 +332,32 @@ describe("Nexus Factory Tests", function () {

ownerAddress = await owner.getAddress();

const validator = await BootstrapLib.createSingleConfig(
await validatorModule.getAddress(),
solidityPacked(["address"], [ownerAddress]),
);

const executor = await BootstrapLib.createSingleConfig(
await executorModule.getAddress(),
"0x",
);
const hook = await BootstrapLib.createSingleConfig(
await hookModule.getAddress(),
"0x",
);
const validator = {
module: await validatorModule.getAddress(),
data: solidityPacked(["address"], [ownerAddress]),
}
const executor = {
module: await executorModule.getAddress(),
data: "0x",
}
const hook = {
module: await hookModule.getAddress(),
data: "0x",
}

parsedValidator = {
module: validator[0],
data: validator[1],
module: validator.module,
data: validator.data,
};

parsedExecutor = {
module: executor[0],
data: executor[1],
module: executor.module,
data: executor.data,
};

parsedHook = {
module: hook[0],
data: hook[1],
module: hook.module,
data: hook.data,
};
});

Expand Down Expand Up @@ -515,20 +515,21 @@ describe("Nexus Factory Tests", function () {
registryFactory = registryFactory.connect(owner);

ownerAddress = await owner.getAddress();

const validator = await BootstrapLib.createSingleConfig(
await validatorModule.getAddress(),
solidityPacked(["address"], [ownerAddress]),
);

const executor = await BootstrapLib.createSingleConfig(
await executorModule.getAddress(),
"0x",
);
const hook = await BootstrapLib.createSingleConfig(
await hookModule.getAddress(),
"0x",
);

const validator = {
module: await validatorModule.getAddress(),
data: solidityPacked(["address"], [ownerAddress]),
}

const executor = {
module: await executorModule.getAddress(),
data: "0x",
}

const hook = {
module: await hookModule.getAddress(),
data: "0x",
}

parsedValidator = {
module: validator[0],
Expand Down
10 changes: 1 addition & 9 deletions test/hardhat/utils/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ export async function getDeployedAccountK1Factory(

// Get the contract factory for K1ValidatorFactory with linked library
const K1ValidatorFactory = await ethers.getContractFactory(
"K1ValidatorFactory",
{
libraries: {
BootstrapLib: await BootstrapLib.getAddress(),
},
},
"K1ValidatorFactory"
);

const deterministicAccountFactory = await deployments.deploy(
Expand All @@ -102,9 +97,6 @@ export async function getDeployedAccountK1Factory(
from: addresses[0],
deterministicDeployment: true,
args: [implementationAddress, owner, k1Validator, bootstrapper, registry],
libraries: {
BootstrapLib: await BootstrapLib.getAddress(),
},
},
);

Expand Down
7 changes: 1 addition & 6 deletions test/hardhat/utils/operationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,7 @@ export async function getInitCode(
BootstrapLib.waitForDeployment();

const K1ValidatorFactory = await ethers.getContractFactory(
"K1ValidatorFactory",
{
libraries: {
BootstrapLib: await BootstrapLib.getAddress(),
},
},
"K1ValidatorFactory"
);

// Encode the createAccount function call with the provided parameters
Expand Down

0 comments on commit 28dbede

Please sign in to comment.