Skip to main content

Simulator

Struct Simulator 

Source
pub struct Simulator { /* private fields */ }
Available on simulation only.
Expand description

A simulator for actions.

Implementations§

Source§

impl Simulator

Source

pub fn from_parts( tokens: HashMap<Pubkey, TokenState>, markets: HashMap<Pubkey, MarketModel>, glvs: HashMap<Pubkey, GlvModel>, vis: BTreeMap<Pubkey, VirtualInventoryModel>, ) -> Self

Create from parts.

Source

pub fn get_market(&self, market_token: &Pubkey) -> Option<&MarketModel>

Get market by its market token.

Source

pub fn get_market_mut( &mut self, market_token: &Pubkey, ) -> Option<&mut MarketModel>

Get market mutably by its market token.

Source

pub fn get_price(&self, token: &Pubkey) -> Option<Price<u128>>

Get prices for the given token.

Source

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.

Source

pub fn get_prices(&self, meta: &MarketMeta) -> Option<Prices<u128>>

Get prices for the given market meta.

Source

pub fn get_glv(&self, glv_token: &Pubkey) -> Option<&GlvModel>

Get GLV by GLV token address.

Source

pub fn get_glv_mut(&mut self, glv_token: &Pubkey) -> Option<&mut GlvModel>

Get GLV by GLV token address mutably.

Source

pub fn insert_glv(&mut self, glv: GlvModel) -> Option<GlvModel>

Insert GLV model.

Source

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 along
  • source_token - The source token to swap from
  • amount - The amount to swap
  • options - Optional simulation options. If None, default options are used.
Source

pub fn tokens(&self) -> impl Iterator<Item = (&Pubkey, &TokenState)>

Get token states.

Source

pub fn markets(&self) -> impl Iterator<Item = (&Pubkey, &MarketModel)>

Get market states.

Source

pub fn glvs(&self) -> impl Iterator<Item = (&Pubkey, &GlvModel)>

Get GLV states.

Source

pub fn insert_vi( &mut self, vi_address: Pubkey, vi: VirtualInventoryModel, ) -> Option<VirtualInventoryModel>

Insert virtual inventory model.

Source

pub fn get_vi(&self, vi_address: &Pubkey) -> Option<&VirtualInventoryModel>

Get virtual inventory model by address.

Source

pub fn vis(&self) -> impl Iterator<Item = (&Pubkey, &VirtualInventoryModel)>

Get all virtual inventory states.

Source

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.

Source

pub fn simulate_deposit<'a>( &'a mut self, market_token: &'a Pubkey, params: &'a CreateDepositParams, ) -> DepositSimulationBuilderForSimulator<'a>

Create a builder for deposit simulation.

Source

pub fn simulate_withdrawal<'a>( &'a mut self, market_token: &'a Pubkey, params: &'a CreateWithdrawalParams, ) -> WithdrawalSimulationBuilderForSimulator<'a>

Create a builder for withdrawal simulation.

Source

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.

Source

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.

Source

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 Clone for Simulator

Source§

fn clone(&self) -> Simulator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Simulator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Simulator> for JsSimulator

Available on crate feature js only.
Source§

fn from(simulator: Simulator) -> Self

Converts to this type from the input type.
Source§

impl GlvCalculator for Simulator

Source§

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>

Calcualtes the market token value in GLV.
Source§

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>

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>

Calculates the maximum sellable value through the given market within the given GLV.
Source§

fn get_max_sellable_glv_value(&self, glv_token: &Pubkey) -> Result<u128>

Calculates the maximum sellable value for the given GLV.
Source§

fn get_glv_status(&self, glv_token: &Pubkey) -> Result<GlvStatus>

Calculates the status of the given GLV.
Source§

impl MarketCalculator for Simulator

Source§

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>>

Returns Price corresponding to the given token address.
Source§

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>)>

Returns MarketModel and Prices corresponding to the given market token.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,