Skip to content

Commit 09b2026

Browse files
authored
feat: better builders for orders (#129)
* feat: better builders for orders * fix: dep specs
1 parent 985ccf2 commit 09b2026

File tree

4 files changed

+93
-29
lines changed

4 files changed

+93
-29
lines changed

Cargo.toml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.11.2"
6+
version = "0.12.0"
77
edition = "2021"
88
rust-version = "1.85"
99
authors = ["init4"]
@@ -34,24 +34,21 @@ debug = false
3434
incremental = false
3535

3636
[workspace.dependencies]
37-
signet-bundle = { version = "0.11", path = "crates/bundle" }
38-
signet-constants = { version = "0.11", path = "crates/constants" }
39-
signet-evm = { version = "0.11", path = "crates/evm" }
40-
signet-extract = { version = "0.11", path = "crates/extract" }
41-
signet-journal = { version = "0.11", path = "crates/journal" }
42-
signet-node = { version = "0.11", path = "crates/node" }
43-
signet-sim = { version = "0.11", path = "crates/sim" }
44-
signet-types = { version = "0.11", path = "crates/types" }
45-
signet-tx-cache = { version = "0.11", path = "crates/tx-cache" }
46-
signet-zenith = { version = "0.11", path = "crates/zenith" }
37+
signet-bundle = { version = "0.12", path = "crates/bundle" }
38+
signet-constants = { version = "0.12", path = "crates/constants" }
39+
signet-evm = { version = "0.12", path = "crates/evm" }
40+
signet-extract = { version = "0.12", path = "crates/extract" }
41+
signet-journal = { version = "0.12", path = "crates/journal" }
42+
signet-node = { version = "0.12", path = "crates/node" }
43+
signet-sim = { version = "0.12", path = "crates/sim" }
44+
signet-types = { version = "0.12", path = "crates/types" }
45+
signet-tx-cache = { version = "0.12", path = "crates/tx-cache" }
46+
signet-zenith = { version = "0.12", path = "crates/zenith" }
4747

48-
signet-test-utils = { version = "0.11", path = "crates/test-utils" }
49-
50-
# ajj
51-
ajj = { version = "0.3.4" }
48+
signet-test-utils = { version = "0.12", path = "crates/test-utils" }
5249

5350
# trevm
54-
trevm = { version = "0.29.0", features = ["full_env_cfg"] }
51+
trevm = { version = "0.30.0", features = ["full_env_cfg"] }
5552

5653
# Alloy periphery crates
5754
alloy-core = "1.4"

crates/types/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ honestly.
77

88
## What's in this crate?
99

10-
- `mod constants` - contains `SignetSystemConstants` a configuration object that
11-
holds the system constants and is used by the extractor, the EVM, and the
12-
node.
1310
- `AggregateFills` - a struct that holds the aggregate fill status for
1411
[conditional transactions].
1512
- `MagicSig` - a struct that holds magic signatures for Signet L1-driven

crates/types/src/signing/order.rs

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use crate::signing::{permit_signing_info, SignedPermitError, SigningError};
22
use alloy::{
33
network::TransactionBuilder,
4-
primitives::{keccak256, Address, B256},
4+
primitives::{keccak256, Address, B256, U256},
55
rpc::types::TransactionRequest,
66
signers::Signer,
77
sol_types::{SolCall, SolValue},
88
};
99
use chrono::Utc;
1010
use serde::{Deserialize, Serialize};
11+
use signet_constants::SignetSystemConstants;
1112
use signet_zenith::RollupOrders::{
12-
initiatePermit2Call, Order, Output, Permit2Batch, TokenPermissions,
13+
initiatePermit2Call, Input, Order, Output, Permit2Batch, TokenPermissions,
1314
};
1415
use std::borrow::Cow;
1516

@@ -108,11 +109,12 @@ impl SignedOrder {
108109
}
109110
}
110111

111-
/// An UnsignedOrder is a helper type used to easily transform an Order into a SignedOrder with correct permit2 semantics.
112+
/// An UnsignedOrder is a helper type used to easily transform an Order into a
113+
/// SignedOrder with correct permit2 semantics.
112114
/// Users can do:
113115
/// let signed_order = UnsignedOrder::from(order).with_chain(rollup_chain_id, rollup_order_address).sign(signer)?;
114116
/// TxCache::new(tx_cache_endpoint).forward_order(signed_order);
115-
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
117+
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Default)]
116118
pub struct UnsignedOrder<'a> {
117119
order: Cow<'a, Order>,
118120
nonce: Option<u64>,
@@ -122,14 +124,56 @@ pub struct UnsignedOrder<'a> {
122124

