Skip to content

Commit

Permalink
Create a wrap for eth::U256 in order to ensure correct serde
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Feb 22, 2024
1 parent 3316205 commit f8c0f85
Show file tree
Hide file tree
Showing 97 changed files with 1,208 additions and 1,232 deletions.
64 changes: 34 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions crates/alerter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,24 @@ use {
anyhow::{Context, Result},
clap::Parser,
model::order::{OrderClass, OrderKind, OrderStatus, OrderUid, BUY_ETH_ADDRESS},
number::serialization::HexOrDecimalU256,
primitive_types::{H160, U256},
primitive_types::H160,
prometheus::IntGauge,
reqwest::Client,
serde_with::serde_as,
std::{
collections::HashMap,
time::{Duration, Instant},
},
url::Url,
};

#[serde_as]
#[derive(Debug, serde::Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
struct Order {
kind: OrderKind,
buy_token: H160,
#[serde_as(as = "HexOrDecimalU256")]
buy_amount: U256,
buy_amount: number::U256,
sell_token: H160,
#[serde_as(as = "HexOrDecimalU256")]
sell_amount: U256,
sell_amount: number::U256,
uid: OrderUid,
partially_fillable: bool,
#[serde(flatten)]
Expand Down Expand Up @@ -130,14 +125,11 @@ impl ZeroExApi {
.append_pair("buyToken", &format!("{buy_token:#x}"))
.append_pair(amount_name, &amount.to_string());

#[serde_as]
#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
#[serde_as(as = "HexOrDecimalU256")]
pub sell_amount: U256,
#[serde_as(as = "HexOrDecimalU256")]
pub buy_amount: U256,
pub sell_amount: number::U256,
pub buy_amount: number::U256,
}

let response: Response = self
Expand Down
6 changes: 3 additions & 3 deletions crates/autopilot/src/boundary/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub fn to_domain(
uid: order.metadata.uid.into(),
sell_token: order.data.sell_token,
buy_token: order.data.buy_token,
sell_amount: order.data.sell_amount,
buy_amount: order.data.buy_amount,
user_fee: order.data.fee_amount,
sell_amount: *order.data.sell_amount,
buy_amount: *order.data.buy_amount,
user_fee: *order.data.fee_amount,
protocol_fees,
valid_to: order.data.valid_to,
kind: order.data.kind.into(),
Expand Down
Loading

0 comments on commit f8c0f85

Please sign in to comment.