Skip to content

Commit 23c0e53

Browse files
committed
feat: simplify configuration of Signed Orders and Fills before signing
1 parent a57a150 commit 23c0e53

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

crates/types/src/signing/error.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,9 @@ pub enum SignedPermitError {
1919
pub enum SigningError {
2020
/// Missing chain config.
2121
#[error(
22-
"Target chain id is missing. Populate it by calling with_chain before attempting to sign"
22+
"Signet System constants are missing. Must call with_constants before attempting to sign"
2323
)]
24-
MissingChainId,
25-
/// Missing rollup chain id for a Fill.
26-
#[error(
27-
"Rollup chain id is missing. Populate it by calling with_ru_chain_id before attempting to sign"
28-
)]
29-
MissingRollupChainId,
30-
/// Missing chain config for a specific chain.
31-
#[error("Target Order contract address is missing for chain id {0}. Populate it by calling with_chain before attempting to sign")]
32-
MissingOrderContract(u64),
24+
MissingConstants,
3325
/// Error signing the order hash.
3426
#[error(transparent)]
3527
Signer(#[from] alloy::signers::Error),

crates/types/src/signing/fill.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,12 @@ impl<'a> UnsignedFill<'a> {
214214
Self { deadline: Some(deadline), ..self }
215215
}
216216

217-
/// Add the rollup chain id to the UnsignedFill.
218-
/// This is the rollup chain id from which the Orders originated,
219-
/// to which the Fill should be credited.
220-
/// MUST call this before signing, cannot be inferred.
221-
pub fn with_ru_chain_id(self, ru_chain_id: u64) -> Self {
222-
Self { ru_chain_id: Some(ru_chain_id), ..self }
223-
}
224-
225217
/// Add the chain id and Order contract address to the UnsignedFill.
226-
pub fn with_chain(mut self, constants: SignetSystemConstants) -> Self {
218+
/// MUST call before `sign` or `sign_for`.
219+
pub fn with_constants(mut self, constants: SignetSystemConstants) -> Self {
227220
self.target_chains.insert(constants.ru_chain_id(), constants.ru_orders());
228221
self.target_chains.insert(constants.host_chain_id(), constants.host_orders());
229-
self
222+
Self { ru_chain_id: Some(constants.ru_chain_id()), ..self }
230223
}
231224

232225
/// Sign the UnsignedFill, generating a SignedFill for each target chain.
@@ -264,13 +257,11 @@ impl<'a> UnsignedFill<'a> {
264257
let deadline = self.deadline.unwrap_or(now.timestamp() as u64 + 12);
265258

266259
// get the target order address
267-
let target_order_address = self
268-
.target_chains
269-
.get(&target_chain_id)
270-
.ok_or(SigningError::MissingOrderContract(target_chain_id))?;
260+
let target_order_address =
261+
self.target_chains.get(&target_chain_id).ok_or(SigningError::MissingConstants)?;
271262

272263
// get the rollup chain id, or throw an error if not set
273-
let ru_chain_id = self.ru_chain_id.ok_or(SigningError::MissingRollupChainId)?;
264+
let ru_chain_id = self.ru_chain_id.ok_or(SigningError::MissingConstants)?;
274265

275266
// get the outputs for the target chain from the AggregateOrders
276267
let outputs = self.orders.outputs_for(target_chain_id, ru_chain_id);

crates/types/src/signing/order.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'a> UnsignedOrder<'a> {
192192
}
193193

194194
/// Add the chain id and Order contract address to the UnsignedOrder.
195-
pub fn with_chain(self, constants: &SignetSystemConstants) -> Self {
195+
pub fn with_constants(self, constants: &SignetSystemConstants) -> Self {
196196
Self {
197197
rollup_chain_id: Some(constants.ru_chain_id()),
198198
rollup_order_address: Some(constants.ru_orders()),
@@ -217,9 +217,9 @@ impl<'a> UnsignedOrder<'a> {
217217
let nonce = self.nonce.unwrap_or(Utc::now().timestamp_micros() as u64);
218218

219219
// get chain id and order contract address
220-
let rollup_chain_id = self.rollup_chain_id.ok_or(SigningError::MissingChainId)?;
220+
let rollup_chain_id = self.rollup_chain_id.ok_or(SigningError::MissingConstants)?;
221221
let rollup_order_contract =
222-
self.rollup_order_address.ok_or(SigningError::MissingOrderContract(rollup_chain_id))?;
222+
self.rollup_order_address.ok_or(SigningError::MissingConstants)?;
223223

224224
// get the outputs for the Order
225225
let outputs = self.order.outputs().to_vec();

0 commit comments

Comments
 (0)