Key Functions
The main entry points and functions of the Rubicon Market contract

Offer

1
function offer(uint pay_amt, ERC20 pay_gem, uint buy_amt, ERC20 buy_gem)
2
public returns (uint)
Copied!
The offer function is the primary function to place a new limit buy or limit sell order on the Rubicon market. This function takes a user's funds for a given ERC-20 pair and places them into the order book of the smart contract. When another user chooses to buy the order or the order is matched with another order, the offer will be filled and the trade executed by the Rubicon Market.
Parameter
Use
uint pay_amt
The quantity of the asset that the user is offering in wad
ERC20 pay_gem
The ERC-20 asset that the user is offering
uint buy_amt
The quantity of the asset that the user is hoping to exchange for in wad
ERC20 buy_gem
The asset the user is hoping to exchange for
[Optional] uint pos
The position in the sorted order book the user wants to place the order
[Optional] bool matching
Optional boolean that dictates whether or not the offer should be automatically matched if possible
It is important to note that the offer function has a few representations in the Rubicon market. Optionally, a user can add a pos or matching parameter. These allow the user to choose where in the sorted order book the offer should live and whether or not the offer should be subject to potential automatic matching of the order.

Buy

1
function buy(uint id, uint amount) public can_buy(id)
2
returns (bool)
Copied!
Parameter
Use
uint id
The id of the order the user wants to buy
uint amount
The wad quantity/portion of the order the user wants to buy
The buy function allows a user to buy a given order in the order book and ultimately calls super.buy() in the RubiconMarket.sol contract. Furthermore, the buy function will also result in the caller paying the trade fee (see fees).

Cancel

1
function cancel(uint id)
2
public
3
can_cancel(id)
4
returns (bool success)
Copied!
Parameter
Use
uint id
The id of the order the user wants to cancel
This function allows a user to cancel an offer and returns funds to the user. The modifier can_cancel checks to make sure that the caller owns the offer and the offer is active. Alternatively, the user can also use the kill routing function to achieve the same result and cancel their order at a given id.

Routing Functions

BuyAllAmount

1
function buyAllAmount(
2
ERC20 buy_gem,
3
uint256 buy_amt,
4
ERC20 pay_gem,
5
uint256 max_fill_amount
6
) external returns (uint256 fill_amt)
Copied!
Parameter
Use
uint id
The id of the order the user wants to cancel
This function allows a user to buy any amount of an asset (buy_gem) through multiple orders in the book. The function will keep buying through orders until the desired buy-amt is acquired.

Make

1
function make(ERC20 pay_gem, ERC20 buy_gem, uint128 pay_amt, uint128 buy_amt)
2
public
3
returns (bytes32)
Copied!
Parameter
Use
uint pay_amt
The quantity of the asset that the user is offering in wad
ERC20 pay_gem
The ERC-20 asset that the user is offering
uint buy_amt
The quantity of the asset that the user is hoping to exchange for in wad
ERC20 buy_gem
The asset the user is hoping to exchange for
This is simply a routing function that allows a user to easily make an offer through the make entry point. This will route a user to then create an offer.

Take

1
function take(bytes32 id, uint128 maxTakeAmount) public
Copied!
Parameter
Use
uint id
The id of the order the user wants to buy
uint maxTakeAmount
The wad quantity/portion of the order the user wants to buy
This is simply a routing function that allows a user to easily take an offer through the take entry point. This will route a user to then buy the offer.
Last modified 1mo ago
Copy link