Skip to content

Commit 14d4b47

Browse files
feat: Add IndicativelyPriced trait
Add GetAmountOutParams to models --- don't change below this line --- ENG-4691 #time 6m
1 parent f57824b commit 14d4b47

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

tycho-common/src/models/protocol.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::collections::{hash_map::Entry, HashMap, HashSet};
22

33
use chrono::NaiveDateTime;
4+
use num_bigint::BigUint;
45
use serde::{Deserialize, Serialize};
56
use tracing::warn;
67

78
use crate::{
89
models::{
9-
blockchain::Transaction, Address, AttrStoreKey, Balance, Chain, ChangeType, ComponentId,
10-
MergeError, StoreVal, TxHash,
10+
blockchain::Transaction, token::Token, Address, AttrStoreKey, Balance, Chain, ChangeType,
11+
ComponentId, MergeError, StoreVal, TxHash,
1112
},
1213
Bytes,
1314
};
@@ -316,6 +317,14 @@ impl ProtocolChangesWithTx {
316317
}
317318
}
318319

320+
pub struct GetAmountOutParams {
321+
pub amount_in: BigUint,
322+
pub token_in: Token,
323+
pub token_out: Token,
324+
pub sender: Bytes,
325+
pub receiver: Bytes,
326+
}
327+
319328
#[cfg(test)]
320329
mod test {
321330
use rstest::rstest;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::collections::HashMap;
2+
3+
use async_trait::async_trait;
4+
use num_bigint::BigUint;
5+
6+
use crate::{
7+
models::protocol::GetAmountOutParams,
8+
simulation::{errors::SimulationError, protocol_sim::ProtocolSim},
9+
Bytes,
10+
};
11+
12+
pub struct SignedQuote {
13+
pub base_token: Bytes,
14+
pub quote_token: Bytes,
15+
pub amount_in: BigUint,
16+
pub amount_out: BigUint,
17+
// each RFQ will need different attributes
18+
pub quote_attributes: HashMap<String, Bytes>,
19+
}
20+
21+
#[async_trait]
22+
pub trait IndicativelyPriced: ProtocolSim {
23+
// this will be true when the price is only an estimation/indicative price
24+
fn is_indicatively_priced() -> bool {
25+
false
26+
}
27+
28+
// if it is indicatively priced, then we need to request a signed quote for the final price
29+
async fn request_signed_quote(
30+
&self,
31+
_params: GetAmountOutParams,
32+
) -> Result<SignedQuote, SimulationError> {
33+
Err(SimulationError::FatalError("request_signed_quote not implemented".into()))
34+
}
35+
}

tycho-common/src/simulation/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod errors;
2+
pub mod indicatively_priced;
23
pub mod protocol_sim;

0 commit comments

Comments
 (0)