Skip to content

Commit 1d34f0d

Browse files
authored
Merge pull request #274 from propeller-heads/rfqs/tnl/ENG-4693-bebop-decoder
feat: Bebop Decoder
2 parents d63a85d + d25ee7f commit 1d34f0d

File tree

14 files changed

+267
-34
lines changed

14 files changed

+267
-34
lines changed

src/evm/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152
state: Arc<RwLock<DecoderState>>| {
153153
Box::pin(async move {
154154
let guard = state.read().await;
155-
T::try_from_with_block(component, header, &account_balances, &guard.tokens)
155+
T::try_from_with_header(component, header, &account_balances, &guard.tokens)
156156
.await
157157
.map(|c| Box::new(c) as Box<dyn ProtocolSim>)
158158
}) as DecodeFut

src/evm/protocol/cpmm/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
protocol::errors::InvalidSnapshotError,
1919
};
2020

21-
pub fn cpmm_try_from_with_block(
21+
pub fn cpmm_try_from_with_header(
2222
snapshot: ComponentWithState,
2323
) -> Result<(U256, U256), InvalidSnapshotError> {
2424
let reserve0 = U256::from_be_slice(

src/evm/protocol/ekubo/tycho_decoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl TryFrom<Bytes> for EkuboExtension {
5252
impl TryFromWithBlock<ComponentWithState, BlockHeader> for EkuboState {
5353
type Error = InvalidSnapshotError;
5454

55-
async fn try_from_with_block(
55+
async fn try_from_with_header(
5656
snapshot: ComponentWithState,
5757
_block: BlockHeader,
5858
_account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>,
@@ -197,7 +197,7 @@ mod tests {
197197

198198
#[apply(all_cases)]
199199
#[tokio::test]
200-
async fn test_try_from_with_block(case: TestCase) {
200+
async fn test_try_from_with_header(case: TestCase) {
201201
let snapshot = ComponentWithState {
202202
state: ResponseProtocolState {
203203
attributes: case.state_attributes,
@@ -208,7 +208,7 @@ mod tests {
208208
entrypoints: Vec::new(),
209209
};
210210

211-
let result = EkuboState::try_from_with_block(
211+
let result = EkuboState::try_from_with_header(
212212
snapshot,
213213
BlockHeader::default(),
214214
&HashMap::new(),
@@ -243,7 +243,7 @@ mod tests {
243243
entrypoints: Vec::new(),
244244
};
245245

246-
let result = EkuboState::try_from_with_block(
246+
let result = EkuboState::try_from_with_header(
247247
snapshot,
248248
BlockHeader::default(),
249249
&HashMap::default(),

src/evm/protocol/pancakeswap_v2/tycho_decoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tycho_common::{models::token::Token, Bytes};
55

66
use crate::{
77
evm::protocol::{
8-
cpmm::protocol::cpmm_try_from_with_block, pancakeswap_v2::state::PancakeswapV2State,
8+
cpmm::protocol::cpmm_try_from_with_header, pancakeswap_v2::state::PancakeswapV2State,
99
},
1010
protocol::{errors::InvalidSnapshotError, models::TryFromWithBlock},
1111
};
@@ -15,13 +15,13 @@ impl TryFromWithBlock<ComponentWithState, BlockHeader> for PancakeswapV2State {
1515

1616
/// Decodes a `ComponentWithState` into a `PancakeswapV2State`. Errors with a
1717
/// `InvalidSnapshotError` if either reserve0 or reserve1 attributes are missing.
18-
async fn try_from_with_block(
18+
async fn try_from_with_header(
1919
snapshot: ComponentWithState,
2020
_block: BlockHeader,
2121
_account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>,
2222
_all_tokens: &HashMap<Bytes, Token>,
2323
) -> Result<Self, Self::Error> {
24-
let (reserve0, reserve1) = cpmm_try_from_with_block(snapshot)?;
24+
let (reserve0, reserve1) = cpmm_try_from_with_header(snapshot)?;
2525
Ok(Self::new(reserve0, reserve1))
2626
}
2727
}
@@ -64,7 +64,7 @@ mod tests {
6464
entrypoints: Vec::new(),
6565
};
6666

67-
let result = PancakeswapV2State::try_from_with_block(
67+
let result = PancakeswapV2State::try_from_with_header(
6868
snapshot,
6969
header(),
7070
&HashMap::new(),
@@ -98,7 +98,7 @@ mod tests {
9898
entrypoints: Vec::new(),
9999
};
100100

101-
let result = PancakeswapV2State::try_from_with_block(
101+
let result = PancakeswapV2State::try_from_with_header(
102102
snapshot,
103103
header(),
104104
&HashMap::new(),

src/evm/protocol/uniswap_v2/tycho_decoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tycho_client::feed::{synchronizer::ComponentWithState, BlockHeader};
44
use tycho_common::{models::token::Token, Bytes};
55

66
use crate::{
7-
evm::protocol::{cpmm::protocol::cpmm_try_from_with_block, uniswap_v2::state::UniswapV2State},
7+
evm::protocol::{cpmm::protocol::cpmm_try_from_with_header, uniswap_v2::state::UniswapV2State},
88
protocol::{errors::InvalidSnapshotError, models::TryFromWithBlock},
99
};
1010

@@ -13,13 +13,13 @@ impl TryFromWithBlock<ComponentWithState, BlockHeader> for UniswapV2State {
1313

1414
/// Decodes a `ComponentWithState` into a `UniswapV2State`. Errors with a `InvalidSnapshotError`
1515
/// if either reserve0 or reserve1 attributes are missing.
16-
async fn try_from_with_block(
16+
async fn try_from_with_header(
1717
snapshot: ComponentWithState,
1818
_block: BlockHeader,
1919
_account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>,
2020
_all_tokens: &HashMap<Bytes, Token>,
2121
) -> Result<Self, Self::Error> {
22-
let (reserve0, reserve1) = cpmm_try_from_with_block(snapshot)?;
22+
let (reserve0, reserve1) = cpmm_try_from_with_header(snapshot)?;
2323
Ok(Self::new(reserve0, reserve1))
2424
}
2525
}
@@ -62,7 +62,7 @@ mod tests {
6262
entrypoints: Vec::new(),
6363
};
6464

65-
let result = UniswapV2State::try_from_with_block(
65+
let result = UniswapV2State::try_from_with_header(
6666
snapshot,
6767
header(),
6868
&HashMap::new(),
@@ -96,7 +96,7 @@ mod tests {
9696
entrypoints: Vec::new(),
9797
};
9898

99-
let result = UniswapV2State::try_from_with_block(
99+
let result = UniswapV2State::try_from_with_header(
100100
snapshot,
101101
header(),
102102
&HashMap::new(),

src/evm/protocol/uniswap_v3/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ mod tests {
767767
let state: ComponentWithState = serde_json::from_value(data)
768768
.expect("Expected json to match ComponentWithState structure");
769769

770-
let usv3_state = UniswapV3State::try_from_with_block(
770+
let usv3_state = UniswapV3State::try_from_with_header(
771771
state,
772772
Default::default(),
773773
&Default::default(),
@@ -831,7 +831,7 @@ mod tests_forks {
831831
let state: ComponentWithState = serde_json::from_value(data)
832832
.expect("Expected json to match ComponentWithState structure");
833833

834-
let pool_state = UniswapV3State::try_from_with_block(
834+
let pool_state = UniswapV3State::try_from_with_header(
835835
state,
836836
Default::default(),
837837
&Default::default(),

src/evm/protocol/uniswap_v3/tycho_decoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl TryFromWithBlock<ComponentWithState, BlockHeader> for UniswapV3State {
1515

1616
/// Decodes a `ComponentWithState` into a `UniswapV3State`. Errors with a `InvalidSnapshotError`
1717
/// if the snapshot is missing any required attributes or if the fee amount is not supported.
18-
async fn try_from_with_block(
18+
async fn try_from_with_header(
1919
snapshot: ComponentWithState,
2020
_block: BlockHeader,
2121
_account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>,
@@ -189,7 +189,7 @@ mod tests {
189189
entrypoints: Vec::new(),
190190
};
191191

192-
let result = UniswapV3State::try_from_with_block(
192+
let result = UniswapV3State::try_from_with_header(
193193
snapshot,
194194
header(),
195195
&HashMap::new(),
@@ -246,7 +246,7 @@ mod tests {
246246
entrypoints: Vec::new(),
247247
};
248248

249-
let result = UniswapV3State::try_from_with_block(
249+
let result = UniswapV3State::try_from_with_header(
250250
snapshot,
251251
header(),
252252
&HashMap::new(),
@@ -280,7 +280,7 @@ mod tests {
280280
entrypoints: Vec::new(),
281281
};
282282

283-
let result = UniswapV3State::try_from_with_block(
283+
let result = UniswapV3State::try_from_with_header(
284284
snapshot,
285285
header(),
286286
&HashMap::new(),

src/evm/protocol/uniswap_v4/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ mod tests {
542542
let state: ComponentWithState = serde_json::from_value(data)
543543
.expect("Expected json to match ComponentWithState structure");
544544

545-
let usv4_state = UniswapV4State::try_from_with_block(
545+
let usv4_state = UniswapV4State::try_from_with_header(
546546
state,
547547
Default::default(),
548548
&Default::default(),
@@ -612,7 +612,7 @@ mod tests {
612612
let state: ComponentWithState = serde_json::from_value(data)
613613
.expect("Expected json to match ComponentWithState structure");
614614

615-
let usv4_state = UniswapV4State::try_from_with_block(
615+
let usv4_state = UniswapV4State::try_from_with_header(
616616
state,
617617
Default::default(),
618618
&Default::default(),

src/evm/protocol/uniswap_v4/tycho_decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl TryFromWithBlock<ComponentWithState, BlockHeader> for UniswapV4State {
1818

1919
/// Decodes a `ComponentWithState` into a `UniswapV4State`. Errors with a `InvalidSnapshotError`
2020
/// if the snapshot is missing any required attributes.
21-
async fn try_from_with_block(
21+
async fn try_from_with_header(
2222
snapshot: ComponentWithState,
2323
_block: BlockHeader,
2424
_account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>,
@@ -198,7 +198,7 @@ mod tests {
198198
entrypoints: Vec::new(),
199199
};
200200

201-
let result = UniswapV4State::try_from_with_block(
201+
let result = UniswapV4State::try_from_with_header(
202202
snapshot,
203203
header(),
204204
&HashMap::new(),
@@ -259,7 +259,7 @@ mod tests {
259259
entrypoints: Vec::new(),
260260
};
261261

262-
let result = UniswapV4State::try_from_with_block(
262+
let result = UniswapV4State::try_from_with_header(
263263
snapshot,
264264
header(),
265265
&HashMap::new(),

src/evm/protocol/vm/tycho_decoder.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl TryFromWithBlock<ComponentWithState, BlockHeader> for EVMPoolState<PreCache
2525
///
2626
/// Errors with a `InvalidSnapshotError`.
2727
#[allow(deprecated)]
28-
async fn try_from_with_block(
28+
async fn try_from_with_header(
2929
snapshot: ComponentWithState,
3030
block: BlockHeader,
3131
account_balances: &HashMap<Bytes, HashMap<Bytes, Bytes>>,
@@ -228,7 +228,7 @@ mod tests {
228228

229229
#[allow(deprecated)]
230230
#[tokio::test]
231-
async fn test_try_from_with_block() {
231+
async fn test_try_from_with_header() {
232232
let attributes: HashMap<String, Bytes> = vec![
233233
(
234234
"balance_owner".to_string(),
@@ -308,9 +308,10 @@ mod tests {
308308
]),
309309
)]);
310310

311-
let res = EVMPoolState::try_from_with_block(snapshot, header(), &account_balances, &tokens)
312-
.await
313-
.unwrap();
311+
let res =
312+
EVMPoolState::try_from_with_header(snapshot, header(), &account_balances, &tokens)
313+
.await
314+
.unwrap();
314315

315316
let res_pool = res;
316317

0 commit comments

Comments
 (0)