OUR INSIGHTS

Helping Platypus stay arbitrage-free

Decentralised Exchanges (DEXs) have captured an increasingly large share of daily trading volume in crypto. This makes the Automated Market Makers (AMMs) that underpin them, one of the most important pieces of De-Fi infrastructure. Haruko’s quantitative research team undertook a project to review the mathematical mechanics of several prominent AMMs.

Many established AMMs, such as UniSwap, Curve and Balancer, use an “invariant-based” approach to link token prices and liquidity in a pool. As swaps change liquidity, prices are automatically adjusted according to a model that only updates when deposits or withdrawals are made. This requires a DEX to partition liquidity into separate pools, giving rise to “liquidity fragmentation” — BTC in the BTC/ETH pool cannot be used in the BTC/USDC pool, despite being on the same DEX.

Platypus provides a novel alternative approach based on “one sided liquidity”. The role of a token in a swap is determined by a “marginal slippage function” depending only on that token’s liquidity across the DEX. The rich general framework of Platypus has significant potential for the community to create future AMMs tailored to new use-cases as they are identified.

A novel feature of Platypus is that negative slippage occurs for swaps that produce a net improvement of the pool’s coverages — the ratio of the pool’s assets to liabilities for a token. A trader will receive a small increase in net value in such instances, rather than a net decrease for other swaps.

Useful as it is, this framework requires arbitrage protection to be explicitly added. The technical paper acknowledges this and Platypus charges penalties for depositing already over-covered tokens or withdrawing under-covered tokens, as these actions decrease coverage. Deposits or withdrawals are otherwise penalty-free.

During the review of the Platypus technical paper, Haruko identified a gap in the arbitrage protection as implemented. Given a first, over-covered, token and a second, arbitrary, token one could:

1. Use the second token to buy enough of the first token to reduce the coverage to just below 1

2. Deposit a large amount of the first token — this is now penalty free

3. Use the first token to buy back exactly the amount of the second token spent in Step 1, pushing the first token’s coverage back above 1

4. Withdraw the original amount of the first token deposited — this is also penalty-free

The trader doing the above arbitrage, would net receive a small amount of the first token risk-free.

Arbitrage Example: Initial coverage ratios for the two tokens are 1.1 and 0.9. 1,000 units of first token are used in the arbitrage procedure resulting in profit of 0.04 units of first token.

Based on the technical paper, Haruko implemented a simulator of the Platypus exchange. It confirmed that, in the absence of any other fees, for every 1 million tokens swapped approximately 1 token of value could be arbitraged out. As long as a token remains over-covered further arbitrage is possible.

Fortunately, Platypus has been protected from arbitrage by the 0.01% StableSwap fee charged on all swaps. Haruko determined that if this was lowered by 0.33 basis points, arbitrage would be possible.

Haruko reached out to the Platypus development team and provided significant documentation of the mathematical origin and numerical behaviour of the protection failure. Platypus corroborated its existence and their intention to remove the arbitrage attack vector.

If you would like to download the paper, you can do so here.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.