Pooled Arbitrage

This is a draft. Expect lots of changes.

Please excuse the simplicity of this page. I am an infrastructure and developer experience engineer, not a designer.

Suggestions, no matter how technical or how mundane, are welcome. Message me on Twitter.

I'm building a website that allows risk-free profits. It isn't done yet, but what will this actually look like for, you, the ether holding user?

  1. You visit the Pooled Arbitrage website, click the "deposit ETH" button, enter an amount, and approve a Ethereum transaction.
  2. When the transaction confirms, you will have an equivalent amount of arbtokens (ARB-V1-ETH).
  3. Arbitrage traders (just me to start) scan many exchanges and aggregators for all orders and their fees.
  4. When orders that form a profitable arbitrage trade are found, the arbitrage trader creates a transaction that sends the orders to the Pooled Arbitrage contract. If the transaction confirms successfuly (the hopefully likely scenario), this transaction borrows some token from the pool, makes some trades, and then returns everything to the pool. But if someone else takes part of the trade before we can, then no money is taken from the pool and I am only out a little bit of gas money. A failed trade costs you nothing and only costs the trader a little bit of gas money.
  5. Every successful trade starting with ETH increases the value of your ARB-V1-ETH.
  6. You return your ARB-V1-ETH and get back more ETH that you started with!

"Arbtokens" are similar to Uniswap's UNI-V1s or Compound's cTokens. These ERC20-compatible tokens can be safely placed into cold-storage or even traded. An arbtoken's value in the underlying token can never go down. An arbtoken's value will grow whenever an arbitrage trade starts with their underlying token.

I expect ether to be the most commonly traded token, but you will be able to deposit any ERC-20 token.

Deposits can only be withdrawn by returning the proper arbtokens (ARB-V1-ETH for ETH, ARB-V1-cDAI for cDAI, etc.). No one has the ability to withdraw anyone else's tokens.

No account sign-up is necessary. There are no limits on deposits or withdrawals.

Why?

Trading on custodial exchanges always comes with certain risks; The most concerning being hackers or malicious owners running away with everyone’s money. Additionally, most all trading strategies are essentially guesses about what the price will be in the future and so there is a chance they will be wrong and lose money.

Several technologies are now available that remove or at least minimize these risks enough for me to be interested in trading again.

  1. Non-custodial exchanges and exchange aggregators
  2. Smart contracts that allow a single transaction to atomically fill multiple trades (atomic arbitrage)
  3. Borrowing and returning funds within a single transaction (flash lending)

Atomic trading across multiple exchanges allows for nearly-risk-free* arbitrage profits. Combining that with flash lending is what I think is really exciting. With my design, people with tokens but without the desire or skill to trade can earn profits on arbitrage trades done by other people.

* The only risk in arbitrage trading is that someone else gets the trade before we do. This can be someone intentionally paying more gas than us, or it might just be someone wanting the same trade as us at the same time. With non-atomic arbitrage, this is really bad since we could get stuck part way through a circle and end up with some tokens that we don't want. Atomic arbitrage has the really great protection that, if someone beats us to one of the trades, none of our trades happen and only a small miner fee for the reverted transaction is paid.

FAQ

Q. How did this start?

The main goal of this project was to learn Solidity and Rust. I've already learned a lot.

The pooling part of the project started when I wanted to figure out a way to keep my trading funds safe from hackers. Moving to non-custodial exchanges protects me from the exchange getting hacked, but someone could still hack into the server running my trading bot. Smart contracts help protect me here. Now if someone hacks into my server, they can only steal my gas money.

Often when I told someone about my arbitrage trading plans, they asked how they could invest. I'm not comfortable taking traditional investments. But using people's funds in a non-custodial way was too interesting to me to not investigate. I started looking at how uniswap and compound set exchange rates for their tokens and realized that I could open deposits up to anyone if I used a similar mechanism, and it was a simple change to allow anyone to deposit into my smart contract instead of just me.

Q. What problems do you forsee?

The biggest problem is that I don't actually need a large amount of capital. Once I have enough to cover a single trade, I don't really need any more. Any further deposits only spread out the profits without adding anything positive. And worse of all, one rich person could deposit so many tokens that they get the vast majority of the profits and leave it unprofitable for me to keep submitting trades.

Small traders might also prefer to keep competing since they get 100% of the trades rather than a small amount of the pool's trades.

So this doesn't appear to reduce competition like I had first hoped. Please, let me know if you see some way to prevent these problems. So far my only idea to stop whales is adding a small percentage deposit fee, but that might push smaller traders away.

Q. Who are your expected customers?

