Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Create a wrap for eth::U256 in order to ensure correct serde #2086 #2416

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading