Integrate the Stackup Bundler into other Golang applications.
Besides running as a standalone service, the bundler is built with packages that can be ported into other Golang based application. This is useful for Golang based block builders and paymasters who want to support EIP-4337.
Adding the dependency
To get started, add the the
stackup-bundler package to your project using Go modules (version 1.19+ required).
go get -u github.com/stackup-wallet/stackup-bundler
All packages that can be imported live in the
pkg directory. The full Go documentation of all available packages can be found here.
On a high level the
stackup-bundler is based around a few core packages. This section will give a quick overview to make diving into the Go documentation and source code more productive.
Want to see it in practice?
Check the code for setting up a standalone private bundler as a concrete example of how these packages are used in practice.
userop package provides the struct for an ERC-4337 style transaction. This is the core data structure that is used throughout all the other packages within the
mempool package provides a pool of all UserOperations that are known to the bundler. A UserOperation that enters the mempool is assumed to have passed all relevant checks by the client. The
mempool is also backed by an embedded database (badgerDB) to provide persistance through server resets.
client package acts as a mediator that controls the processing of incoming UserOperations to make sure they are valid before adding it to the mempool. The
client is also required to be flexible enough to run in many different modes and can be customized in how it processes incoming UserOperations with the use of standardized modules.
bundler package acts as another mediator that controls the process of batching UserOperations from the mempool and sending them to the EntryPoint. The
bundler is also required to be flexible enough to run in many different modes and can be customized in how it processes outgoing batches with the use of standardized modules.
modules package provides standard interfaces for extending instances of the client and bundler with middleware to process UserOperations and batches.
The architecture of the
stackup-bundler is similar to the architecture of ERC-4337 in the ERC-4337 Overview, plus a few extra boxes that is worth mentioning in this context.
UserOperationreaches the client through any arbitrary transport layer (e.g. HTTP or P2P).
The client validates the
- Checks the EntryPoint is supported.
UseOperationhas the correct schema.
- There are no duplicates in the mempool or it has high enough gas to replace it.
- Sends the
UserOperationthrough the middleware stack for processing.
UserOperationis added to the mempool. The mempool will also save it in an embedded database for persistence.
In a separate goroutine, the bundler will run a repeated process:
- Queries the mempool for new batches.
- Sends the batch through the middleware stack for processing.
- Removes processed UserOperations from the mempool.
Updated about 1 month ago