@@ -66,6 +66,8 @@ pub struct RestingOrder {
6666 pub output_amount : U256 ,
6767 pub nonce : U256 ,
6868 pub deadline_sec : u64 ,
69+ pub additional_validation_contract : Address ,
70+ pub additional_validation_data : Bytes ,
6971 /// 65-byte EIP-712 signature over the Permit2 witness digest.
7072 pub signature : Vec < u8 > ,
7173}
@@ -85,6 +87,8 @@ impl RestingOrder {
8587 output_token : self . output_token ,
8688 output_amount : self . output_amount ,
8789 recipient : self . maker ,
90+ additional_validation_contract : self . additional_validation_contract ,
91+ additional_validation_data : self . additional_validation_data . clone ( ) ,
8892 }
8993 }
9094}
@@ -109,6 +113,11 @@ fn parse_signature_field(v: &Value) -> Option<Vec<u8>> {
109113 ( bytes. len ( ) == 65 ) . then_some ( bytes)
110114}
111115
116+ fn parse_bytes_field ( v : & Value ) -> Option < Bytes > {
117+ let value = v. as_str ( ) ?;
118+ alloy_primitives:: hex:: decode ( value) . ok ( ) . map ( Bytes :: from)
119+ }
120+
112121/// Parse the `restingLimitOrders` response rows; malformed rows are dropped
113122/// (they can only have come from a broken or hostile indexer).
114123pub fn parse_resting_orders ( rows : & Value ) -> Vec < RestingOrder > {
@@ -126,6 +135,14 @@ pub fn parse_resting_orders(rows: &Value) -> Vec<RestingOrder> {
126135 output_amount : parse_u256_field ( row. get ( "outputAmount" ) ?) ?,
127136 nonce : parse_u256_field ( row. get ( "nonce" ) ?) ?,
128137 deadline_sec : parse_u256_field ( row. get ( "deadlineSec" ) ?) ?. try_into ( ) . ok ( ) ?,
138+ additional_validation_contract : row
139+ . get ( "additionalValidationContract" )
140+ . and_then ( parse_address_field)
141+ . unwrap_or ( Address :: ZERO ) ,
142+ additional_validation_data : row
143+ . get ( "additionalValidationData" )
144+ . and_then ( parse_bytes_field)
145+ . unwrap_or_default ( ) ,
129146 signature : parse_signature_field ( row. get ( "signature" ) ?) ?,
130147 } )
131148 } )
@@ -294,7 +311,9 @@ fn word_address(a: Address) -> [u8; 32] {
294311/// encoding locally from verified fields is what keeps a hostile indexer's
295312/// `encodedOrder` out of the transaction entirely.
296313pub fn encode_order_bytes ( o : & OrderParams ) -> Vec < u8 > {
297- let mut out = Vec :: with_capacity ( 17 * 32 ) ;
314+ let validation_data = padded_bytes ( & o. additional_validation_data ) ;
315+ let info_size = 6 * 32 + validation_data. len ( ) ;
316+ let mut out = Vec :: with_capacity ( 10 * 32 + info_size) ;
298317 out. extend_from_slice ( & word_usize ( 0x20 ) ) ; // offset to the tuple
299318
300319 // Tuple head: [info offset, input.token, input.amount, input.maxAmount,
@@ -304,16 +323,16 @@ pub fn encode_order_bytes(o: &OrderParams) -> Vec<u8> {
304323 out. extend_from_slice ( & word_address ( o. input_token ) ) ;
305324 out. extend_from_slice ( & word_u256 ( o. input_amount ) ) ;
306325 out. extend_from_slice ( & word_u256 ( o. input_amount ) ) ; // maxAmount == amount
307- out. extend_from_slice ( & word_usize ( 5 * 32 + 7 * 32 ) ) ; // outputs after info
326+ out. extend_from_slice ( & word_usize ( 5 * 32 + info_size ) ) ; // outputs after info
308327
309- // OrderInfo: 5 static words + offset to empty `additionalValidationData`.
328+ // OrderInfo: 5 static words + offset to `additionalValidationData`.
310329 out. extend_from_slice ( & word_address ( o. reactor ) ) ;
311330 out. extend_from_slice ( & word_address ( o. swapper ) ) ;
312331 out. extend_from_slice ( & word_u256 ( o. nonce ) ) ;
313332 out. extend_from_slice ( & word_u256 ( o. deadline ) ) ;
314- out. extend_from_slice ( & word_address ( Address :: ZERO ) ) ;
333+ out. extend_from_slice ( & word_address ( o . additional_validation_contract ) ) ;
315334 out. extend_from_slice ( & word_usize ( 6 * 32 ) ) ; // bytes offset within info
316- out. extend_from_slice ( & word_usize ( 0 ) ) ; // len(additionalValidationData)
335+ out. extend_from_slice ( & validation_data ) ;
317336
318337 // OutputToken[1]
319338 out. extend_from_slice ( & word_usize ( 1 ) ) ;
@@ -476,6 +495,7 @@ async fn take_direction_once(
476495 chain_id,
477496 & input_token. to_string ( ) ,
478497 & output_token. to_string ( ) ,
498+ & wallet. address ( ) . to_string ( ) ,
479499 )
480500 . await ?;
481501 let orders = parse_resting_orders ( & rows) ;
@@ -648,6 +668,8 @@ mod tests {
648668 output_amount : U256 :: from ( 1_000_000u64 ) ,
649669 nonce : U256 :: from ( 42u64 ) ,
650670 deadline_sec,
671+ additional_validation_contract : Address :: ZERO ,
672+ additional_validation_data : Default :: default ( ) ,
651673 signature : vec ! [ ] ,
652674 } ;
653675 let digest = permit2_digest ( & order. params ( ) , PERMIT2 , CHAIN ) ;
@@ -834,6 +856,8 @@ mod tests {
834856 output_token : CNGN ,
835857 output_amount : U256 :: from ( 1_550_000_000u64 ) ,
836858 recipient : address ! ( "2222222222222222222222222222222222222222" ) ,
859+ additional_validation_contract : Address :: ZERO ,
860+ additional_validation_data : Default :: default ( ) ,
837861 }
838862 }
839863
0 commit comments