Verified contractExactMIT
LucidityModule
Address0x78e9030229af5cef853cc035e1d2facfeb747a29
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.20
- Same code
Only this contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- Yes, 400 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 19,587,555
- Creation transaction
- 0x74239ca01c…bc29bf949e
10 files
- contracts/modules/LucidityModule.solmain7.75 KB
- @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol4.03 KB
- @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol8.91 KB
- @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol1.09 KB
- contracts/interfaces/IFlashloanHandler.sol246 B
- contracts/interfaces/IRegistry.sol626 B
- contracts/interfaces/ISafe.sol3.02 KB
- contracts/modules/BaseModule.sol4.82 KB
- contracts/modules/ModuleStorage.sol748 B
- contracts/utils/Enum.sol277 B
contracts/modules/LucidityModule.sol
// SPDX-License-Identifier: MIT
/// @title Core Lucidity Module
pragma solidity ^0.8.20;
import './BaseModule.sol';
import './ModuleStorage.sol';
import '../interfaces/IRegistry.sol';
import '../interfaces/IFlashloanHandler.sol';
import '../interfaces/ISafe.sol';
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
contract LucidityModule is ModuleStorage, BaseModule, OwnableUpgradeable {
event LucidityRegistryUpdated(address _lucidityRegistry);
event DisabledFlashloanHandler(address _flashLoanHandler);
event EnabledFlashloanHandler(address _flashLoanHandler);
constructor() {
_disableInitializers();
}
/**
* @notice Initializer for the BaseModule
* @param _owner The owner of the Module Singleton.
* @param _registry The address of the Lucidity registry
*/
function initialize(address _registry, address _owner) public initializer {
MainStorage storage mainStorage = _getMainStorage();
__Ownable_init(_owner);
mainStorage.LUCIDITY_MODULE_SINGLETON = address(this);
mainStorage.lucidityRegistry = IRegistry(_registry);
}
// Can only be called as delegatecall from a GnosisSafe during setup.
function enableModule(
address module,
address registry,
address owner
) external {
MainStorage storage mainStorage = _getMainStorage();
require(
_isContract(address(this)),
'enableModule should only be called via smartcontract'
);
require(
address(this) != mainStorage.LUCIDITY_MODULE_SINGLETON,
'enableModule should only be called via delegatecall'
);
// Enable Module
ISafe((address(this))).enableModule(module);
// Register the safe for the user.
IRegistry(registry).registerSafeForUser(ISafe((address(this))), owner);
// event is emitted by the safe.
}
/** @dev Passes a transaction to be executed by the safe.
* @notice Can only be called by this contract.
* @param tos Destination address of module transaction.
* @param values Ether value of module transaction.
* @param datas Data payload of module transaction.
* @param operations Operation type of module transaction: 0 == call, 1 == delegate call.
* @param safe address that will be used to execute the module transactions.
*/
function exec(
address[] calldata tos,
uint256[] calldata values,
bytes[] memory datas,
Enum.Operation[] calldata operations,
ISafe safe
) external payable {
require(tos.length == values.length, 'Tos and values length inconsistent');
require(tos.length == datas.length, 'Tos and datas length inconsistent');
require(
tos.length == operations.length,
'Tos and operations length inconsistent'
);
// First transfer the eth to safe if there is any msg.value sent with the tx.
if (msg.value > 0) {
(bool sent, ) = address(safe).call{value: msg.value}('');
require(sent, 'Failed to send Ether');
}
for (uint256 i = 0; i < tos.length; i++) {
_execTx(tos[i], values[i], datas[i], operations[i], safe);
}
}
/** @dev Passes a transaction to be executed by the target and returns data.
* @notice Can only be called by this contract.
* @param tos Destination address of module transaction.
* @param values Ether value of module transaction.
* @param datas Data payload of module transaction.
* @param operations Operation type of module transaction: 0 == call, 1 == delegate call.
* @param safe address that will be used to execute the module transactions.
*/
function execAndReturnData(
address[] calldata tos,
uint256[] calldata values,
bytes[] memory datas,
Enum.Operation[] calldata operations,
ISafe safe
)
external
payable
returns (bool[] memory successes, bytes[] memory returnDatas)
{
require(tos.length == values.length, 'Tos and values length inconsistent');
require(tos.length == datas.length, 'Tos and datas length inconsistent');
require(
tos.length == operations.length,
'Tos and operations length inconsistent'
);
// First transfer the eth to safe if there is any msg.value sent with the tx.
if (msg.value > 0) {
(bool sent, ) = address(safe).call{value: msg.value}('');
require(sent, 'Failed to send Ether');
}
for (uint256 i = 0; i < tos.length; i++) {
(successes[i], returnDatas[i]) = _execTx(
tos[i],
values[i],
datas[i],
operations[i],
safe
);
}
}
/**
* @notice Executes a flashloan
* @param flashloanHandler The flashloan handler contract address
* @param assetsToFlashloan The assets to flashloan
* @param amountsToFlashloan The amounts to flashloan
* @param dataToExecute The data to execute - abi.encode(tos, values, datas, operations, safe);
*/
function execFlashloan(
IFlashloanHandler flashloanHandler,
address[] calldata assetsToFlashloan,
uint[] calldata amountsToFlashloan,
bytes calldata dataToExecute
) external {
MainStorage storage mainStorage = _getMainStorage();
require(
mainStorage.flashLoanHandlers[flashloanHandler] == true,
'Invalid flashloan handler'
);
require(
assetsToFlashloan.length == amountsToFlashloan.length,
'Invalid lengths'
);
(, , , , ISafe safe) = abi.decode(
dataToExecute,
(address[], uint256[], bytes[], Enum.Operation[], ISafe)
);
// Check if the caller is the safe owner
_checkIfValidCaller(msg.sender, safe);
bytes memory data = abi.encode(dataToExecute, msg.sender);
require(
flashloanHandler.execFlashloan(
assetsToFlashloan,
amountsToFlashloan,
data
) == true
);
}
// Admin Functions
/**
* @notice Enables a flashloan handler
* @param _flashLoanHandler The flashloan handler
* @dev Can only be called by the owner
* @dev Emits an event
*/
function enableFlashloanHandler(
IFlashloanHandler _flashLoanHandler
) public onlyOwner {
MainStorage storage mainStorage = _getMainStorage();
mainStorage.flashLoanHandlers[_flashLoanHandler] = true;
emit EnabledFlashloanHandler(address(_flashLoanHandler));
}
/**
* @notice Disables a flashloan handler
* @param _flashLoanHandler The flashloan handler
* @dev Can only be called by the owner
* @dev Emits an event
*/
function disableFlashloanHandler(
IFlashloanHandler _flashLoanHandler
) public onlyOwner {
MainStorage storage mainStorage = _getMainStorage();
mainStorage.flashLoanHandlers[_flashLoanHandler] = false;
emit DisabledFlashloanHandler(address(_flashLoanHandler));
}
/**
@notice Return the status of a flashloan handler
@param _flashLoanHandler The flashloan handler
*/
function isFlashloanHandlerEnabled(
IFlashloanHandler _flashLoanHandler
) public view returns (bool) {
return _getMainStorage().flashLoanHandlers[_flashLoanHandler];
}
/**
* @notice Sets the lucidity registry
* @param _registryAddress The Lucidity Registry
* @dev Can only be called by the owner
* @dev Emits an event
*/
function setLucidityRegistry(address _registryAddress) public onlyOwner {
MainStorage storage mainStorage = _getMainStorage();
mainStorage.lucidityRegistry = IRegistry(_registryAddress);
emit LucidityRegistryUpdated(address(_registryAddress));
}
/**
* @notice Gets the lucidity registry.
*/
function getLucidityRegistry() public view returns (IRegistry) {
return _getMainStorage().lucidityRegistry;
}
/**
* @notice Gets the flashloan handlers
*/
function getLucidityModule() public view returns (address) {
return _getMainStorage().LUCIDITY_MODULE_SINGLETON;
}
}
@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
OwnableStorage storage $ = _getOwnableStorage();
return $._owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
contracts/interfaces/IFlashloanHandler.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
interface IFlashloanHandler {
function execFlashloan(
address[] calldata assetToFlashloan,
uint[] calldata amount,
bytes calldata data
) external returns (bool);
}
contracts/interfaces/IRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import './ISafe.sol';
interface IRegistry {
function userSafes(address) external view returns (address);
function handlers(address) external view returns (bytes32);
function callers(address) external view returns (bytes32);
function bannedAgents(address) external view returns (uint256);
function fHalt() external view returns (bool);
function isValidHandler(address handler) external view returns (bool);
function isValidCaller(address handler) external view returns (bool);
function registerSafeForUser(ISafe safe, address user) external;
}
contracts/interfaces/ISafe.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
import '../utils/Enum.sol';
interface ISafe {
event EnabledModule(address module);
event DisabledModule(address module);
event ExecutionFromModuleSuccess(address indexed module);
event ExecutionFromModuleFailure(address indexed module);
/// @dev Enables a module on the safe
/// @notice Can only be called by the safe
/// @notice Modules should be stored as a linked list.
/// @notice Must emit EnabledModule(address module) if successful.
/// @param module Module to be enabled.
function enableModule(address module) external;
/// @dev Disables a module on the safe
/// @notice Can only be called by the safe
/// @notice Must emit DisabledModule(address module) if successful.
/// @param prevModule Address that pointed to the module to be removed in the linked list
/// @param module Module to be removed.
function disableModule(address prevModule, address module) external;
/// @dev Allows a Module to execute a transaction.
/// @notice Can only be called by an enabled module.
/// @notice Must emit ExecutionFromModuleSuccess(address module) if successful.
/// @notice Must emit ExecutionFromModuleFailure(address module) if unsuccessful.
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction: 0 == call, 1 == delegate call.
function execTransactionFromModule(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation
) external returns (bool success);
/// @dev Allows a Module to execute a transaction and return data
/// @notice Can only be called by an enabled module.
/// @notice Must emit ExecutionFromModuleSuccess(address module) if successful.
/// @notice Must emit ExecutionFromModuleFailure(address module) if unsuccessful.
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction: 0 == call, 1 == delegate call.
function execTransactionFromModuleReturnData(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation
) external returns (bool success, bytes memory returnData);
/// @dev Returns if an module is enabled
/// @return True if the module is enabled
function isModuleEnabled(address module) external view returns (bool);
/// @dev Returns array of modules.
/// @param start Start of the page.
/// @param pageSize Maximum number of modules that should be returned.
/// @return array Array of modules.
/// @return next Start of the next page.
function getModulesPaginated(
address start,
uint256 pageSize
) external view returns (address[] memory array, address next);
function getOwners() external view returns (address[] memory);
}
contracts/modules/BaseModule.sol
// SPDX-License-Identifier: MIT
/// @title Module Interface - A contract that can pass messages and execute transactions to a Safe contract if enabled by that contract.
pragma solidity ^0.8.20;
import '../utils/Enum.sol';
import '../interfaces/ISafe.sol';
import './ModuleStorage.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
/**
* @title BaseModule
* @dev Base contract for modules in the Lucidity v1 protocol.
*/
contract BaseModule is ModuleStorage {
/**
* @dev Executes a transaction on a target contract.
* @param to The address of the target contract.
* @param value The amount of Ether to send with the transaction.
* @param data The data payload for the transaction.
* @param operation The operation type for the transaction (e.g., CALL, DELEGATECALL, etc.).
* @param safe The instance of the Safe contract.
* @return success A boolean indicating the success of the transaction.
* @return returnData The return data of the transaction.
*/
function _execTx(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
ISafe safe
) internal returns (bool success, bytes memory returnData) {
_checkTransaction(to, safe, msg.sender);
(success, returnData) = safe.execTransactionFromModuleReturnData(
to,
value,
data,
operation
);
if (success == false) {
_revert(returnData);
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert('Batch call failed');
}
}
/** @dev Guard transactions only use the first four parameters: to, value, data, and operation.
* Guard.sol hardcodes the remaining parameters as 0 since they are not used for guard transactions.
* @notice This interface is used to maintain compatibilty with Gnosis Safe transaction guards.
*/
function _checkTransaction(
address to,
ISafe safe,
address originalSender
) internal view {
// Check if originalSender is the owner of the safe.
_checkIfValidCaller(originalSender, safe);
// Check if to is the whitelisted address via registry.
// _checkIfValidTarget(to, safe);
}
/**
* @dev Checks if the originalSender is the owner of the safe or a whitelisted caller in the registry.
* @param originalSender The original sender of the transaction.
* @param safe The instance of the Safe contract.
*/
function _checkIfValidCaller(
address originalSender,
ISafe safe
) internal view {
MainStorage storage mainStorage = _getMainStorage();
bool isOwner = address(
mainStorage.lucidityRegistry.userSafes(originalSender)
) == address(safe);
bool isValidCaller = mainStorage.lucidityRegistry.isValidCaller(
originalSender
);
require(isOwner || isValidCaller, 'Invalid callers');
}
/**
* @dev Checks if the target is a whitelisted address in the registry.
* @param target The address of the target. Example: AaveLendingPool, or any other contract that safe will send transaction to.
* @notice The purpose of this function is to control contracts to which safe can send the transaction.
*/
function _checkIfValidTarget(address target, ISafe safe) internal view {
MainStorage storage mainStorage = _getMainStorage();
require(target != address(0), 'zero address');
bool isValidTarget;
if (
address(mainStorage.lucidityRegistry.userSafes(target)) == address(safe)
) {
isValidTarget = true;
} else if ((address(safe) == target)) {
isValidTarget = true;
} else if (mainStorage.lucidityRegistry.isValidHandler(target) == true) {
isValidTarget = true;
}
require(isValidTarget, 'Invalid handler.');
}
/**
* @notice Returns true if `account` is a contract.
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param account The address being queried
* @return True if `account` is a contract
*/
function _isContract(address account) internal view returns (bool) {
uint256 size;
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly {
size := extcodesize(account)
}
/* solhint-enable no-inline-assembly */
return size > 0;
}
}
contracts/modules/ModuleStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import '../interfaces/IFlashloanHandler.sol';
import '../interfaces/IRegistry.sol';
contract ModuleStorage {
// keccak256(abi.encode(uint256(keccak256('modulestorage.main')) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant MAIN_STORAGE_LOCATION =
0x5343796fba3ac3e19f4e5aac935ab1fa90ab94423c688107250cc7fdfcce2900;
/// @custom:storage-location erc7201:<LucidityModule>
struct MainStorage {
address LUCIDITY_MODULE_SINGLETON;
IRegistry lucidityRegistry;
mapping(IFlashloanHandler => bool) flashLoanHandlers;
}
function _getMainStorage() internal pure returns (MainStorage storage $) {
assembly {
$.slot := MAIN_STORAGE_LOCATION
}
}
}
contracts/utils/Enum.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Enum - Collection of enums used in Safe contracts.
* @author Richard Meissner - @rmeissner
*/
abstract contract Enum {
enum Operation {
Call,
DelegateCall,
Flashloan
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 400,
"enabled": true
},
"evmVersion": "paris",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.