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
impl Exchange
Sourcepub const fn revision() -> &'static str
pub const fn revision() -> &'static str
Revision of the exchange smart contract the SDK targeted at.
Sourcepub fn instant(&self) -> StateInstant
pub fn instant(&self) -> StateInstant
Instant the snapshot is consistent with or was last updated at.
Sourcepub fn features(&self) -> ContractFeatures
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.
Sourcepub fn contract_version(&self) -> Option<ContractVersion>
pub fn contract_version(&self) -> Option<ContractVersion>
Version reported by the deployed contract, None before v1.1.7.4 which
has no version getter.
Sourcepub fn fee_schedules(&self) -> &FeeScheduleRegistry
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).
Sourcepub fn default_fee_schedule(&self) -> FeeSchedule
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.
Sourcepub fn rwa_fee_schedule(&self) -> FeeSchedule
pub fn rwa_fee_schedule(&self) -> FeeSchedule
Exchange-wide default fee schedule for real-world assets.
Sourcepub fn fee_schedule(&self, key: FeeScheduleKey) -> Option<FeeSchedule>
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.
Sourcepub fn collateral_converter(&self) -> Converter
pub fn collateral_converter(&self) -> Converter
Converter of fixed-point <-> decimal numbers for collateral token amounts.
Sourcepub fn funding_interval_blocks(&self) -> u32
pub fn funding_interval_blocks(&self) -> u32
Funding interval in blocks.
Each perpetual contract has own Perpetual::funding_start_block this interval applied to.
Sourcepub fn min_post(&self) -> UD128
pub fn min_post(&self) -> UD128
Minimal amount in collateral token that can be posted to the book.
Sourcepub fn min_settle(&self) -> UD128
pub fn min_settle(&self) -> UD128
Minimal amount in collateral token that can be settled.
Sourcepub fn recycle_fee(&self) -> UD128
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
Sourcepub fn perpetuals(&self) -> &HashMap<PerpetualId, Perpetual>
pub fn perpetuals(&self) -> &HashMap<PerpetualId, Perpetual>
Perpetual contracts state tracked within the exchange, according to initial snapshot building configuration.
Sourcepub fn accounts(&self) -> &HashMap<AccountId, Account>
pub fn accounts(&self) -> &HashMap<AccountId, Account>
Accounts state tracked within the exchange, according to initial snapshot building configuration.
Sourcepub fn apply_events(
&mut self,
events: &RawBlockEvents,
) -> Result<Option<StateBlockEvents>, DexError>
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:
- State mutation events
- Order request error responses, for requests issued in batches via
crate::abi::dex::Exchange::ExchangeInstance::execOrderswithrevertOnFail= false.
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§
Auto Trait Implementations§
impl Freeze for Exchange
impl RefUnwindSafe for Exchange
impl Send for Exchange
impl Sync for Exchange
impl Unpin for Exchange
impl UnsafeUnpin for Exchange
impl UnwindSafe for Exchange
Blanket Implementations§
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
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> ⓘ
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> ⓘ
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.