pub struct EVMPoolState<D: EngineDatabaseInterface + Clone + Debug>{
pub tokens: Vec<Bytes>,
/* private fields */
}Fields§
§tokens: Vec<Bytes>The pool’s token’s addresses
Implementations§
Source§impl<D> EVMPoolState<D>where
D: EngineDatabaseInterface + Clone + Debug + 'static,
<D as DatabaseRef>::Error: Debug,
<D as EngineDatabaseInterface>::Error: Debug,
impl<D> EVMPoolState<D>where
D: EngineDatabaseInterface + Clone + Debug + 'static,
<D as DatabaseRef>::Error: Debug,
<D as EngineDatabaseInterface>::Error: Debug,
Sourcepub fn new(
id: String,
tokens: Vec<Bytes>,
component_balances: HashMap<Address, U256>,
balance_owner: Option<Address>,
contract_balances: HashMap<Address, HashMap<Address, U256>>,
spot_prices: HashMap<(Address, Address), f64>,
capabilities: HashSet<Capability>,
block_lasting_overwrites: HashMap<Address, HashMap<SlotId, U256>>,
involved_contracts: HashSet<Address>,
manual_updates: bool,
adapter_contract: TychoSimulationContract<D>,
disable_overwrite_tokens: HashSet<Address>,
) -> Self
pub fn new( id: String, tokens: Vec<Bytes>, component_balances: HashMap<Address, U256>, balance_owner: Option<Address>, contract_balances: HashMap<Address, HashMap<Address, U256>>, spot_prices: HashMap<(Address, Address), f64>, capabilities: HashSet<Capability>, block_lasting_overwrites: HashMap<Address, HashMap<SlotId, U256>>, involved_contracts: HashSet<Address>, manual_updates: bool, adapter_contract: TychoSimulationContract<D>, disable_overwrite_tokens: HashSet<Address>, ) -> Self
Creates a new instance of EVMPoolState with the given attributes, with the ability to
simulate a protocol-agnostic transaction.
See struct definition of EVMPoolState for attribute explanations.
Sourcepub fn set_spot_prices(
&mut self,
tokens: &HashMap<Bytes, Token>,
) -> Result<(), SimulationError>
pub fn set_spot_prices( &mut self, tokens: &HashMap<Bytes, Token>, ) -> Result<(), SimulationError>
Sets the spot prices for a pool for all possible pairs of the given tokens.
§Arguments
tokens- A hashmap ofTokeninstances representing the tokens to calculate spot prices for.
§Returns
Result<(), SimulationError>- ReturnsOk(())if the spot prices are successfully set, or aSimulationErrorif an error occurs during the calculation or processing.
§Behavior
This function performs the following steps:
- Ensures the pool has the required capability to perform price calculations.
- Iterates over all permutations of token pairs (sell token and buy token). For each pair:
- Retrieves all possible overwrites, considering the maximum balance limit.
- Calculates the sell amount limit, considering the overwrites.
- Invokes the adapter contract’s
pricefunction to retrieve the calculated price for the token pair, considering the sell amount limit. - Processes the price based on whether the
ScaledPricecapability is present:- If
ScaledPriceis present, uses the price directly from the adapter contract. - If
ScaledPriceis absent, scales the price by adjusting for token decimals.
- If
- Stores the calculated price in the
spot_pricesmap with the token addresses as the key.
- Returns
Ok(())upon successful completion or aSimulationErrorupon failure.
§Usage
Spot prices need to be set before attempting to retrieve prices using spot_price.
Tip: Setting spot prices on the pool every time the pool actually changes will result in faster price fetching than if prices are only set immediately before attempting to retrieve prices.
Sourcepub fn get_balances(&self) -> &HashMap<Address, U256>
pub fn get_balances(&self) -> &HashMap<Address, U256>
Get the component balances for validation purposes
Trait Implementations§
Source§impl<D: Clone + EngineDatabaseInterface + Clone + Debug> Clone for EVMPoolState<D>
impl<D: Clone + EngineDatabaseInterface + Clone + Debug> Clone for EVMPoolState<D>
Source§fn clone(&self) -> EVMPoolState<D>
fn clone(&self) -> EVMPoolState<D>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<D> Debug for EVMPoolState<D>where
D: EngineDatabaseInterface + Clone + Debug,
<D as DatabaseRef>::Error: Debug,
<D as EngineDatabaseInterface>::Error: Debug,
impl<D> Debug for EVMPoolState<D>where
D: EngineDatabaseInterface + Clone + Debug,
<D as DatabaseRef>::Error: Debug,
<D as EngineDatabaseInterface>::Error: Debug,
Source§impl<D> ProtocolSim for EVMPoolState<D>where
D: EngineDatabaseInterface + Clone + Debug + 'static,
<D as DatabaseRef>::Error: Debug,
<D as EngineDatabaseInterface>::Error: Debug,
impl<D> ProtocolSim for EVMPoolState<D>where
D: EngineDatabaseInterface + Clone + Debug + 'static,
<D as DatabaseRef>::Error: Debug,
<D as EngineDatabaseInterface>::Error: Debug,
Source§fn spot_price(
&self,
base: &Token,
quote: &Token,
) -> Result<f64, SimulationError>
fn spot_price( &self, base: &Token, quote: &Token, ) -> Result<f64, SimulationError>
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>
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>
Source§fn delta_transition(
&mut self,
delta: ProtocolStateDelta,
tokens: &HashMap<Bytes, Token>,
balances: &Balances,
) -> Result<(), TransitionError<String>>
fn delta_transition( &mut self, delta: ProtocolStateDelta, tokens: &HashMap<Bytes, Token>, balances: &Balances, ) -> Result<(), TransitionError<String>>
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 eq(&self, other: &dyn ProtocolSim) -> bool
fn eq(&self, other: &dyn ProtocolSim) -> bool
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§impl TryFromWithBlock<ComponentWithState, BlockHeader> for EVMPoolState<PreCachedDB>
impl TryFromWithBlock<ComponentWithState, BlockHeader> for EVMPoolState<PreCachedDB>
Source§async fn try_from_with_header(
snapshot: ComponentWithState,
_block: BlockHeader,
account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>,
all_tokens: &HashMap<Bytes, Token>,
decoder_context: &DecoderContext,
) -> Result<Self, Self::Error>
async fn try_from_with_header( snapshot: ComponentWithState, _block: BlockHeader, account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>, all_tokens: &HashMap<Bytes, Token>, decoder_context: &DecoderContext, ) -> Result<Self, Self::Error>
Decodes a ComponentWithState, block BlockHeader and HashMap of all available tokens into
an EVMPoolState.
Errors with a InvalidSnapshotError.
type Error = InvalidSnapshotError
Auto Trait Implementations§
impl<D> Freeze for EVMPoolState<D>where
D: Freeze,
impl<D> RefUnwindSafe for EVMPoolState<D>where
D: RefUnwindSafe,
impl<D> Send for EVMPoolState<D>
impl<D> Sync for EVMPoolState<D>
impl<D> Unpin for EVMPoolState<D>where
D: Unpin,
impl<D> UnwindSafe for EVMPoolState<D>where
D: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)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,
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.