Skip to content

Commit

Permalink
make the meta an associated type
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Sep 16, 2024
1 parent 28c015a commit a0c3822
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 234 deletions.
21 changes: 7 additions & 14 deletions src/quoting/base_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl Pool for BasePool {
type Resources = BasePoolResources;
type State = BasePoolState;
type QuoteError = BasePoolQuoteError;
type Meta = ();

fn get_key(&self) -> NodeKey {
self.key
Expand All @@ -133,7 +134,7 @@ impl Pool for BasePool {

fn quote(
&self,
params: QuoteParams<Self::State>,
params: QuoteParams<Self::State, Self::Meta>,
) -> Result<Quote<Self::Resources, Self::State>, Self::QuoteError> {
let amount = params.token_amount.amount;
let token = params.token_amount.token;
Expand Down Expand Up @@ -318,7 +319,7 @@ impl Pool for BasePool {
#[cfg(test)]
mod tests {
use super::*;
use crate::quoting::types::{Block, QuoteMeta, TokenAmount};
use crate::quoting::types::TokenAmount;
use alloc::vec;

const TOKEN0: U256 = U256([1, 0, 0, 0]);
Expand Down Expand Up @@ -353,9 +354,7 @@ mod tests {
},
sqrt_ratio_limit: None,
override_state: None,
meta: QuoteMeta {
block: Block { number: 1, time: 2 },
},
meta: (),
};

let quote = pool.quote(params).expect("Failed to get quote");
Expand Down Expand Up @@ -383,9 +382,7 @@ mod tests {
},
sqrt_ratio_limit: None,
override_state: None,
meta: QuoteMeta {
block: Block { number: 1, time: 2 },
},
meta: (),
};

let quote = pool.quote(params).expect("Failed to get quote");
Expand Down Expand Up @@ -424,9 +421,7 @@ mod tests {
},
sqrt_ratio_limit: None,
override_state: None,
meta: QuoteMeta {
block: Block { number: 1, time: 2 },
},
meta: (),
};

let quote = pool.quote(params).expect("Failed to get quote");
Expand Down Expand Up @@ -465,9 +460,7 @@ mod tests {
},
sqrt_ratio_limit: None,
override_state: None,
meta: QuoteMeta {
block: Block { number: 1, time: 2 },
},
meta: (),
};

let quote = pool.quote(params).expect("Failed to get quote");
Expand Down
19 changes: 8 additions & 11 deletions src/quoting/oracle_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::quoting::base_pool::{
MAX_SQRT_RATIO_AT_MAX_TICK_SPACING, MAX_TICK_AT_MAX_TICK_SPACING, MAX_TICK_SPACING,
MIN_SQRT_RATIO_AT_MAX_TICK_SPACING, MIN_TICK_AT_MAX_TICK_SPACING,
};
use crate::quoting::types::{NodeKey, Pool, Quote, QuoteParams, Tick};
use crate::quoting::types::{BlockTimestamp, NodeKey, Pool, Quote, QuoteParams, Tick};
use alloc::vec;
use core::ops::Add;
use num_traits::ToPrimitive;
Expand Down Expand Up @@ -87,6 +87,7 @@ impl Pool for OraclePool {
type Resources = OraclePoolResources;
type State = OraclePoolState;
type QuoteError = BasePoolQuoteError;
type Meta = BlockTimestamp;

fn get_key(&self) -> NodeKey {
self.base_pool.get_key()
Expand All @@ -101,18 +102,18 @@ impl Pool for OraclePool {

fn quote(
&self,
params: QuoteParams<Self::State>,
params: QuoteParams<Self::State, Self::Meta>,
) -> Result<Quote<Self::Resources, Self::State>, Self::QuoteError> {
let block_time = params.meta.block.time;
let block_time = params.meta;
let pool_time = params
.override_state
.map_or(self.last_snapshot_time, |os| os.last_snapshot_time);

let result = self.base_pool.quote(QuoteParams {
sqrt_ratio_limit: params.sqrt_ratio_limit,
meta: params.meta,
override_state: params.override_state.map(|s| s.base_pool_state),
token_amount: params.token_amount,
meta: (),
})?;

Ok(Quote {
Expand Down Expand Up @@ -145,7 +146,7 @@ mod tests {
MIN_SQRT_RATIO_AT_MAX_TICK_SPACING, MIN_TICK_AT_MAX_TICK_SPACING,
};
use crate::quoting::oracle_pool::OraclePool;
use crate::quoting::types::{Block, Pool, QuoteMeta, QuoteParams, TokenAmount};
use crate::quoting::types::{Pool, QuoteParams, TokenAmount};

#[test]
fn test_max_values() {
Expand Down Expand Up @@ -181,9 +182,7 @@ mod tests {
},
sqrt_ratio_limit: None,
override_state: None,
meta: QuoteMeta {
block: Block { number: 1, time: 2 },
},
meta: 2,
};

let quote = pool.quote(params).expect("Failed to get quote");
Expand Down Expand Up @@ -219,9 +218,7 @@ mod tests {
},
sqrt_ratio_limit: None,
override_state: None,
meta: QuoteMeta {
block: Block { number: 1, time: 2 },
},
meta: 2,
};

let quote = pool.quote(params).expect("Failed to get quote");
Expand Down
Loading

0 comments on commit a0c3822

Please sign in to comment.