pub struct PriceLevelStreamState {
pub token0: Bytes,
pub token1: Bytes,
pub quotes_0_to_1: Vec<PriceLevelStreamQuote>,
pub quotes_1_to_0: Vec<PriceLevelStreamQuote>,
pub gas_cost: BigUint,
/* private fields */
}Expand description
State of a single pAMM pair fed from the price level stream.
Holds the latest complete quotes for both trade directions. Quotes are absolute
(amount_in → total amount_out), sorted ascending by amount_in; amounts between two
quotes are interpolated linearly, mirroring how Titan itself densifies the simulated levels.
Amounts outside the quoted range are not served.
A swap returns a state that records its fill. A later swap on the same direction continues
that fill: it pays the quotes’ output for the merged input less the output so far, at zero
gas, and get_limits and spot_price answer for what is left. The other direction is refused
with an “already quoted” error, as the quotes are cumulative from the pre-fill venue and say
nothing about its price after a fill. So the caller merges all swaps on one direction into
one swap.
Fields§
§token0: Bytes§token1: Bytes§quotes_0_to_1: Vec<PriceLevelStreamQuote>§quotes_1_to_0: Vec<PriceLevelStreamQuote>§gas_cost: BigUintImplementations§
Source§impl PriceLevelStreamState
impl PriceLevelStreamState
Sourcepub fn new(
token0: Bytes,
token1: Bytes,
quotes_0_to_1: Vec<PriceLevelStreamQuote>,
quotes_1_to_0: Vec<PriceLevelStreamQuote>,
gas_cost: BigUint,
) -> Self
pub fn new( token0: Bytes, token1: Bytes, quotes_0_to_1: Vec<PriceLevelStreamQuote>, quotes_1_to_0: Vec<PriceLevelStreamQuote>, gas_cost: BigUint, ) -> Self
Creates the state for the pair (token0, token1).
Both quote lists are sorted ascending by amount_in and deduplicated on it, so callers
may pass them in stream order.
Sourcepub fn with_quotable_until(self, until: Instant) -> Self
pub fn with_quotable_until(self, until: Instant) -> Self
Sets the monotonic instant from which this state refuses every query.
Sourcepub fn with_simulation_overrides(
self,
overrides: impl Into<Arc<PammSimulationOverrides>>,
) -> Self
pub fn with_simulation_overrides( self, overrides: impl Into<Arc<PammSimulationOverrides>>, ) -> Self
Attaches the account state Titan priced these quotes on.
Sourcepub fn simulation_overrides(&self) -> Option<&PammSimulationOverrides>
pub fn simulation_overrides(&self) -> Option<&PammSimulationOverrides>
The account state Titan priced these quotes on, to convert and pass to eth_call as state
overrides, or None when the stream matched no quote stream entry to this state’s book, or
runs without simulation overrides. Quoting never reads it.
Sourcepub fn quotable_until(&self) -> Option<Instant>
pub fn quotable_until(&self) -> Option<Instant>
The monotonic instant from which this state refuses every query, or None if it never
expires.
Trait Implementations§
Source§impl Clone for PriceLevelStreamState
impl Clone for PriceLevelStreamState
Source§impl Debug for PriceLevelStreamState
impl Debug for PriceLevelStreamState
Source§impl<'de> Deserialize<'de> for PriceLevelStreamState
impl<'de> Deserialize<'de> for PriceLevelStreamState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl ProtocolSim for PriceLevelStreamState
impl ProtocolSim for PriceLevelStreamState
Source§fn spot_price(
&self,
base: &Token,
quote: &Token,
) -> Result<f64, SimulationError>
fn spot_price( &self, base: &Token, quote: &Token, ) -> Result<f64, SimulationError>
Before a fill, the price of the smallest quote. After a fill, the marginal price at the filled amount, and a refusal for the other direction.
Source§fn get_amount_out(
&self,
amount_in: BigUint,
token_in: &Token,
token_out: &Token,
) -> Result<GetAmountOutResult, SimulationError>
fn get_amount_out( &self, amount_in: BigUint, token_in: &Token, token_out: &Token, ) -> Result<GetAmountOutResult, SimulationError>
Records the fill in the returned state. After a swap on the same direction it pays the
output of the merged input less the output so far, at zero gas. A swap on the other
direction fails: the venue already quoted. See PriceLevelStreamState.
Source§fn get_limits(
&self,
sell_token: Bytes,
buy_token: Bytes,
) -> Result<(BigUint, BigUint), SimulationError>
fn get_limits( &self, sell_token: Bytes, buy_token: Bytes, ) -> Result<(BigUint, BigUint), SimulationError>
The largest quote, less the fill after a swap on the same direction. A swap on the other direction fails: the venue already quoted.
Source§fn eq(&self, other: &dyn ProtocolSim) -> bool
fn eq(&self, other: &dyn ProtocolSim) -> bool
Equal when the pair, both quote lists, the gas cost and the fill match, and either neither state carries simulation overrides, or both carry overrides of the same block over the same account addresses. A state that gains or loses its overrides is a changed state.
The overridden values are left out. Quoting never reads them, and Titan republishes a venue’s accounts several times a second while its prices stand still, so comparing them would report a changed quote for an unchanged price.
The block is compared because prices can be identical across a block boundary: without it, a consumer that keeps the state it holds would simulate on the previous block’s overrides. The account addresses are compared because a merge can add or lose another quote address’s entry (see Metric); without them, a consumer would keep overrides missing an account the swap reads.
quotable_until is left out too: this process derives it and never serializes it. A
consumer that keeps the state it holds whenever eq says equal therefore keeps the earlier
deadline, and that state stops quoting one slot after its own message, even while newer
messages repeat the same quotes. Replace the held state on every update to always quote on
the newest deadline.
Source§fn delta_transition(
&mut self,
_delta: ProtocolStateDelta,
_tokens: &HashMap<Bytes, Token>,
_balances: &Balances,
) -> Result<(), TransitionError>
fn delta_transition( &mut self, _delta: ProtocolStateDelta, _tokens: &HashMap<Bytes, Token>, _balances: &Balances, ) -> Result<(), TransitionError>
Source§fn clone_box(&self) -> Box<dyn ProtocolSim>
fn clone_box(&self) -> Box<dyn ProtocolSim>
Box<dyn ProtocolSim>.Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Source§fn query_pool_swap(
&self,
_params: &QueryPoolSwapParams,
) -> Result<PoolSwap, SimulationError>
fn query_pool_swap( &self, _params: &QueryPoolSwapParams, ) -> Result<PoolSwap, SimulationError>
Source§fn as_indicatively_priced(
&self,
) -> Result<&(dyn IndicativelyPriced + 'static), SimulationError>
fn as_indicatively_priced( &self, ) -> Result<&(dyn IndicativelyPriced + 'static), SimulationError>
Source§fn apply_block(&mut self, _block: &BlockContext) -> bool
fn apply_block(&mut self, _block: &BlockContext) -> bool
Auto Trait Implementations§
impl !Freeze for PriceLevelStreamState
impl Forget for PriceLevelStreamState
impl RefUnwindSafe for PriceLevelStreamState
impl Send for PriceLevelStreamState
impl Sync for PriceLevelStreamState
impl Unpin for PriceLevelStreamState
impl UnsafeUnpin for PriceLevelStreamState
impl UnwindSafe for PriceLevelStreamState
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
impl<'de, T> BorrowedRpcObject<'de> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<'de, T> RpcBorrow<'de> for T
impl<T> RpcObject for T
impl<T> RpcRecv for T
impl<T> RpcSend for T
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.