MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose.

Overview

MevWallet

MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose.

This repo contains the solidity contracts in contracts/, deployment tooling in script/, and a Rust library for interacting with the contracts in src/.

THIS IS UNAUDITED CODE. USE AT YOUR OWN RISK

Wait what?

MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose.

Ok yeah I heard you the first time, what does that mean?

User transactions pay fees, and may generate MEV. Searchers take the MEV from the user, and pay it to block proposers. This means that users are effectively paying block creators twice. Once via MEV, and once via the regular transaction fee.

MevWallet changes this relationship. Instead of paying block proposers via tx fees, users make transactions via the MevWallet. These transaction pay no tx fee. Instead, MevWallet transactions create MEV, and allow Searchers to pay tx fees on the user's behalf. This allows users to more effectively and efficiently price their transactions.

It also allows one more (really cool thing). It lets the user give the Searcher negative MEV. This means that the Searcher's bundle must pay the user for the right to broadcast the transaction. If the user is creating a large amount of MEV, they can force the Searcher to give them a cut of that MEV. The user gets to use this to cover their tx fees (cool!) and potentially end up paying less than 0 tx fees (coooler!).

Addresses

  • MevWeth: 0x00000000008C43efC014746c230049e330039Cb3
  • MevWalletV1 Implementation: 0x0000000000c08718718B974D644B098C19bd0064
  • MevWalletV1 ProxyFactory: 0x9248B5e672e1880af34068C0FaE18D30c26D05Fb

Didn't bother to grind an address for the proxy factory :)

How do I integrate it?

This repo has a Rust library for working with MevTxns. I'm also publishing a typescript library using ethers.js.

Use MevTxBuilder to build a txn:

let mev_tx: MevTx = MevTxBuilder::new()
  .from(&wallet_contract)
  .to(weth_address)
  .call(
    // WOW! you can use any `abigen!` generated call here!
    // (you can also you `.data(some_bytes)` to set the raw calldata
    ierc20::TransferCall {
      recipient,
      amount,
    }
  )
  .tip(1_000_000_000)
  .populate()
  .await?
  .build();
let signed_mev_tx = mev_tx.sign(wallet_address, signer).await?;

// You can convert from an ether-rs tx too!
// Middleware is required to resolve typed tx ENS name. This can often be a
// dummy middleware.
let typed_tx = weth.transfer(recipient, amount);
let signed_mev_tx = MevTxBuilder::from_typed_tx(&wallet_contract, typed_tx)
  .await?
  .nonce(5)
  // adding a signer signs the mev tx when it's built :)
  .with_signer(signer)
  // Defaults to the signer's chain_id
  .with_chain_id(31337)
  .populate()
  .await?
  .build(wallet_address)
  .await?;

Searchers should can use any middleware to send a MevTx:

let signed_mev_tx = serde_json::from_str(a_serialized_tx)?;

// `into_call` converts into a normal `ContractCall` wrapping the MevTx
// it sets value to the mev_tx_value, and
let pending = signed_mev_tx
  .into_call(arc_middleware.clone())
  // modify gas or w/e here :)
  // it is STRONGLY ADVISED that you use `.call()` to simulate
  // as we do not currently check the code at the wallet address
  .send()
  .await?;

You can also use this lib to deploy a new proxy contract:

// set owner to msg.sender
let my_wallet = MevWallet::new_proxy(middleware, salt).await?;

// set owner to an arbitrary address
let my_wallet = MevWallet::new_proxy(middleware, salt, owner_address).await?;

However, if doing it manually might be easier to use forge

forge script --broadcast $FORGE_SIGNER_INFO DeployProxyV0 --sig "run(bytes32)" $SALT -vvvvvv

MevTx Layout

MevTxns are very similar to normal txns, and are signed with EIP712.

  • to -- target address for the call.
  • data -- data for the call.
  • value -- value that should be passed in the call.
  • delegate -- true for delegatecall (but be careful!). Must be false if value is non-0
  • tip -- MEV created by the tx, in wei, can be negative
  • maxBaseFee -- call should not be executed above this basefee (may be 0, for no max)
  • deadline -- call should not be executed after this timestamp (may be 0, for no deadline)
  • nonce -- nonce for the MevTx, as set in MevWallet state

Repo Setup

$ git submodule update --init --recursive

Running Tests

Integrations tests are a bit funky right now. Run ./devenv.sh to start an anvil instance. Then run cargo test in another terminal. Use ctrl+C to exist the anvil instance when necessary.

Regenerating contract bindings.