123125
impl<'a> From<&'a Order> for UnsignedOrder<'a> {
124126
fn from(order: &'a Order) -> Self {
125-
UnsignedOrder::new(order)
127+
Self { order: Cow::Borrowed(order), ..Default::default() }
126128
}
127129
}
128130

129131
impl<'a> UnsignedOrder<'a> {
130132
/// Get a new UnsignedOrder from an Order.
131-
pub fn new(order: &'a Order) -> Self {
132-
Self { order: order.into(), nonce: None, rollup_chain_id: None, rollup_order_address: None }
133+
pub fn new() -> Self {
134+
Self {
135+
order: Cow::Owned(Order::default()),
136+
nonce: None,
137+
rollup_chain_id: None,
138+
rollup_order_address: None,
139+
}
140+
}
141+
142+
/// Add an input to the UnsignedOrder.
143+
pub fn with_raw_input(self, input: Input) -> UnsignedOrder<'static> {
144+
let order = self.order.into_owned().with_input(input);
145+
146+
UnsignedOrder { order: Cow::Owned(order), ..self }
147+
}
148+
149+
/// Add an input to the UnsignedOrder.
150+
pub fn with_input(self, token: Address, amount: U256) -> UnsignedOrder<'static> {
151+
self.with_raw_input(Input { token, amount })
152+
}
153+
154+
/// Add an output to the UnsignedOrder.
155+
pub fn with_raw_output(self, output: Output) -> UnsignedOrder<'static> {
156+
let order = self.order.into_owned().with_output(output);
157+
158+
UnsignedOrder { order: Cow::Owned(order), ..self }
159+
}
160+
161+
/// Add an output to the UnsignedOrder.
162+
pub fn with_output(
163+
self,
164+
token: Address,
165+
amount: U256,
166+
recipient: Address,
167+
chain_id: u32,
168+
) -> UnsignedOrder<'static> {
169+
self.with_raw_output(Output { token, amount, recipient, chainId: chain_id })
170+
}
171+
172+
/// Set the deadline on the UnsignedOrder.
173+
pub fn with_deadline(self, deadline: u64) -> UnsignedOrder<'static> {
174+
let order = self.order.into_owned().with_deadline(deadline);
175+
176+
UnsignedOrder { order: Cow::Owned(order), ..self }
133177
}
134178

135179
/// Add a Permit2 nonce to the UnsignedOrder.
@@ -138,10 +182,10 @@ impl<'a> UnsignedOrder<'a> {
138182
}
139183

140184
/// Add the chain id and Order contract address to the UnsignedOrder.
141-
pub fn with_chain(self, chain_id: u64, order_contract_address: Address) -> Self {
185+
pub fn with_chain(self, constants: &SignetSystemConstants) -> Self {
142186
Self {
143-
rollup_chain_id: Some(chain_id),
144-
rollup_order_address: Some(order_contract_address),
187+
rollup_chain_id: Some(constants.ru_chain_id()),
188+
rollup_order_address: Some(constants.ru_orders()),
145189
..self
146190
}
147191
}

crates/zenith/src/bindings.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,32 @@ mod orders {
333333
self.outputs.as_slice()
334334
}
335335
}
336+
337+
impl Default for Orders::Order {
338+
fn default() -> Self {
339+
Self { inputs: Vec::new(), outputs: Vec::new(), deadline: U256::ZERO }
340+
}
341+
}
342+
343+
impl Orders::Order {
344+
/// Add an input to the Order and return the modified Order.
345+
pub fn with_input(mut self, input: IOrders::Input) -> Self {
346+
self.inputs.push(input);
347+
self
348+
}
349+
350+
/// Add an output to the Order and return the modified Order.
351+
pub fn with_output(mut self, output: IOrders::Output) -> Self {
352+
self.outputs.push(output);
353+
self
354+
}
355+
356+
/// Set the deadline of the Order and return the modified Order.
357+
pub fn with_deadline(mut self, deadline: u64) -> Self {
358+
self.deadline = U256::from(deadline);
359+
self
360+
}
361+
}
336362
}
337363

338364
mod transactor {

0 commit comments

Comments
 (0)