The technical challenges of our AMMs (and how we overcame them)
In retrospect, building on StarkEx presented a number of challenges that weren’t evident at the outset of the project.
StarkEx is designed for high-performance trading. By giving up some of the flexibility of a Turing-complete virtual machine (which is available on StarkNet but not StarkEx), we instead gain the potential for higher throughput and lower cost per transaction.
We determined early on in 2021 that it was indeed technically possible to build AMMs over StarkEx. One of the major benefits of doing so would be to combine the AMM liquidity with existing order-book liquidity, and route users’ orders to get the best price from both sources.
What we underestimated was the level of complexity involved in doing so.
In total the project took over a year to complete. Time and again we butted the limits of what we could do with StarkEx, requiring multiple upgrades of the smart contracts and proving system to deliver the final result.
The main technical components are as follows:
- A forked Uniswap V2 solidity smart contract system, upgraded to connect with the StarkEx bridge.
- A smart contract transpiler to C++, which feeds into rhino.fi’s off-chain matching engine.
- All the AMM operations (supply liquidity, remove liquidity, and swap) replicated on StarkEx using limit orders.
- A complicated syncing process between L2 and L1, which ensures that the state of each AMM pool on L1 always matches the pool’s state on StarkEx at the point of proofs being submitted.
The system was audited by Peckshield and heavily tested. The longest period of public mainnet testing lasted six months (yep, six whole months!), with six pools available for trading but with whitelisted liquidity provision, and without the syncing process to L1.
As a result of this long, long period of testing, we have high confidence in the robustness of the solution.
As always, if rhino.fi were to go offline as an operator of StarkEx, users would be able to exit their funds back to L1 and withdraw from the AMM pools, giving the ultimate guarantee of trustlessness.