Two main groups have my initial focus:

  1. Other arbitrage traders who are tired of the gas race and front running
  2. People with spare tokens

What tokens will you support?

To ensure compatibility with future projects, the contract is capable of receiving deposits in any ERC-20 token. But because of how arbitrage trading works, I think I'm going to have to focus on one main token at a time.

I'm currently deciding between focusing on either ether, cDAI, or UNI-V1-cDAI. I may cycle between them depending on how the market is doing. I'm definitely looking for feedback here.

Deposits in cDAI bring with them the risks of Compound, but they also pay interest.

Deposits in UNI-V1-cDAI bring the risks of both Compound and Uniswap, but they also pay interest and trading fees. Pooling ETH and cDAI at the same time sounds really powerful to me.

Q. What outcome do you expect if this is successful?

Q. What are the potential profits or returns?

Bloxy has some great historical data, but no one can predict the future. There are just so many factors. What is for sure is that so long as Uniswap is popular, there will be arbitrage opportunities available.

How do I invest?

You can't yet. This is mostly just ideas still.

Once the arbitrage finding code is done, smart contracts are audited and deployed, a name is purchased on ENS, and a web3 website is launched, you will be able to participate with just a few clicks.

Q. What about Know Your Customer (KYC)?

I'm not sure yet, but I'm starting to talk to California lawyers and tax attorneys now.

I'm not really interested in building a limited platform.

If the lawyers are unhappy with deposits and withdrawals being open, they might be limited to people who have completed some sort of KYC/AML compliance. It's also possible the lawyers will require setting account limits. Platforms like Civic and ZAP Tech may help here. But again, I really want this system to be as open as possble.

Q. How is this monetized?

I'm still thinking about that. At a minimum, I will have some of my own tokens deposited.

I'm also thinking of taking a small percentage of the initial deposit.

Q. How does Compound work?

You deposit a token. You get cToken back at an exchange rate that represents your percent ownership of the pool of tokens.

Other people can borrow from the pool of tokens and pay interest for it back to the pool. To reduce risk, these people must provide collateral in other tokens in order to do this. If the value of their collateral doesn't match the value of their debt, their collateral might be sold to cover the gap.

If you don't borrow, you don't have to worry about your tokens being sold. Though there is risk that the market collapses and the loan is repaid with the worthless tokens. But if that happens, you would have lost your value anyways.

So long as there is token available in the pool, you can trade your cToken in and withdraw the original underlying token. There is a risk here that all the tokens in the pool are being borrowed and withdrawls are blocked, but that will also mean you are earning maximum interest on your deposit.

There are multiple competitors to Compound that all provide roughly the same functionality. There are also smart contracts that automatically move between them all to get the best rates. All of these should be compatible with the arbitrage pool.

Q. What is flash lending?

Flash lending is borrowing funds and then returning them inside a single transaction. You don't need to prove credit-worthiness, or post collateral because the smart contract guarantees the amount borrowed from the lender is returned.

It's possible to have a flash lending system where all the profits go to the arbitrage finder and no profits go to the pool (or anything in-between), but I think everything going to the pool makes the most sense for now. If an arbitrage trader wants profit, they should add collateral. I am definitely open to conversation about finding a fair split.

Q. What have I done so far?

I wrote some code that connects to a few exchanges and then does a bunch of math to find the best arbitrage opportunities. It is currently checking the prices on over 600 Ethereum tokens. It could be faster, but it mostly works. Right now it just prints found opportunities to my terminal, but I want to send them to a smart contract like I've described above.

I currently support Kyber, Uniswap, ZRX Mesh V3, the WETH wrapping contract, and Compound. I am half done adding support for the Synthetix Arbitrage Rewarder contract on-top of Uniswap. Adding more exchanges is relatively simple, though I'm only interested in non-custodial decentralized exchanges that support atomic arbitrage. Non-atomic arbitrage can definitely be profitable, but is not compatible with the way trades on the Arbitrage Pool contract work.

I wrote some solidity and got a basic arbitrage trade working in a development environment, but nothing on mainnet. This quick and dirty contract code is also fully custodial and has no associated arbtokens.

Q. What more do I need?

To finish the smart contract that can trade against a bunch of exchanges. I have a wrapper contract for Uniswap and 0x, but I am not super happy with them. It looks like Kyber and 0x both have plans for there own versions of this and I'm sure others do to.

A smart contract for depositing and withdrawing tokens for arbtokens. This is pretty standard ERC-20 stuff. I am open to using a different standard though.

To finish the smart contract that ensures balances increase after trades are finished. It needs to be updated to the latest versions of everything and none of it audited. I have parts of this, but it needs an update to the latest solidity, some more work, and an audit.

