Try   HackMD

Using EIP-4337 in Production (Sweep.gg)

Problem

  • Placing a bet takes too long: 10-20 seconds
  • Individually claiming winning bets takes way too long: 10 seconds * number of bets

The main reason why it takes so long for these transactions are twofold:

  1. Placing a bet has two transactions, approving your USDB for spending, then going and spending that transaction. Permit2 would technically solve this problem, but integrating that is too much work
  2. We are sending each transaction and waiting for the transaction receipt, meaning that the transaction needs to be included in a block.

Solution

Ideally read this before continuing: https://metamask.io/news/latest/account-abstraction-past-present-future/

We are using the EIP-4337 flavor of account abstraction. Note, EIP-4337 is this overcomplicated mess of random infra and contracts hacked together since they didn't receive Vitalik's blessing to make protocol level changes. If you read these three articles, I promise you will know more about 4337 than all the VCs that invested into EIP-4337 startups

Total Read Time: 30 minutes

Architectural Differences

The biggest change to our product is that the user stores all of their funds and interacts with sweep via a smart contract deployed on-chain.

image

Previously, Privy created an externally owned account(similar to metamask, rainbow wallet) that held your funds and interacted with the sweep contracts.

Now, Privy uses that same EOA to sign transactions that originate from your smart contract wallet.

Benefits

  1. The smart contract wallet can batch multiple transactions together. There is no need to wait for them to sequentially execute anymore.
  2. We no longer need to send users gas, we can instead pay for all of our user's gas via EIP-4337 gas sponsorship.
  3. The wallets are programmable, meaning that in the future we could probably change stuff(though backwards compatibility will be extremely annoying)

Drawbacks

  1. Each transaction sent costs $0.01 USD(bundler costs) + the cost of gas if we choose to pay for users' gas
  2. EIP-4337 is not super easy to work with