11use crate :: agg:: AggregateOrders ;
22use crate :: signing:: { permit_signing_info, SignedPermitError , SigningError } ;
3+ use crate :: SignedOrder ;
34use alloy:: {
45 network:: TransactionBuilder , primitives:: Address , rpc:: types:: TransactionRequest ,
56 signers:: Signer , sol_types:: SolCall ,
67} ;
78use chrono:: Utc ;
89use serde:: { Deserialize , Serialize } ;
10+ use signet_constants:: SignetSystemConstants ;
11+ use signet_zenith:: RollupOrders :: Order ;
912use signet_zenith:: {
1013 BundleHelper :: { FillPermit2 , IOrders } ,
1114 RollupOrders :: { fillPermit2Call, Output , Permit2Batch , TokenPermissions } ,
@@ -110,7 +113,8 @@ impl From<&SignedFill> for FillPermit2 {
110113 }
111114}
112115
113- /// An UnsignedFill is a helper type used to easily transform an AggregateOrder into a single SignedFill with correct permit2 semantics.
116+ /// An [`UnsignedFill`] is a builder type used to easily transform [`Order`]s
117+ /// or [`AggregateOrders`] into a [`SignedFill`] with correct permit2 semantics.
114118#[ derive( Clone , Debug , Deserialize , Serialize , PartialEq , Eq ) ]
115119pub struct UnsignedFill < ' a > {
116120 /// The rollup chain id from which the Orders originated.
@@ -126,24 +130,80 @@ pub struct UnsignedFill<'a> {
126130 target_chains : HashMap < u64 , Address > ,
127131}
128132
133+ impl Default for UnsignedFill < ' _ > {
134+ fn default ( ) -> Self {
135+ Self {
136+ ru_chain_id : None ,
137+ orders : Cow :: Owned ( AggregateOrders :: default ( ) ) ,
138+ deadline : None ,
139+ nonce : None ,
140+ target_chains : HashMap :: new ( ) ,
141+ }
142+ }
143+ }
144+
129145impl < ' a > From < & ' a AggregateOrders > for UnsignedFill < ' a > {
130146 fn from ( orders : & ' a AggregateOrders ) -> Self {
131- UnsignedFill :: new ( orders)
147+ Self {
148+ ru_chain_id : None ,
149+ orders : Cow :: Borrowed ( orders) ,
150+ deadline : None ,
151+ nonce : None ,
152+ target_chains : HashMap :: new ( ) ,
153+ }
154+ }
155+ }
156+
157+ impl From < Order > for UnsignedFill < ' static > {
158+ fn from ( order : Order ) -> Self {
159+ let mut aggregate_orders = AggregateOrders :: default ( ) ;
160+ aggregate_orders. ingest ( & order) ;
161+ Self {
162+ ru_chain_id : None ,
163+ orders : Cow :: Owned ( aggregate_orders) ,
164+ deadline : None ,
165+ nonce : None ,
166+ target_chains : HashMap :: new ( ) ,
167+ }
132168 }
133169}
134170
135171impl < ' a > UnsignedFill < ' a > {
136- /// Get a new UnsignedFill from a set of AggregateOrders.
137- pub fn new ( orders : & ' a AggregateOrders ) -> Self {
172+ /// Get a new UnsignedFill from a set of [` AggregateOrders`] .
173+ pub fn new ( ) -> Self {
138174 Self {
139175 ru_chain_id : None ,
140- orders : orders . into ( ) ,
176+ orders : Cow :: Owned ( AggregateOrders :: default ( ) ) ,
141177 deadline : None ,
142178 nonce : None ,
143179 target_chains : HashMap :: new ( ) ,
144180 }
145181 }
146182
183+ /// Add an [`Order`] to the [`UnsignedFill`].
184+ pub fn fill_raw ( mut self , order : & Order ) -> UnsignedFill < ' static > {
185+ self . orders . to_mut ( ) . ingest ( order) ;
186+ UnsignedFill {
187+ ru_chain_id : self . ru_chain_id ,
188+ orders : Cow :: Owned ( self . orders . into_owned ( ) ) ,
189+ deadline : self . deadline ,
190+ nonce : self . nonce ,
191+ target_chains : self . target_chains ,
192+ }
193+ }
194+
195+ /// Add a [`SignedOrder`] to the [`UnsignedFill`].
196+ pub fn fill ( mut self , order : & SignedOrder ) -> UnsignedFill < ' static > {
197+ self . orders . to_mut ( ) . ingest_signed ( order) ;
198+ UnsignedFill {
199+ ru_chain_id : self . ru_chain_id ,
200+ orders : Cow :: Owned ( self . orders . into_owned ( ) ) ,
201+ deadline : self . deadline ,
202+ nonce : self . nonce ,
203+ target_chains : self . target_chains ,
204+ }
205+ }
206+
147207 /// Add a Permit2 nonce to the UnsignedFill.
148208 pub fn with_nonce ( self , nonce : u64 ) -> Self {
149209 Self { nonce : Some ( nonce) , ..self }
@@ -163,8 +223,9 @@ impl<'a> UnsignedFill<'a> {
163223 }
164224
165225 /// Add the chain id and Order contract address to the UnsignedFill.
166- pub fn with_chain ( mut self , chain_id : u64 , order_contract_address : Address ) -> Self {
167- self . target_chains . insert ( chain_id, order_contract_address) ;
226+ pub fn with_chain ( mut self , constants : SignetSystemConstants ) -> Self {
227+ self . target_chains . insert ( constants. ru_chain_id ( ) , constants. ru_orders ( ) ) ;
228+ self . target_chains . insert ( constants. host_chain_id ( ) , constants. host_orders ( ) ) ;
168229 self
169230 }
170231
0 commit comments