11use crate :: signing:: { permit_signing_info, SignedPermitError , SigningError } ;
22use 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} ;
99use chrono:: Utc ;
1010use serde:: { Deserialize , Serialize } ;
11+ use signet_constants:: SignetSystemConstants ;
1112use signet_zenith:: RollupOrders :: {
12- initiatePermit2Call, Order , Output , Permit2Batch , TokenPermissions ,
13+ initiatePermit2Call, Input , Order , Output , Permit2Batch , TokenPermissions ,
1314} ;
1415use 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 ) ]
116118pub struct UnsignedOrder < ' a > {
117119 order : Cow < ' a , Order > ,
118120 nonce : Option < u64 > ,
@@ -122,14 +124,56 @@ pub struct UnsignedOrder<'a> {
122124
123125impl < ' 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
129131impl < ' 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 }
0 commit comments