generated from defi-wonderland/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootstrapLib.sol
More file actions
62 lines (55 loc) · 2.66 KB
/
BootstrapLib.sol
File metadata and controls
62 lines (55 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {BootstrapConfig, BootstrapPreValidationHookConfig} from '../utils/Bootstrap.sol';
/// @title Bootstrap Configuration Library
/// @notice Provides utility functions to create and manage BootstrapConfig structures.
/// Special thanks to the Biconomy team for https://github.com/bcnmy/nexus/ and ERC7579 reference implementation on which this implementation is highly based on.
library BootstrapLib {
error LengthMismatch();
/// @notice Creates a single BootstrapConfig structure.
/// @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) internal pure returns (BootstrapConfig memory config) {
config.module = module;
config.data = data;
}
/// @notice Creates an array with a single BootstrapConfig structure.
/// @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) internal pure returns (BootstrapConfig[] memory config) {
config = new BootstrapConfig[](1);
config[0].module = module;
config[0].data = data;
}
/// @notice Creates an array with a single BootstrapPreValidationHookConfig structure.
/// @param hookType The type of the pre-validation hook.
/// @param module The address of the module.
/// @param data The initialization data for the module.
/// @return config An array containing a single BootstrapPreValidationHookConfig structure.
function createArrayPreValidationHookConfig(
uint256 hookType,
address module,
bytes memory data
) internal pure returns (BootstrapPreValidationHookConfig[] memory config) {
config = new BootstrapPreValidationHookConfig[](1);
config[0].hookType = hookType;
config[0].module = module;
config[0].data = data;
}
/// @notice Creates an array of BootstrapConfig structures.
/// @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
) internal pure returns (BootstrapConfig[] memory configs) {
if (modules.length != datas.length) revert LengthMismatch();
configs = new BootstrapConfig[](modules.length);
for (uint256 i = 0; i < modules.length; i++) {
configs[i] = createSingleConfig(modules[i], datas[i]);
}
}
}