Rubicon Router
Contract source code (opens in a new tab)
RubiconRouter is a high-level helper contract for interacting with Rubicon Classic. It wraps lower-level RubiconMarket operations with convenience functions for swaps, multihop routes, native ETH flows, and order book reads.
Swap Functions
swap()
function swap(
uint256 pay_amt,
uint256 buy_amt_min,
address[] memory route,
address to
) public returns (uint256)Swaps pay_amt of the first token in route for at least buy_amt_min of the final token in route.
| Parameter | Type | Description |
|---|---|---|
pay_amt | uint256 | Quantity of tokens sold. |
buy_amt_min | uint256 | Minimum quantity received of the final route token. |
route | address[] | Token route. First address is input token, final address is output token. |
to | address | Recipient address. |
multiswap()
function multiswap(
address[][] memory routes,
uint256[] memory pay_amts,
uint256[] memory buy_amts_min,
address to
) publicSwaps across multiple routes in one transaction.
ETH Helpers
function swapWithETH(
uint256 pay_amt,
uint256 buy_amt_min,
address[] calldata route,
address to
) external payable returns (uint256)function swapForETH(
uint256 pay_amt,
uint256 buy_amt_min,
address[] calldata route
) external returns (uint256 fill)swapWithETH() swaps native ETH into an ERC-20 route. swapForETH() swaps an ERC-20 into native ETH. Routes should use WETH at the ETH side of the path.
Exact Amount ETH Helpers
function buyAllAmountWithETH(
IERC20 buy_gem,
uint256 buy_amt,
uint256 max_fill_amount
) external payable returns (uint256 fill)function sellAllAmountWithETH(
uint256 pay_amt,
IERC20 buy_gem,
uint256 min_fill_amount
) external payable returns (uint256 fill)These functions support exact buy and exact sell flows using native ETH.
View Functions
getExpectedSwapFill()
function getExpectedSwapFill(
uint256 pay_amt,
uint256 buy_amt_min,
address[] calldata route
) public view returns (uint256 currentAmount)Returns the expected output for a swap() route.
getExpectedMultiswapFill()
function getExpectedMultiswapFill(
uint256[] memory pay_amts,
uint256[] memory buy_amt_mins,
address[][] memory routes
) public view returns (uint256 outputAmount)Returns the expected output for a multiswap() call.
getBookFromPair()
function getBookFromPair(
IERC20 asset,
IERC20 quote
) public view returns (uint256[3][] memory asks, uint256[3][] memory bids)Returns outstanding asks and bids for a token pair. Pair ordering matters: for example, (WETH, USDC) returns WETH asks and USDC bids.
getOffersFromPair()
function getOffersFromPair(
IERC20 tokenIn,
IERC20 tokenOut
) public view returns (uint256[3][] memory offers)Returns offers for one side of the specified book.
getBookDepth()
function getBookDepth(
IERC20 tokenIn,
IERC20 tokenOut
) public view returns (uint256 depth, uint256 bestOfferID)Returns order book depth and the best offer ID for one side of the book.
getOfferIDsFromPair()
function getOfferIDsFromPair(
IERC20 tokenIn,
IERC20 tokenOut
) public view returns (uint256[] memory IDs)Returns offer IDs for a token pair.