Skip to main content

Exchange

Struct Exchange 

Source
pub struct Exchange { /* private fields */ }
Expand description

Exchange state snapshot.

super::SnapshotBuilder can be used to create the snapshot at specified/latest block, which can then be kept up to date by calling Self::apply_events with events from crate::stream::raw.

Implementations§

Source§

impl Exchange

Source

pub const fn revision() -> &'static str

Revision of the exchange smart contract the SDK targeted at.

Source

pub fn chain(&self) -> &Chain

Chain the snapshot collected from.

Source

pub fn instant(&self) -> StateInstant

Instant the snapshot is consistent with or was last updated at.

Source

pub fn features(&self) -> ContractFeatures

Feature set of the deployed contract, which can lag behind the revision the SDK targets (Self::revision). Detected while building the snapshot and kept up to date by ContractVersionSet.

Source

pub fn contract_version(&self) -> Option<ContractVersion>

Version reported by the deployed contract, None before v1.1.7.4 which has no version getter.

Source

pub fn fee_schedules(&self) -> &FeeScheduleRegistry

Every fee schedule known to the exchange, which perpetual contracts resolve their fees from by pointing at one (see Perpetual::fee_schedule).

Source

pub fn default_fee_schedule(&self) -> FeeSchedule

Exchange-wide default fee schedule, shared by every perpetual contract that has not been repointed at another one.

Source

pub fn rwa_fee_schedule(&self) -> FeeSchedule

Exchange-wide default fee schedule for real-world assets.

Source

pub fn fee_schedule(&self, key: FeeScheduleKey) -> Option<FeeSchedule>

Fee schedule registered under the given key, None for a custom schedule that has never been observed - one keyed by a perpetual the snapshot does not track, and not written since.

Source

pub fn collateral_converter(&self) -> Converter

Converter of fixed-point <-> decimal numbers for collateral token amounts.

Source

pub fn funding_interval_blocks(&self) -> u32

Funding interval in blocks.

Each perpetual contract has own Perpetual::funding_start_block this interval applied to.

Source

pub fn min_post(&self) -> UD128

Minimal amount in collateral token that can be posted to the book.

Source

pub fn min_settle(&self) -> UD128

Minimal amount in collateral token that can be settled.

Source

pub fn recycle_fee(&self) -> UD128

Amount in collateral token locked with each posted order to pay the account that cleans it up:

  • When cancelled/changed by the original poster -> the original poster
  • When filled -> the original poster
  • In all other cases -> the one that performed the recycling
Source

pub fn perpetuals(&self) -> &HashMap<PerpetualId, Perpetual>

Perpetual contracts state tracked within the exchange, according to initial snapshot building configuration.

Source

pub fn accounts(&self) -> &HashMap<AccountId, Account>

Accounts state tracked within the exchange, according to initial snapshot building configuration.

Source

pub fn is_halted(&self) -> bool

Indicates if exchange is being halted.

Source

pub fn apply_events( &mut self, events: &RawBlockEvents, ) -> Result<Option<StateBlockEvents>, DexError>

Updates state snapshot by applying raw exchange events from the specific block.

Blocks expected to arrive strictly in-order, with already applied blocks being ignored, to enforce state consistency as most raw events provide only incremental state update information rather than full piece of state snapshot.

Exchange emits two categories of events:

This method applies state mutation events only to tracked perpetual contracts and accounts provided to SnapshotBuilder during the initial snapshot creation, and returns order request failure events only for requests issues by tracked accounts. Successfull order book mutations are applied to all orders of tracked perpetual contracts, so client code can keep up to date order book representation externally if needed.

§Returns

On success, list of state mutation and failure StateEvents produced from the original raw events, filtered as described above and with numeric systems conversion applied.

StateEvents are roughly resemble crate::abi::dex::Exchange::ExchangeEvents so corresponding smart contract documentation and raw event data for error responses could be helpful with debugging, but there is no exact match and more than one state event can be emitted in response to a single raw event, eg. processing of single order event produces up to two account events on top of order events within the same event context.

On failure, the corresponding DexError, any of which indicates some inconsistency in event sequence or event handling logic and should not be ignored as it may lead to state inconsistency.

Trait Implementations§

Source§

impl Clone for Exchange

Source§

fn clone(&self) -> Exchange

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Exchange

Source§

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

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

impl Display for Exchange

Available on crate feature display only.
Source§

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

Formats the value using the given formatter. Read more

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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