Skip to main content

Deploy an Example SUAPP

The suave-geth repo has an example version of MEV-Share along with a script that will:

  1. deploy the MEV-Share contract
  2. sign and submit a transaction to be back run
  3. grab the extracted hint from onchain
  4. sign a back run transaction and submit it

Running the Script

If you followed the previous sub-section, you will have SUAVE running locally, either in Docker or via the binaries themselves.

In either case, you can cause a series of transactions to occur by running:

go run suave/devenv/cmd/main.go

This script is focused on sending transactions in a local dev environment, but you can repurpose it for Rigil by changing the exNodeNetAddr and exNodeEthAddr.

Step-by-Step Breakdown

Let's break down what this script is doing.

Step 1: Create and Fund Test Accounts

testAddr1 = generatePrivKey()
testAddr2 = generatePrivKey()

if err := fundAccount(mevmClt, testAddr1.Address(), fundBalance); err != nil {
return err
}
fmt.Printf("- Funded test account: %s (%s)\n", testAddr1.Address().Hex(), fundBalance.String())
  • Generate two new private keys representing test accounts.
  • Fund these test accounts with a specified amount of Ether to simulate transactions.

Step 2: Deploy MEV-Share Contract

// Code snippet related to the step
txnResult, err := sdk.DeployContract(mevShareArtifact.Code, mevmClt)
  • Deploy the MEV-Share smart contract to the SUAVE chain using the bytecode and a client instance.
  • Confirm the deployment by checking the transaction receipt status.

Step 3: Send Bid

    refundPercent := 10
bundle := &types.SBundle{
Txs: types.Transactions{ethTxn1},
RevertingHashes: []common.Hash{},
RefundPercent: &refundPercent,
}
bundleBytes, _ := json.Marshal(bundle)

targetBlock := uint64(1)
allowedPeekers := []common.Address{mevShareContract.Address()}

confidentialDataBytes, _ := bundleBidContract.Abi.Methods["fetchBidConfidentialBundleData"].Outputs.Pack(bundleBytes)

txnResult, err := mevShareContract.SendTransaction("newBid", []interface{}{targetBlock + 1, allowedPeekers, []common.Address{}}, confidentialDataBytes)
if err != nil {
return err
}
  • Craft a bid using the MEV-Share contract function newBid.
  • Serialize the bundle of transactions to include in the bid.
  • Send the bid to the SUAVE chain and validate its inclusion.

Step 4: Send Backrun

    backRunBundle := &types.SBundle{
Txs: types.Transactions{ethTxnBackrun},
RevertingHashes: []common.Hash{},
}
backRunBundleBytes, _ := json.Marshal(backRunBundle)

confidentialDataMatchBytes, _ := bundleBidContract.Abi.Methods["fetchBidConfidentialBundleData"].Outputs.Pack(backRunBundleBytes)

// backrun inputs
targetBlock := uint64(1)
allowedPeekers := []common.Address{mevShareContract.Address()}

txnResult, err := mevShareContract.SendTransaction("newMatch", []interface{}{targetBlock + 1, allowedPeekers, []common.Address{}, bidId}, confidentialDataMatchBytes)
if err != nil {
return err
}
  • Create a backrun transaction bundle that will be sent after the initial bid.
  • Serialize the backrun bundle and use the MEV-Share contract's newMatch function to submit it.
  • Verify the transaction receipt to ensure the backrun was successful.

Result

If all has been succesfully run you should see the following in your terminal:

suave-geth$ go run suave/devenv/cmd/main.go
Step 0: Create and fund test accounts
- Funded test account: 0x66d5a8D6B34329c0639071275b3d78D29e11EbC6 (100000000)
Step 1: Deploy mev-share contract
- Mev share contract deployed: 0x8f21Fdd6B4f4CacD33151777A46c122797c8BF17
Step 2: Send bid
- Bid sent at txn: 0xb49debcdead2b306d6ab6282b88fdad7c8d6a33d87df34b79f56d141eae7c08a
- Bid id: 30bbc65298f24e67aaf5c95bf5f0686c
Step 3: Send backrun
- Backrun sent at txn: 0xcf7880e61e94aaab48c60655c321716ecab6edab752586448b0412e93a969889
- Backrun bid id: db98b83d02694fc2b13c042ad22c233