Sitelet https://github.com/SharkHand3/examples/commit/941c8a7d11b3c00ae49b3b03eb866dc1b4588d4b
Skip to content

Commit 941c8a7

Browse files
authored
chore: restructure examples, benches, helpers (alloy-rs#242)
* refactor examples * fix benches * clean up * clean up * fix * add flaky example to ignore
1 parent b2f7609 commit 941c8a7

19 files changed

Lines changed: 47 additions & 355 deletions

‎Cargo.toml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["examples/*", "benches"]
2+
members = ["helpers", "examples/*", "benches"]
33
resolver = "2"
44

55
[workspace.package]
@@ -111,7 +111,7 @@ alloy = { version = "1.1.0", features = [
111111
"signer-mnemonic",
112112
"signer-trezor",
113113
"signer-yubihsm",
114-
"kzg"
114+
"kzg",
115115
] }
116116
alloy-chains = "0.2.17"
117117

@@ -149,3 +149,6 @@ ethabi = "18"
149149
rlp = "0.6.1"
150150
rlp-derive = "0.2.0"
151151
alloy-rlp = "0.3.12"
152+
153+
# helpers
154+
helpers = { path = "helpers" }

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ This repository contains the following examples:
142142
- [x] [Encoding with `dyn_abi`](./examples/advanced/examples/encoding_dyn_abi.rs)
143143
- [x] [Static encoding with `sol!`](./examples/advanced/examples/encoding_sol_static.rs)
144144
- [x] [Using `foundry-fork-db`](./examples/advanced/examples/foundry_fork_db.rs)
145-
- [x] [Uniswap V2 arbitrage profit calculation using Alloy](./examples/advanced/examples/uniswap_u256/alloy_profit.rs)
146-
- [x] [Uniswap V2 arbitrage profit calculation using Ethers](./examples/advanced/examples/uniswap_u256/ethers_profit.rs)
147-
- [x] [Uniswap V2 arbitrage simulation](./examples/advanced/examples/uniswap_u256/alloy_simulation.rs)
145+
- [x] [Uniswap V2 arbitrage profit calculation using Alloy](./examples/advanced/examples/uniswap_u256_alloy_profit.rs)
146+
- [x] [Uniswap V2 arbitrage profit calculation using Ethers](./examples/advanced/examples/uniswap_u256_ethers_profit.rs)
147+
- [x] [Uniswap V2 arbitrage simulation](./examples/advanced/examples/uniswap_u256_alloy_simulation.rs)
148148

149149
## Contributing
150150

‎benches/Cargo.toml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ ethabi.workspace = true
1515
rlp.workspace = true
1616
rlp-derive.workspace = true
1717
alloy-rlp.workspace = true
18-
19-
[lib]
20-
name = "alloy_benches"
21-
path = "src/lib.rs"
18+
helpers.workspace = true
2219

2320
[[bench]]
2421
name = "abi_encoding"

‎benches/benches/json_abi.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Benchmarks alloy JSON-ABI serialization and deserialization against ethabi.
22
#![allow(unknown_lints, clippy::incompatible_msrv)]
33

4+
use std::{hint::black_box, time::Duration};
5+
46
use alloy::json_abi::{Function, JsonAbi};
57
use criterion::{
68
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
79
};
8-
use std::{hint::black_box, time::Duration};
910

1011
fn ser_group(c: &mut Criterion) {
1112
let mut g = c.benchmark_group("JSON-ABI Serialization");

‎benches/benches/rlp.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Benchmarking alloy RLP encode and decode against parity-rlp.
22
33
use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable};
4-
54
use criterion::{black_box, criterion_group, criterion_main, Criterion};
65
use rlp::Encodable as ParityEncodable;
76

‎benches/benches/u256.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use alloy::primitives::U256 as aU256;
1+
use std::{hint::black_box, str::FromStr};
22

3+
use alloy::primitives::U256 as AlloyU256;
34
use criterion::{criterion_group, criterion_main, Criterion};
45
use ethers::types::U256;
5-
use std::{hint::black_box, str::FromStr};
66

7-
use alloy_benches::{
8-
alloy_helpers::{
7+
use helpers::{
8+
alloy::{
99
get_amount_in as a_get_amount_in, get_amount_out as a_get_amount_out,
1010
get_sushi_pair as a_get_sushi_pair, get_uniswap_pair as a_get_uniswap_pair,
1111
},
12-
ethers_helpers::{
12+
ethers::{
1313
get_amount_in as e_get_amount_in, get_amount_out as e_get_amount_out,
1414
get_sushi_pair as e_get_sushi_pair, get_uniswap_pair as e_get_uniswap_pair,
1515
},
@@ -21,7 +21,7 @@ fn u256_benchmark(c: &mut Criterion) {
2121
let e_uniswap_pair = e_get_uniswap_pair();
2222
let e_sushi_pair = e_get_sushi_pair();
2323

24-
let a_amount_in = aU256::from_str("1000000000000000000").unwrap();
24+
let a_amount_in = AlloyU256::from_str("1000000000000000000").unwrap();
2525
let e_amount_in = U256::from_dec_str("1000000000000000000").unwrap();
2626

2727
let mut group1 = c.benchmark_group("U256 Operations");

‎benches/src/alloy_helpers.rs‎

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

0 commit comments

Comments
 (0)