To send your first commitment, you will need to connect to the mev-commit Testnet. This will allow you to consume bids incoming to the network and submit commitments. To do this, you’ll want to run an emulator to simulate accepting and rejecting bids.

You will want to connect to a decisioning system that will accept and reject bids based on custom criteria. You can read more about the API to open a gRPC stream here.

As an example, a dummy decisioning system is implemented in the repository. This dummy system accepts all the bids it gets. To try it, you can open a new terminal and run the following command:

You require Go Version 1.21.1 to run the example emulator
git clone --recurse-submodules https://github.com/primev/mev-commit.git && cd mev-commit &&
git checkout v0.5.0 && cd p2p/examples/provideremulator && go run . 

Configuring custom logic to process bids and send Commitments

We can take a deeper look at how you can add custom logic to decision on the sending of commitments.

Integrating Bid Processing in Your System

To integrate bid processing in your system using the Provider API, follow these steps to receive bid information and send back processed bids:

1

Implement the gRPC Service

Implement the Provider service as outlined in the providerapi.proto. This requires setting up a server that can manage RPC methods, with a particular emphasis on the reception of bids and response of commitment authorizations.

2

Receive Bids

Utilize the ReceiveBids RPC method to listen for incoming bids from clients. This method streams bid messages to your server. The structure of the bid is as follows:

message Bid {
  option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = {
    json_schema: {
      title: "Bid message"
      description: "Signed bid message from bidders to the provider."
      required: ["txHashes", "bidAmount", "blockNumber", "bidDigest"]
    }
    example: "{"bidDigest": "9dJinwL+FZ6B1xsIQQo8t8B0ZXJubJwY86l/Yu7yAH159QrPHU0qj2P+YFj+llbuI1ZygdxGsX8+P3byMEA5ig==", "status": "STATUS_ACCEPTED"}"
  };
  repeated string tx_hashes = 1;
  string bid_amount = 2;
  int64 block_number = 3;
  bytes bid_digest = 4;
  int64 decay_start_timestamp = 5;
  int64 decay_end_timestamp = 6;
  repeated string reverting_tx_hashes = 7;
  repeated string rawTransactions = 8;
};

The raw transactions are optionally provided by the bidder. If provided the order of the transaction hashes in txHashes will be the same as the order or the corresponding rawTransactions.

Below is an image of the flow through which bids would be received through the gRPC API

3

Process Bids

For each received bid, implement your custom logic to validate and process these bids. This could involve checking the bid’s validity and feasibility based on orderflow, computing the effective gas price, and deciding whether to accept or reject the bid.

4

Send Processed Bid Responses (Accept/Reject)

After processing each bid, construct a BidResponse message indicating the outcome. This message should include the bid’s digest and a status indicating acceptance or rejection. At a high level, to commit to a bid, your code must send a STATUS_ACCEPTED with the bid digest specified, and correspondingly STATUS_REJECTED to reject the bid.

5

Server Setup

Deploy your gRPC server on suitable infrastructure, ensuring it’s accessible to clients. Configure necessary network settings for security and connectivity. Example Server Implementation in Go:


import (
	...

	"github.com/primev/mev-commit/p2p/examples/provideremulator/client"
	providerapiv1 "github.com/primev/mev-commit/p2p/gen/go/providerapi/v1"
)

func ...() {
	...

	providerClient, _ := client.NewProviderClient(*serverAddr, logger)

	bidS, _ := providerClient.ReceiveBids()

	for {
		select {
		case bid, more := <-bidS:
			if !more {
				return
			}
			logger.Info("received new bid", "bid", bid)
			_ := providerClient.SendBidResponse(context.Background(), &providerapiv1.BidResponse{
				BidDigest: bid.BidDigest,
				Status:    providerapiv1.BidResponse_STATUS_ACCEPTED, // decide here if you want to accept or reject
        DispatchTimestamp: time.Now().Unix(),
			})
		}
	}
}

This should help you integrate bid processing into your system, allowing you to receive bid information and send back processed bids as commitments.