Skip to content

Commit bae34b6

Browse files
authored
Extract U256Ext implementations into the numbers crate (#4030)
# Description As noted in #4010, several U256Ext utility implementations are scattered across different crates in the codebase, some of which are duplicated. This PR moves all of them into a single U256Ext trait under the `numbers` crate. No logic changes. As a result, easier to keep everything in one place, no duplicated logic.
1 parent 9b01756 commit bae34b6

File tree

15 files changed

+148
-209
lines changed

15 files changed

+148
-209
lines changed

crates/autopilot/src/domain/eth/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
pub use alloy::primitives::{Address, B256, U256};
22
use {
3-
crate::{domain, util::conv::U256Ext},
3+
crate::domain,
44
derive_more::{Display, From, Into},
5+
number::u256_ext::U256Ext,
56
};
67

78
/// ERC20 token address for ETH. In reality, ETH is not an ERC20 token because

crates/autopilot/src/domain/settlement/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,15 @@ pub struct ExecutionEnded {
351351
#[cfg(test)]
352352
mod tests {
353353
use {
354-
crate::{
355-
domain::{
356-
self,
357-
auction,
358-
eth,
359-
settlement::{OrderMatchKey, trade_to_key},
360-
},
361-
util::conv::U256Ext,
354+
crate::domain::{
355+
self,
356+
auction,
357+
eth,
358+
settlement::{OrderMatchKey, trade_to_key},
362359
},
363360
alloy::{eips::BlockId, primitives::address},
364361
hex_literal::hex,
362+
number::u256_ext::U256Ext,
365363
std::collections::{HashMap, HashSet},
366364
winner_selection::{self as ws, state::RankedItem},
367365
};

crates/autopilot/src/domain/settlement/trade/math.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
pub use error::Error;
22
use {
33
super::ExecutedProtocolFee,
4-
crate::{
5-
domain::{
6-
self,
7-
OrderUid,
8-
auction::{self, order},
9-
eth,
10-
fee,
11-
settlement::transaction::{ClearingPrices, Prices},
12-
},
13-
util::conv::U256Ext,
4+
crate::domain::{
5+
self,
6+
OrderUid,
7+
auction::{self, order},
8+
eth,
9+
fee,
10+
settlement::transaction::{ClearingPrices, Prices},
1411
},
1512
error::Math,
1613
num::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub},
14+
number::u256_ext::U256Ext,
1715
std::collections::HashMap,
1816
};
1917

crates/autopilot/src/util/conv.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

crates/autopilot/src/util/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use url::Url;
22

33
mod bytes;
4-
pub mod conv;
54

65
pub use self::bytes::Bytes;
76

crates/driver/src/domain/competition/solution/scoring.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ use {
1212
order::{self, Side},
1313
trade::CustomClearingPrices,
1414
},
15-
crate::{
16-
domain::{
17-
competition::{
18-
PriceLimits,
19-
auction,
20-
order::FeePolicy,
21-
solution::{
22-
error,
23-
fee::{self, adjust_quote_to_order_limits},
24-
},
15+
crate::domain::{
16+
competition::{
17+
PriceLimits,
18+
auction,
19+
order::FeePolicy,
20+
solution::{
21+
error,
22+
fee::{self, adjust_quote_to_order_limits},
2523
},
26-
eth,
2724
},
28-
util::conv::u256::U256Ext,
25+
eth,
2926
},
3027
alloy::primitives::ruint::UintTryFrom,
28+
number::u256_ext::U256Ext,
3129
};
3230

3331
pub fn compute_score(

crates/driver/src/domain/competition/solution/trade.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use crate::{
2-
domain::{
1+
use {
2+
crate::domain::{
33
competition::{
44
self,
55
order::{self, FeePolicy, SellAmount, Side, TargetAmount, Uid},
66
solution::error::{self, Math},
77
},
88
eth::{self, Asset},
99
},
10-
util::conv::u256::U256Ext,
10+
number::u256_ext::U256Ext,
1111
};
1212

1313
/// A trade which executes an order as part of this solution.

crates/driver/src/domain/eth/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use {
2-
crate::util::{Bytes, conv::u256::U256Ext},
2+
crate::util::Bytes,
33
alloy::rpc::types::TransactionRequest,
44
derive_more::{From, Into},
5+
number::u256_ext::U256Ext,
56
solvers_dto::auction::FlashloanHint,
67
std::{
78
collections::{HashMap, HashSet},

crates/driver/src/infra/solver/dto/auction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use {
99
liquidity,
1010
},
1111
infra::{config::file::FeeHandler, solver::ManageNativeToken},
12-
util::conv::{rational_to_big_decimal, u256::U256Ext},
1312
},
1413
app_data::AppDataHash,
1514
model::order::{BuyTokenDestination, SellTokenSource},
15+
number::{conversions::rational_to_big_decimal, u256_ext::U256Ext},
1616
std::collections::HashMap,
1717
};
1818

crates/driver/src/tests/cases/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Test cases.
22
33
use {
4-
crate::{domain::eth, util::conv::u256::U256Ext},
4+
crate::domain::eth,
55
bigdecimal::{BigDecimal, FromPrimitive, Signed, num_traits::CheckedMul},
66
num::BigRational,
7-
number::conversions::big_decimal_to_big_rational,
7+
number::{conversions::big_decimal_to_big_rational, u256_ext::U256Ext},
88
std::str::FromStr,
99
};
1010

0 commit comments

Comments
 (0)