Skip to content

Commit bcb5e34

Browse files
authored
Implement build.rs bindings generation (#3827)
# Description Implements bindings generation in `build.rs`, adding this allows 1. Generated code to be inspected manually and "cmd-click"ed into 2. Faster incremental compilation since the code can be cached unlike macros # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] New contracts-generate crate to simplify build.rs code - [ ] Generate bindings in contracts build.rs - [ ] Migrate everything without changing any module paths - [ ] Moved away from the Provider re-export (`contracts::alloy::Provider` -> `alloy::providers::DynProvider`) - [ ] Removes the ethcontract re-export from the contracts crate - [ ] Removes now unused code (some inconsistent tests and dummy legacy things) ## How to test Run existing tests & compile <!-- ## Related Issues Fixes # -->
1 parent 5923b47 commit bcb5e34

File tree

27 files changed

+1326
-1199
lines changed

27 files changed

+1326
-1199
lines changed

Cargo.lock

Lines changed: 98 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ tower-http = "0.4"
9999
tracing-opentelemetry = "0.31"
100100
tracing-serde = "0.2"
101101
vergen = "8"
102+
walkdir = "2.5.0"
103+
quote = "1.0.41"
104+
syn = "2.0.108"
105+
prettyplease = "0.2.37"
106+
proc-macro2 = "1.0.103"
107+
alloy-sol-macro-input = "1.4.1"
108+
alloy-sol-macro-expander = "1.4.1"
102109

103110
[workspace.lints]
104111
clippy.cast_possible_wrap = "deny"

crates/autopilot/src/boundary/events/settlement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl AlloyEventRetrieving for GPv2SettlementContract {
2828
Filter::new().address(self.address)
2929
}
3030

31-
fn provider(&self) -> &contracts::alloy::Provider {
31+
fn provider(&self) -> &alloy::providers::DynProvider {
3232
&self.provider
3333
}
3434
}

crates/autopilot/src/database/ethflow_events/event_retriever.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl EthFlowRefundRetriever {
2929
impl AlloyEventRetrieving for EthFlowRefundRetriever {
3030
type Event = CoWSwapEthFlow::CoWSwapEthFlowEvents;
3131

32-
fn provider(&self) -> &contracts::alloy::Provider {
32+
fn provider(&self) -> &alloy::providers::DynProvider {
3333
&self.web3.alloy
3434
}
3535

crates/autopilot/src/database/onchain_order_events/event_retriever.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl AlloyEventRetrieving for CoWSwapOnchainOrdersContract {
4242
]))
4343
}
4444

45-
fn provider(&self) -> &contracts::alloy::Provider {
45+
fn provider(&self) -> &alloy::providers::DynProvider {
4646
&self.web3.alloy
4747
}
4848
}

crates/autopilot/src/database/onchain_order_events/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ mod test {
786786
super::*,
787787
crate::database::Config,
788788
alloy::primitives::U256,
789-
contracts::alloy::{CoWSwapOnchainOrders, InstanceExt},
789+
contracts::alloy::CoWSwapOnchainOrders,
790790
database::{byte_array::ByteArray, onchain_broadcasted_orders::OnchainOrderPlacement},
791791
ethcontract::H160,
792792
ethrpc::Web3,

crates/autopilot/src/infra/blockchain/contracts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use {
66
GPv2AllowListAuthentication,
77
GPv2Settlement,
88
HooksTrampoline,
9-
InstanceExt,
109
WETH9,
1110
support::Balances,
1211
},

crates/autopilot/src/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use {
2727
alloy::eips::BlockNumberOrTag,
2828
chain::Chain,
2929
clap::Parser,
30-
contracts::alloy::{BalancerV2Vault, GPv2Settlement, IUniswapV3Factory, InstanceExt, WETH9},
30+
contracts::alloy::{BalancerV2Vault, GPv2Settlement, IUniswapV3Factory, WETH9},
3131
ethcontract::H160,
3232
ethrpc::{
3333
Web3,

crates/contracts/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated by build.rs, will contain the contract bindings
2+
src/alloy

crates/contracts/Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ bin = [
2222

2323
[dependencies]
2424
alloy = { workspace = true, features = ["sol-types", "json", "contract", "json-abi"] }
25-
paste = { workspace = true }
2625
ethcontract = { workspace = true }
26+
paste = { workspace = true }
27+
serde = { workspace = true }
2728
serde_json = { workspace = true }
2829

2930
# [bin-dependencies]
@@ -33,8 +34,14 @@ tracing = { workspace = true, optional = true }
3334
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"], optional = true }
3435

3536
[build-dependencies]
36-
ethcontract = { workspace = true }
37-
ethcontract-generate = { workspace = true }
37+
anyhow = { workspace = true }
38+
alloy-sol-macro-expander = {workspace = true}
39+
alloy-sol-macro-input = {workspace = true, features = ["json"]}
40+
prettyplease = {workspace = true}
41+
proc-macro2 = {workspace = true}
42+
quote = {workspace = true}
43+
syn = {workspace = true}
44+
walkdir = {workspace = true}
3845

3946
[lints]
4047
workspace = true

0 commit comments

Comments
 (0)