It is NOT RECOMMENDED that you make contract changes. If you must, make sure to run ./bind.sh to generate the rust bindings.

Deploying MevWallet

If working on chain with a MevWeth deployment, use these scripts (including your RPC and signer details):

# deploy the implementation to a new chain
forge script DeployImplV0
# deploy the proxy factory to a new chain
forge script DeployFactoryV0
# deploy a new proxy wallet
forge script DeployProxyV0.sol --sig "run(bytes32)" $YOUR_SALT_BYTES32

If working on a fresh anvil instance or a chain without MevWeth, follow the MevWeth deployment instructions. Then deploy MevWallet as above :)

You might also like...
Emerging smart contract language for the Ethereum blockchain.

Emerging smart contract language for the Ethereum blockchain.

Smart Contract built in Rust to run inside Cosmos SDK module on all chains that enable it

CoinSwap is a Smart Contract that is built on the terra blockchain and can be used to swap cryptocurrencies such as LUNA, UST, TerraUSD, Anchor, Mirror Protocol, LUNI and other CW20 tokens. The Project also contains a smart contract which works as a analysis tool for the gas fees on the Terra Blockchain.

Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis.
Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis.

Heimdall is an advanced EVM toolkit which aims to make dealing with smart contracts on EVM based chains easier. Installation & Usage Heimdall's update

A simple example demonstrating cross-contract calls in CosmWasm smart contracts

Cross-contract calls This tutorial demonstrates cross-contract calls with CosmWasm v1. Overview An end user calls the reservation contract to register

The Ink! smart contract SDK for XVM interface

Ink! XVM SDK The Ink! smart contract SDK for XVM interface. This SDK contains contract wrappers and all middleware code to make XVM development easy.

Example NFT marketplace project using ink! smart contract.

NFT Marketplace project This contract is an example for the NFT marketplace implementation. License Apache 2.0 🏗️ How to use - Contracts 💫 Build Use

An EVM low-level language that gives full control over the control flow of the smart contract.

Meplang - An EVM low-level language Meplang is a low-level programming language that produces EVM bytecode. It is designed for developers who need ful

A smart-contract api and client for revm

revmup A smart contract and client API for revm. Features: Auto-generate contracts that interact directly with revm without needing ethers provider Co

A brand-new multi-scenarios smart contract compiler framework

The Smart Intermediate Representation The Smart Intermediate Representation(short for IR) project is a new compiler framework intended for smart contr

Owner
Blunt Instruments
smashing solutions to difficult problems
Blunt Instruments
Clipboard Capture for Linux, it can capture the contents of clipboard (or primary selection)

Clipboard Capture for Linux, it can capture the contents of clipboard (or primary selection), as it changes when the program is running and print it to stdout. You can also choose to run some command on each capture.

Zero 5 Aug 6, 2022
A Bitcoin wallet collider that brute forces random wallet addresses written in Rust.

Plutus-Rustus Bitcoin Brute Forcer A Bitcoin wallet collider that brute forces random wallet addresses written in Rust. This is a straight port of Plu

null 46 Dec 23, 2022
Substrate NFT !ink smart contract base

Substrate !ink NFT simple implementation This is a simple working version of base NFT smart contract written using latest (as of this date) !ink 3.0.0

POLK4.NET 14 Dec 3, 2022
clockchain is a system for benchmarking smart contract execution times across blockchains.

Clockchain Clockchain is a research tool for benchmarking smart contract execution times across blockchains using Arcesco-- a block-chain agnostic ins

Zeke Medley 7 Oct 3, 2022
Testing a smart contract on the Solana blockchain

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

Maurice 1 Oct 25, 2021
clockchain is a system for benchmarking smart contract execution times across blockchains.

Clockchain Clockchain is a research tool for benchmarking smart contract execution times across blockchains using Arcesco-- a block-chain agnostic ins

zeke 7 Oct 3, 2022
The NFT smart contract powering xyz on Terra

xyz NFT Contract This repository contains the core NFT smart contract that implements xyz, a base layer for metaverses on the Terra blockchain. The xy

null 16 Sep 25, 2022
An example smart contract that builds on top of xyz

xyz Guestbook Tutorial Contract This repository contains an example smart contract that illustrates how to build on top of the xyz NFT contract. This

null 5 Apr 4, 2022
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

ono 6 Jan 30, 2022
Smart Contract for Terra Name Service

TERRA NAME SERVICE CONTRACTS Terra Name Service is to create easy-to-remember names for your Terra address like ‘dokwon.ust’ instead of ‘terra1...whez

null 12 Nov 23, 2022