Software to sign a transaction at several fee levels and broadcast them at set intervals if they don't confirm or if someone else broadcasts a conflicting transaction. It should also be able to replace or cancel transactions.

A website for users to track their deposits and earnings. We all love watching graphs that go up and to the right.

A dashboard for viewing all arbitrage trades on the network, not just the ones we are able to fill. I saw a site that did this, but I've lost the link somewhere in my notes.

For people to point out flaws in my design or incentives. I want people to prefer to pool funds rather than outbid each other on gas, but I'm not sure this fully accomplishes that.

More questions for this FAQ. I've been involved with cryptocurrency for a long while now and so things that are clear to me are likely completely alien to you. Please let me know what terms and concepts you need explanations of.

Probably lots more stuff.

Q. What does "custodial exchange" mean?

... TODO: answer ...

Q. What does "atomic trading" mean?

... TODO: answer ...

Q. What does "fungible" mean?

... TODO: answer ...

Other Thoughts

I'm not interested in rent-seeking. I'm interested in building things like Uniswap that pay fees to people that deserve them. This platform won't have any extraneous fees. I plan to make money off crypto being successful.

I'm not afraid of someone "stealing" this idea. I just want this thing to exist. Arbitrage traders are needed to set market prices on exchanges like Uniswap and so I think there will always be demand for something like this. I don't need this pool to be to be smart contract code that I wrote. If someone else builds this, I will probably just deposit my tokens with them and contribute to their code. I'm more concerned with lawyers saying I can't participate in this at all. If you want to build this (with or without me), please talk to me.

Arbitrage trades enrich the person that combines the orders. The Pooled Arbitrage contract spreads that gain across the whole pool. I think this is an improvement over racing to pay the most gas, but I still think systems like loopring that return these gains to the relevant traders might be a better user experience.

Because only one person can fill a trade, arbitrage traders are forced to front-run/race. I am hoping that arbitrage traders will stop racing in favor of having a share of the profits, but I don't think this is a perfect replacement. I am open to additional incentives.

There are no bonuses for being an arbitrage trader on the Pool contract, and they have to pay their own gas. Adding an incentive here would bring back an incentive for front-running. I am open to suggestions. I would love to re-imburse gas, but that brings in problems, too.

Ether is the main coin traded on the decentralized exchanges that I'm currently looking at and so it is likely to have an arbitrage opportunity available often. What's interesting is that the arbitrage detection code looks for opportunities involving Compound's cTokens. That way users can deposit cTokens into the Pooled Arbitrage contract and earn interest on compound and also get gains from arbitrage trades. These trades are less common or require more hops compared to trades in ether, but I am still excited about this potential.

I will open source my arbitrage finding code eventually. It is written in Rust.

I am currently planning on having the arbtokens be ERC20-compatible, but there are several possible standards now. This idea is generic enough to work on any blockchain that has multiple exchanges and atomic transactions. For now, I'm developing on Ethereum.

Gains only happen if the token is the starting/ending point for an arbitrage trade. If you deposit a token that's never used, it won't ever grow.

So far, Ethereum 2.0's sharding causes some problems with my design.

I think it is possible for a malicious arbitrage trader to make an exchange proxy contract that returns more than it started with for a trade, but keeps the rest for itself. I'm not sure the best way to stop this. I think adding delays to contracts being usable like Compound does should be sufficient.

Should the smart contracts be written in Solidity or Vyper?

If someone hacks into the server running my bot, they can only steal my gas money. No user funds are at risk from a hack like this.

The only risk to user funds would be a bug in the contract, but that's true of all smart contracts and not specific to my design.

I want all fees and all risks to be very clear (even if they aren't created by me).

I want to think a lot more about how depositing UNI-V1 tokens into the arbitrage pool and then trading on uniswap effects fees.

The arbitrage pool website will be hosted on IPFS with an immutable ENS name. This means that once the page is published, no one can change it. It can be audited and declared safe and no malicious people will be able to modify it. Updates will be on a new subdomain. While this is different than how most people are used to using websites, it should be more secure.

For v1, trading will be limited to approved accounts run by me. This will limit any damage done by contract bugs. If there were, for example, a bug that allowed an attacker to withdraw funds by tricking the trade function, then only I would be able to exploit it. And if I exploit it, you can sue me for theft. If some random address exploits it, then there would be no recourse for anyone. I absolutely want to eventually have an open protocol if possible. For now, we have the legal system to fallback on. I have doubts that a DAO would solve this.

I could setup a mailing list if people are interested in staying up-to-date. Let me know if you would like this.

I think the term "front-running" is sometimes used when it shoouldn't be. I'll be writing a longer post about this.

Links