feat: Support Bebop quote through IndicativelyPriced state
Made a new feature gate (test-utils) for MockRFQState Took 2 hours 19 minutes
This commit is contained in:
104
src/encoding/evm/testing_utils.rs
Normal file
104
src/encoding/evm/testing_utils.rs
Normal file
@@ -0,0 +1,104 @@
|
||||
// This module is used in integration tests as well
|
||||
use std::{any::Any, collections::HashMap};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use num_bigint::BigUint;
|
||||
use tycho_common::{
|
||||
dto::ProtocolStateDelta,
|
||||
models::{protocol::GetAmountOutParams, token::Token},
|
||||
simulation::{
|
||||
errors::{SimulationError, TransitionError},
|
||||
indicatively_priced::{IndicativelyPriced, SignedQuote},
|
||||
protocol_sim::{Balances, GetAmountOutResult, ProtocolSim},
|
||||
},
|
||||
Bytes,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MockRFQState {
|
||||
pub quote_amount_out: BigUint,
|
||||
pub quote_calldata: Bytes,
|
||||
pub quote_partial_fill_offset: u64,
|
||||
}
|
||||
impl ProtocolSim for MockRFQState {
|
||||
fn fee(&self) -> f64 {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn spot_price(&self, _base: &Token, _quote: &Token) -> Result<f64, SimulationError> {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn get_amount_out(
|
||||
&self,
|
||||
_amount_in: BigUint,
|
||||
_token_in: &Token,
|
||||
_token_out: &Token,
|
||||
) -> Result<GetAmountOutResult, SimulationError> {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn get_limits(
|
||||
&self,
|
||||
_sell_token: Bytes,
|
||||
_buy_token: Bytes,
|
||||
) -> Result<(BigUint, BigUint), SimulationError> {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn delta_transition(
|
||||
&mut self,
|
||||
_delta: ProtocolStateDelta,
|
||||
_tokens: &HashMap<Bytes, Token>,
|
||||
_balances: &Balances,
|
||||
) -> Result<(), TransitionError<String>> {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn ProtocolSim> {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn eq(&self, _other: &dyn ProtocolSim) -> bool {
|
||||
panic!("MockRFQState does not implement fee")
|
||||
}
|
||||
|
||||
fn as_indicatively_priced(&self) -> Result<&dyn IndicativelyPriced, SimulationError> {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl IndicativelyPriced for MockRFQState {
|
||||
async fn request_signed_quote(
|
||||
&self,
|
||||
params: GetAmountOutParams,
|
||||
) -> Result<SignedQuote, SimulationError> {
|
||||
let mut quote_attributes: HashMap<String, Bytes> = HashMap::new();
|
||||
quote_attributes.insert("calldata".to_string(), self.quote_calldata.clone());
|
||||
quote_attributes.insert(
|
||||
"partial_fill_offset".to_string(),
|
||||
Bytes::from(
|
||||
self.quote_partial_fill_offset
|
||||
.to_be_bytes()
|
||||
.to_vec(),
|
||||
),
|
||||
);
|
||||
|
||||
Ok(SignedQuote {
|
||||
base_token: params.token_in,
|
||||
quote_token: params.token_out,
|
||||
amount_in: params.amount_in,
|
||||
amount_out: self.quote_amount_out.clone(),
|
||||
quote_attributes,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user