pub struct Simulator { /* private fields */ }Available on
simulation only.Expand description
A simulator for actions.
Implementations§
Source§impl Simulator
impl Simulator
Sourcepub fn from_parts(
tokens: HashMap<Pubkey, TokenState>,
markets: HashMap<Pubkey, MarketModel>,
glvs: HashMap<Pubkey, GlvModel>,
vis: BTreeMap<Pubkey, VirtualInventoryModel>,
) -> Self
pub fn from_parts( tokens: HashMap<Pubkey, TokenState>, markets: HashMap<Pubkey, MarketModel>, glvs: HashMap<Pubkey, GlvModel>, vis: BTreeMap<Pubkey, VirtualInventoryModel>, ) -> Self
Create from parts.
Sourcepub fn get_market(&self, market_token: &Pubkey) -> Option<&MarketModel>
pub fn get_market(&self, market_token: &Pubkey) -> Option<&MarketModel>
Get market by its market token.
Sourcepub fn get_market_mut(
&mut self,
market_token: &Pubkey,
) -> Option<&mut MarketModel>
pub fn get_market_mut( &mut self, market_token: &Pubkey, ) -> Option<&mut MarketModel>
Get market mutably by its market token.
Sourcepub fn insert_price(
&mut self,
token: &Pubkey,
price: Arc<Price<u128>>,
) -> Result<&mut Self>
pub fn insert_price( &mut self, token: &Pubkey, price: Arc<Price<u128>>, ) -> Result<&mut Self>
Upsert the prices for the give token.
§Errors
Returns error if the token does not exist in the simulator.
Sourcepub fn get_prices(&self, meta: &MarketMeta) -> Option<Prices<u128>>
pub fn get_prices(&self, meta: &MarketMeta) -> Option<Prices<u128>>
Get prices for the given market meta.
Sourcepub fn get_glv_mut(&mut self, glv_token: &Pubkey) -> Option<&mut GlvModel>
pub fn get_glv_mut(&mut self, glv_token: &Pubkey) -> Option<&mut GlvModel>
Get GLV by GLV token address mutably.
Sourcepub fn insert_glv(&mut self, glv: GlvModel) -> Option<GlvModel>
pub fn insert_glv(&mut self, glv: GlvModel) -> Option<GlvModel>
Insert GLV model.
Sourcepub fn swap_along_path(
&mut self,
path: &[Pubkey],
source_token: &Pubkey,
amount: u128,
options: Option<SimulationOptions>,
) -> Result<SwapOutput>
pub fn swap_along_path( &mut self, path: &[Pubkey], source_token: &Pubkey, amount: u128, options: Option<SimulationOptions>, ) -> Result<SwapOutput>
Swap along the provided path.
§Arguments
path- The path of market tokens to swap alongsource_token- The source token to swap fromamount- The amount to swapoptions- Optional simulation options. IfNone, default options are used.
Sourcepub fn tokens(&self) -> impl Iterator<Item = (&Pubkey, &TokenState)>
pub fn tokens(&self) -> impl Iterator<Item = (&Pubkey, &TokenState)>
Get token states.
Sourcepub fn markets(&self) -> impl Iterator<Item = (&Pubkey, &MarketModel)>
pub fn markets(&self) -> impl Iterator<Item = (&Pubkey, &MarketModel)>
Get market states.
Sourcepub fn insert_vi(
&mut self,
vi_address: Pubkey,
vi: VirtualInventoryModel,
) -> Option<VirtualInventoryModel>
pub fn insert_vi( &mut self, vi_address: Pubkey, vi: VirtualInventoryModel, ) -> Option<VirtualInventoryModel>
Insert virtual inventory model.
Sourcepub fn get_vi(&self, vi_address: &Pubkey) -> Option<&VirtualInventoryModel>
pub fn get_vi(&self, vi_address: &Pubkey) -> Option<&VirtualInventoryModel>
Get virtual inventory model by address.
Sourcepub fn vis(&self) -> impl Iterator<Item = (&Pubkey, &VirtualInventoryModel)>
pub fn vis(&self) -> impl Iterator<Item = (&Pubkey, &VirtualInventoryModel)>
Get all virtual inventory states.
Sourcepub fn simulate_order<'a>(
&'a mut self,
kind: CreateOrderKind,
params: &'a CreateOrderParams,
collateral_or_swap_out_token: &'a Pubkey,
) -> OrderSimulationBuilderForSimulator<'a>
pub fn simulate_order<'a>( &'a mut self, kind: CreateOrderKind, params: &'a CreateOrderParams, collateral_or_swap_out_token: &'a Pubkey, ) -> OrderSimulationBuilderForSimulator<'a>
Create a builder for order simulation.
Sourcepub fn simulate_deposit<'a>(
&'a mut self,
market_token: &'a Pubkey,
params: &'a CreateDepositParams,
) -> DepositSimulationBuilderForSimulator<'a>
pub fn simulate_deposit<'a>( &'a mut self, market_token: &'a Pubkey, params: &'a CreateDepositParams, ) -> DepositSimulationBuilderForSimulator<'a>
Create a builder for deposit simulation.
Sourcepub fn simulate_withdrawal<'a>(
&'a mut self,
market_token: &'a Pubkey,
params: &'a CreateWithdrawalParams,
) -> WithdrawalSimulationBuilderForSimulator<'a>
pub fn simulate_withdrawal<'a>( &'a mut self, market_token: &'a Pubkey, params: &'a CreateWithdrawalParams, ) -> WithdrawalSimulationBuilderForSimulator<'a>
Create a builder for withdrawal simulation.
Sourcepub fn simulate_glv_deposit<'a>(
&'a mut self,
glv_token: &'a Pubkey,
market_token: &'a Pubkey,
params: &'a CreateGlvDepositParams,
) -> GlvDepositSimulationBuilderForSimulator<'a>
pub fn simulate_glv_deposit<'a>( &'a mut self, glv_token: &'a Pubkey, market_token: &'a Pubkey, params: &'a CreateGlvDepositParams, ) -> GlvDepositSimulationBuilderForSimulator<'a>
Create a builder for GLV deposit simulation.
Sourcepub fn simulate_glv_withdrawal<'a>(
&'a mut self,
glv_token: &'a Pubkey,
market_token: &'a Pubkey,
params: &'a CreateGlvWithdrawalParams,
) -> GlvWithdrawalSimulationBuilderForSimulator<'a>
pub fn simulate_glv_withdrawal<'a>( &'a mut self, glv_token: &'a Pubkey, market_token: &'a Pubkey, params: &'a CreateGlvWithdrawalParams, ) -> GlvWithdrawalSimulationBuilderForSimulator<'a>
Create a builder for GLV withdrawal simulation.
Sourcepub fn simulate_shift<'a>(
&'a mut self,
from_market_token: &'a Pubkey,
to_market_token: &'a Pubkey,
params: &'a CreateShiftParams,
) -> ShiftSimulationBuilderForSimulator<'a>
pub fn simulate_shift<'a>( &'a mut self, from_market_token: &'a Pubkey, to_market_token: &'a Pubkey, params: &'a CreateShiftParams, ) -> ShiftSimulationBuilderForSimulator<'a>
Create a builder for shift simulation.
Trait Implementations§
Source§impl From<Simulator> for JsSimulator
Available on crate feature js only.
impl From<Simulator> for JsSimulator
Available on crate feature
js only.Source§impl GlvCalculator for Simulator
impl GlvCalculator for Simulator
Source§fn get_glv_model(&self, glv_token: &Pubkey) -> Option<&GlvModel>
fn get_glv_model(&self, glv_token: &Pubkey) -> Option<&GlvModel>
Returns
GlvModel corresponding to the given GLV token.Source§fn get_market_token_value_in_glv(
&self,
glv_token: &Pubkey,
market_token: &Pubkey,
maximize: bool,
) -> Result<u128>
fn get_market_token_value_in_glv( &self, glv_token: &Pubkey, market_token: &Pubkey, maximize: bool, ) -> Result<u128>
Calcualtes the market token value in GLV.
Source§fn get_glv_value(&self, glv_token: &Pubkey, maximize: bool) -> Result<u128>
fn get_glv_value(&self, glv_token: &Pubkey, maximize: bool) -> Result<u128>
Calculates the total value of the given GLV.
Source§fn get_glv_token_value(
&self,
glv_token: &Pubkey,
amount: u64,
maximize: bool,
) -> Result<u128>
fn get_glv_token_value( &self, glv_token: &Pubkey, amount: u64, maximize: bool, ) -> Result<u128>
Calculates the underlying value represented by the given amount of a GLV token.
Source§fn get_max_sellable_glv_value_for_market_token(
&self,
glv_token: &Pubkey,
market_token: &Pubkey,
) -> Result<u128>
fn get_max_sellable_glv_value_for_market_token( &self, glv_token: &Pubkey, market_token: &Pubkey, ) -> Result<u128>
Calculates the maximum sellable value through the given market within the given GLV.
Source§impl MarketCalculator for Simulator
impl MarketCalculator for Simulator
Source§fn get_market_model(&self, market_token: &Pubkey) -> Option<&MarketModel>
fn get_market_model(&self, market_token: &Pubkey) -> Option<&MarketModel>
Returns
MarketModel corresponding to the given market token.Source§fn get_token_price(&self, token: &Pubkey) -> Option<Price<u128>>
fn get_token_price(&self, token: &Pubkey) -> Option<Price<u128>>
Returns
Price corresponding to the given token address.Source§fn get_token_prices_for_market_meta(
&self,
meta: &MarketMeta,
) -> Option<Prices<u128>>
fn get_token_prices_for_market_meta( &self, meta: &MarketMeta, ) -> Option<Prices<u128>>
Returns
Prices corresponding to the given MarketMeta.Source§fn get_market_model_with_prices(
&self,
market_token: &Pubkey,
) -> Result<(&MarketModel, Prices<u128>)>
fn get_market_model_with_prices( &self, market_token: &Pubkey, ) -> Result<(&MarketModel, Prices<u128>)>
Returns
MarketModel and Prices corresponding to the given market token.Auto Trait Implementations§
impl Freeze for Simulator
impl RefUnwindSafe for Simulator
impl Send for Simulator
impl Sync for Simulator
impl Unpin for Simulator
impl UnwindSafe for Simulator
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more