Learn how to write your own MEV Plus modules
1.20+
installed on your system.Name() string
: Returns the name of the module.
Start() error
: Starts the module lifecycles. You can start any non-blocking microservice or internal logic here. MEV Plus would call this method after calling Configure.
Stop() error
: Stops the module lifecycles. Implement logic to stop any microservices, goRoutines, servers, etc. This is called by MEV Plus on shutdown or if anything fails.
ConnectCore(coreClient *Client, pingId string) error
: Connects the module to the MEV Plus core service. MEV Plus would create a secure communication client during start up and pass this to your module as the coreClient as well as a on-time generated pingId for you to use to connect your module to MEV Plus’ core communication channels. Store this coreClient in a struct/map/registry within your module in order to communicate with the core and other modules. In order for MEV Plus to relay communication securely to your module, within the ConnectCore method, you must implement a core_ping call to pass the unique pingId back to MEV Plus that on runtime no other module can spoof and is used to determine your module being up and running and securely available to communicate across the ecosystem.
Configure(moduleFlags common.ModuleFlags) error
: Configures the module with the provided flags. Your module provides a cli command to MEV Plus with any attached flags, this is made available to a user when running MEV Plus’ CLI app. Any flags provided can be set by the user when running MEV Plus and is securely provided to each module as a string value for any flags set. Your module flags and arguments and values are never shared across modules and thus no other code, module, or operation can access private data passed as an argument to your module flags.
CliCommand() *cli.Command
: Returns the CLI command for the module, allowing MEV Plus to parse the flags. The Command has a name and this name is required to be the unique name of your module/package this name MUST also be the name string that Name() string
returns.
https://
prefix. Eg. github.com/restaking-cloud/native-delegation-for-plus
service.go
) in the root of your repository/directory and implement the MEV Plus Service interface. The entire interface must be implemented in the same file. You may define other structs, and methods, however ensure the struct that implements the MEV Plus interface is in the same file as the interface methods.
Also give the service file a package name of which should be your module’s name. Not your module package url. In this tutorial we would be creating a module with name myTest
Here’s a basic template:
<set_module_flag_name>
(string) to <module_flag_value>
(string)
ONLY flags a user sets for your module would be passed to your module. If your module’s logic has no reason to boot up when a user has not activated the module or passed any flags, you can perform the check here to choose what happens when MEV Plus then calls Start
after configuring your module with Configure
.
*cli.Command
. This function should be part of your module’s configuration package. The CLI command should include the module name, usage text, and any flags your module requires.
CliCommand
and the Name
method, use the ModuleName
constant when defining these.
Call
, CallContext
or Notify
methods. These methods allow you to call methods on other modules by specifying the module name and method name in the form:
coreClient.Notify
, coreClient.Call
and coreClient.CallContext
methods are used to interact with other modules in MEV Plus, allowing one module to call methods on another module or send notifications.These methods are part of the core client’s API, which facilitates inter-module communication. Let’s break down the different arguments for each method:
ctx context.Context
: This is the context for the operation. It can be used to cancel the operation if needed.
method string
: The name of the method to call on the target module. This should be in the format <module_name>_<method_name>
.
notifyAll bool
: If set to true, the notification will be sent to all modules that have the specified method name as a public method on their service struct. If false, the notification will only be sent to the first module that matches the method name.
notificationExclusion []string
: A list of module names to exclude from receiving the notification. This is useful when you want to notify all modules except for certain ones.
args ...interface{}
: The arguments to pass to the method being called. These should match the parameters defined in the method signature of the target module.
result interface{}
: A pointer to a variable where the result of the method call will be stored. This must be a pointer so that the method’s return value can be unmarshaled into it. If you don’t need the result, you can pass nil.
method string
: The name of the method to call on the target module. This should be in the format <module_name>_<method_name>
.
notifyAll bool
: Similar to the Notify method, this determines whether the call should notify all modules with the specified method name.
notificationExclusion []string
: A list of module names to exclude from receiving the notification. This is useful when you want to notify all modules except for certain ones.
args ...interface{}
: The arguments to pass to the method being called. These should match the parameters defined in the method signature of the target module.
ctx context.Context
: This is the context for the operation. It can be used to cancel the operation if needed. This context can also carry deadlines, timeouts, and other request-scoped values across API boundaries and between processes.
result interface{}
: A pointer to a variable where the result of the method call will be stored. This must be a pointer so that the method’s return value can be unmarshaled into it. If you don’t need the result, you can pass nil.
method string
: The name of the method to call on the target module. This should be in the format <module_name>_<method_name>
.
notifyAll bool
: Similar to the Notify method, this determines whether the call should also notify all other modules with the specified method name.
notificationExclusion []string
: A list of module names to exclude from receiving the notification. This is useful when you want to notify all modules except for certain ones.
args ...interface{}
: The arguments to pass to the method being called. These should match the parameters defined in the method signature of the target module.
v1.0.0
). This helps users to easily identify the version of your module they want to install.
github.com/yourusername/[email protected]
with the actual GitHub URL and version tag of your module, i.e your <module-package-url>
you created in Step 2.