Module Development
Part 1: Implementation Contract
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.20;
import './interfaces/IMyModulePluginImplementation.sol';
// ERC-7201 namespaced storage - defined alongside the implementation
library MyModuleStorage {
/// @dev keccak256(abi.encode(uint256(keccak256("erc7201:algebra.storage.mymodule")) - 1)) & ~bytes32(uint256(0xff))
bytes32 internal constant NAMESPACE = 0x/* compute offline */00;
struct Layout {
uint256 someValue;
address someAddress;
bool isActive;
}
function layout() internal pure returns (Layout storage l) {
bytes32 position = NAMESPACE;
assembly { l.slot := position }
}
}
contract MyModulePluginImplementation is IMyModulePluginImplementation {
/// @notice Initialize module state. Called once during plugin initialization
function initializeMyModule(uint256 initialValue, address initialAddress) external {
MyModuleStorage.Layout storage s = MyModuleStorage.layout();
s.someValue = initialValue;
s.someAddress = initialAddress;
s.isActive = true;
}
/// @notice Core module logic. Called from the assembled plugin's afterSwap handler
function processAfterSwap(bool zeroToOne) external {
MyModuleStorage.Layout storage s = MyModuleStorage.layout();
if (!s.isActive) return;
// ... your logic here
s.someValue += 1;
}
/// @notice Admin function. Updates configuration
function setSomeValue(uint256 newValue) external {
MyModuleStorage.layout().someValue = newValue;
}
}Part 2: Connector
Plugin Config Flags
Flag
Value
Hook triggered
_authorize() and _delegateCall()
_authorize() and _delegateCall()Part 3: Integration into the Assembled Plugin
Last updated