Scope

The following contracts are considered in scope for this audit. Here is the codebase for the audit, note that it includes some contracts outside of scope for helpful reference and for the testing suite to work.

Contracts in-scope destinations
contracts/RubiconMarket.sol
contracts/BathHouseV2.sol
contracts/V2Migrator.sol
contracts/periphery/BathBuddy.sol
contracts/utilities/poolsUtility/Position.sol
contracts/utilities/FeeWrapper.sol

SLOC for contracts in-scope

Contract SLOC Purpose Libraries used
RubiconMarket 888 Main order-book logic @openzeppelin/*
BathHouseV2 89 Management of the BathTokens and BathBuddies @openzeppelin/*
V2Migrator 30 v1-v2 LPs migration @openzeppelin/*
BathBuddy 143 Rewards distribution for LPs @openzeppelin/*
Position 360 Creation of leveraged positions @openzeppelin/*
FeeWrapper 67 Adding fees via 3rd party protocols @openzeppelin/*

Total nSLOC: 1577 - calculated with this plugin.

Overview

Rubicon v2 is the next generation of the Rubicon protocol, which has been live on Optimism for over a year. Try out our app, learn more about Rubicon, and read our whitepaper for added context. V2 overhauls the old Pools system, replacing it with a Compound V2 fork - leveraging over-collateralized lending/borrowing to enable cross-margin long/short trading on the protocol. The core of the protocol is RubiconMarket, an open order book contract that allows for limit and market orders for any arbitrary ERC20 trading pair of tokens. Paired with the new Pools system, we feel Rubicon v2 embodies two core primitives of the new financial era: the most efficient modality of exchange paired with a robust multi-collateral money market. Note that this protocol will be deployed on ETH L2 networks that are EVM equivalent, non-EVM L2s may require changes to the implementation.

Installation

gh repo clone RubiconDeFi/rubi-protocol-v2 # clone the repo
yarn install
yarn run test # run the test suite
yarn run compile # compile the smart contracts

Additional Context

Rubicon V2 is a new version of the Rubicon Protocol. The Rubicon Pools system has undergone the biggest changes - the previous ERC4626-based liquidity pools have been replaced with Compound’s cTokens. The main functionality of the RubiconMarket remains the same, but minor changes were made. These include the addition of a new maker fee (rebate), changes to the OfferInfo struct, as well as minor changes to the offer functionality itself. All new features are described in more detail in the next section.

We wrap all contracts in TransparentUpgradeableProxies for upgradeability. On Optimism Mainnet, we will upgrade our RubiconMarket and RubiconRouter to the new implementations. For the market contract, there is a storage collision consideration we are aware of (please see Acknowledged Risks below) and the Router will not modify storage when upgraded. Please feel free to sanity-check our approach here!

Contracts overview

RubiconMarket

Source Code:

rubi-protocol-v2/RubiconMarket.sol at master · RubiconDeFi/rubi-protocol-v2

This contract implements order-book logic for peer-to-peer trading of ERC-20 tokens and a matching engine. It is a derivative work of MakerDAO’s OasisDEX.

An order book is a list of buy and sell orders for an asset, sorted by price. This contract implements each ERC20/ERC20 order book as two double-linked sorted lists, one for the Buy-side and one for the Sell-side of the given market.