Struct rubi::session::RubiconSession
source · pub struct RubiconSession<M: Middleware + Clone + 'static> { /* private fields */ }
Expand description
RubiconSession
wraps up all of the basic contracts that the protocol uses into one convenient struct.
It provides all of the basic functions you would need to tracsact with the protocol. All of the view/pure functions are async,
and will return the expected value. All of the mutating functions are sync, and will return a ContractCall.send()
method.
Implementations
sourceimpl<M: Middleware + Clone + 'static> RubiconSession<M>
impl<M: Middleware + Clone + 'static> RubiconSession<M>
- impl<M: Middleware + Clone + ’static> RubiconSession
where ::Provider: PubsubClient,
sourcepub fn new_mainnet(client: M) -> Self
pub fn new_mainnet(client: M) -> Self
Creates a new RubiconSession
configured to Optimism Mainnet.
sourcepub fn new_kovan(client: M) -> Self
pub fn new_kovan(client: M) -> Self
Creates a new RubiconSession
configured to Optimism Kovan. OP Kovan is now considered obsolete.
This requires that the aid
feature is not set - the Market Aid contract is not deployed on OP Kovan.
sourcepub fn new_goerli(client: M) -> Self
pub fn new_goerli(client: M) -> Self
Creates a new RubiconSession
configured to Optimism Goerli.
This requires that the aid
feature is not set - the Market Aid contract is not deployed on OP Goerli.
sourcepub fn bath_house(&self) -> &Contract<M>
pub fn bath_house(&self) -> &Contract<M>
Returns a reference to the BathHouse contract.
sourcepub fn get_address(&self) -> Option<Address>
pub fn get_address(&self) -> Option<Address>
Address associated with the current middleware, if it exists.
sourcepub fn is_legacy(&self) -> bool
pub fn is_legacy(&self) -> bool
Are we on a legacy chain (pre EIP-1559)? If so, we have to use legacy TX calls…
sourcepub fn local_asset(&self, asset: Asset, size: U256) -> Result<ChainNativeAsset>
pub fn local_asset(&self, asset: Asset, size: U256) -> Result<ChainNativeAsset>
Returns a ChainNativeAsset
localized to the current chain.
sourcepub fn local_zero_asset(&self, asset: Asset) -> Result<ChainNativeAsset>
pub fn local_zero_asset(&self, asset: Asset) -> Result<ChainNativeAsset>
Returns a ChainNativeAsset
localized to the current chain, with size equal to zero.
sourcepub fn local_max_asset(&self, asset: Asset) -> Result<ChainNativeAsset>
pub fn local_max_asset(&self, asset: Asset) -> Result<ChainNativeAsset>
Returns a ChainNativeAsset
localized to the current chain, with size equal to 2^256-1.
sourcepub fn local_asset_human_decimal(
&self,
asset: Asset,
human_size: Decimal
) -> Result<ChainNativeAsset>
pub fn local_asset_human_decimal(
&self,
asset: Asset,
human_size: Decimal
) -> Result<ChainNativeAsset>
Returns a ChainNativeAsset
localized to the current chain. human_size
is human readable, and is converted to wei behind the scenes.
sourcepub fn local_asset_string<T: ToString>(
&self,
asset: Asset,
human_size: &T
) -> Result<ChainNativeAsset>
pub fn local_asset_string<T: ToString>(
&self,
asset: Asset,
human_size: &T
) -> Result<ChainNativeAsset>
Returns a ChainNativeAsset
localized to the current chain. human_size
is human readable, and is converted to wei behind the scenes.
sourcepub async fn self_is_approved_strategist(&self) -> Result<bool>
pub async fn self_is_approved_strategist(&self) -> Result<bool>
Strategists have to be approved by the Rubicon protocol before they can place market making trades with pooled funds. This function returns true if the current middleware is an approved strategist.
sourcepub async fn is_approved_strategist(&self, addr: Address) -> Result<bool>
pub async fn is_approved_strategist(&self, addr: Address) -> Result<bool>
Strategists have to be approved by the Rubicon protocol before they can place market making trades with pooled funds. This function returns true if the supplied address is an approved strategist.
sourceimpl<M: Middleware + Clone + 'static, S: Clone + Signer> RubiconSession<SignerMiddleware<M, S>>
impl<M: Middleware + Clone + 'static, S: Clone + Signer> RubiconSession<SignerMiddleware<M, S>>
sourcepub fn buy_all_amount(
&self,
buy_gem: Address,
buy_amt: U256,
pay_gem: Address,
max_fill_amount: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn buy_all_amount(
&self,
buy_gem: Address,
buy_amt: U256,
pay_gem: Address,
max_fill_amount: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This is a market buy, where we spend no more than max_fill_amount to buy buy_amt the returned value is the fill amount
sourcepub fn sell_all_amount(
&self,
pay_gem: Address,
pay_amt: U256,
buy_gem: Address,
min_fill_amount: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn sell_all_amount(
&self,
pay_gem: Address,
pay_amt: U256,
buy_gem: Address,
min_fill_amount: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This is a market sell, where we spend pay_amt to buy as much as possible of buy_gem (and we get at least min_fill_amount) the returned value is the filled amount
sourcepub fn market_sell(
&self,
source: &ChainNativeAsset,
target: &Asset
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn market_sell(
&self,
source: &ChainNativeAsset,
target: &Asset
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This represents a market sell, where we sell the source.size()
worth of source.asset()
in exchange for some undetermined amount target
sourcepub fn market_buy(
&self,
source: &Asset,
target: &ChainNativeAsset
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn market_buy(
&self,
source: &Asset,
target: &ChainNativeAsset
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This represents a market sell, where we sell the source.size()
worth of source.asset()
in exchange for some undetermined amount target
sourcepub fn offer(
&self,
pay_amt: U256,
pay_gem: Address,
buy_amt: U256,
buy_gem: Address,
pos: Option<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn offer(
&self,
pay_amt: U256,
pay_gem: Address,
buy_amt: U256,
buy_gem: Address,
pos: Option<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This is used to construct a limit order, where we want to sell pay_amt
of pay_gem
for at least buy_amt
of buy_gem
.
The pos
parameter should be None
unless you know the new position of the order in the sorted orderbook.
pay_gem
and buy_gem
must not be equal.
sourcepub fn limit_order_bins(
&self,
source: &ChainNativeAsset,
target: &ChainNativeAsset
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn limit_order_bins(
&self,
source: &ChainNativeAsset,
target: &ChainNativeAsset
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This constructs a limit order transaction.
We want to sell source.size()
of source.asset()
for at least target.size()
of target.asset()
.
source.asset()
and target.asset()
must not be equal.
sourcepub fn limit_sell(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
base_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn limit_sell(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
base_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This constructs a limit order transaction.
We sell base_size
worth of base
for quote
, at a price greater than or equal to price
.
price
has units quote/base
. Both price
and base_size
are in human readable units, not wei.
base
and quote
must not be equal.
sourcepub fn limit_buy(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
base_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn limit_buy(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
base_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This constructs a limit order transaction.
We buy base_size
worth of base
for quote
, at a price less than or equal to price
.
price
has units quote/base
. Both price
and base_size
are in human readable units, not wei.
base
and quote
must not be equal.
sourcepub fn conj_limit_sell(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
quote_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn conj_limit_sell(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
quote_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This constructs a limit order transaction.
We want to sell quute_size
worth of quote
for base
, at a price greater than or equal to price
.
price
has units quote/base
. Both price
and quote_size
are in human readable units, not wei.
base
and quote
must not be equal.
sourcepub fn conj_limit_buy(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
quote_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn conj_limit_buy(
&self,
base: &Asset,
quote: &Asset,
price: Decimal,
quote_size: Decimal
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
This constructs a limit order transaction.
We want to buy quute_size
worth of quote
for base
, at a price less than or equal to price
.
price
has units quote/base
. Both price
and quote_size
are in human readable units, not wei.
base
and quote
must not be equal.
sourcepub fn cancel(
&self,
order_id: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
pub fn cancel(
&self,
order_id: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, U256>>
Cancels an order that’s already on the Rubicon book
sourcepub fn place_market_making_trades(
&self,
token_pair: [Address; 2],
ask_num: U256,
ask_den: U256,
bid_num: U256,
bid_den: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
pub fn place_market_making_trades(
&self,
token_pair: [Address; 2],
ask_num: U256,
ask_den: U256,
bid_num: U256,
bid_den: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
This is used to place a strategist trade on the market.
Trades are placed in pairs - a bid and an ask.
ask_num
and ask_den
are the numerator and denominator of the ask price, respectively. The same is true of the bid.
token_pair
is of the form [base, quote], where base != quote
.
sourcepub fn batch_place_market_making_trades(
&self,
token_pair: [Address; 2],
ask_nums: Vec<U256>,
ask_dems: Vec<U256>,
bid_nums: Vec<U256>,
bid_dems: Vec<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
pub fn batch_place_market_making_trades(
&self,
token_pair: [Address; 2],
ask_nums: Vec<U256>,
ask_dems: Vec<U256>,
bid_nums: Vec<U256>,
bid_dems: Vec<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
This returns a ContractCall
that will place a series of paired market making trades.
sourcepub fn requote_offers(
&self,
order_id: U256,
token_pair: [Address; 2],
ask_num: U256,
ask_dem: U256,
bid_num: U256,
bid_dem: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
pub fn requote_offers(
&self,
order_id: U256,
token_pair: [Address; 2],
ask_num: U256,
ask_dem: U256,
bid_num: U256,
bid_dem: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
This returns a ContractCall
that requotes the given pair of orders.
sourcepub fn batch_requote_offers(
&self,
ids: Vec<U256>,
token_pair: [Address; 2],
ask_nums: Vec<U256>,
ask_dems: Vec<U256>,
bid_nums: Vec<U256>,
bid_dems: Vec<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
pub fn batch_requote_offers(
&self,
ids: Vec<U256>,
token_pair: [Address; 2],
ask_nums: Vec<U256>,
ask_dems: Vec<U256>,
bid_nums: Vec<U256>,
bid_dems: Vec<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
This returns a ContractCall
that requotes a series of paired strategist orders.
sourcepub fn scrub_strategist_trade(
&self,
trade_id: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
pub fn scrub_strategist_trade(
&self,
trade_id: U256
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
This returns a ContractCall
that cancels an outstanding strategist orders.
sourcepub fn scrub_strategist_trades(
&self,
trade_ids: Vec<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
pub fn scrub_strategist_trades(
&self,
trade_ids: Vec<U256>
) -> Result<ContractCall<SignerMiddleware<M, S>, ()>>
This returns a ContractCall
that cancels a list of outstanding strategist orders.