@@ -58,13 +58,61 @@ impl Default for FeePayerBalanceMetricsConfig {
5858 }
5959}
6060
61+ #[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
62+ pub enum SplTokenConfig {
63+ All ,
64+ #[ serde( untagged) ]
65+ Allowlist ( Vec < String > ) ,
66+ }
67+
68+ impl Default for SplTokenConfig {
69+ fn default ( ) -> Self {
70+ SplTokenConfig :: Allowlist ( vec ! [ ] )
71+ }
72+ }
73+
74+ impl < ' a > IntoIterator for & ' a SplTokenConfig {
75+ type Item = & ' a String ;
76+ type IntoIter = std:: slice:: Iter < ' a , String > ;
77+
78+ fn into_iter ( self ) -> Self :: IntoIter {
79+ match self {
80+ SplTokenConfig :: All => [ ] . iter ( ) ,
81+ SplTokenConfig :: Allowlist ( tokens) => tokens. iter ( ) ,
82+ }
83+ }
84+ }
85+
86+ impl SplTokenConfig {
87+ pub fn has_token ( & self , token : & str ) -> bool {
88+ match self {
89+ SplTokenConfig :: All => true ,
90+ SplTokenConfig :: Allowlist ( tokens) => tokens. iter ( ) . any ( |s| s == token) ,
91+ }
92+ }
93+
94+ pub fn has_tokens ( & self ) -> bool {
95+ match self {
96+ SplTokenConfig :: All => true ,
97+ SplTokenConfig :: Allowlist ( tokens) => !tokens. is_empty ( ) ,
98+ }
99+ }
100+
101+ pub fn as_slice ( & self ) -> & [ String ] {
102+ match self {
103+ SplTokenConfig :: All => & [ ] ,
104+ SplTokenConfig :: Allowlist ( v) => v. as_slice ( ) ,
105+ }
106+ }
107+ }
108+
61109#[ derive( Debug , Clone , Serialize , Deserialize , ToSchema ) ]
62110pub struct ValidationConfig {
63111 pub max_allowed_lamports : u64 ,
64112 pub max_signatures : u64 ,
65113 pub allowed_programs : Vec < String > ,
66114 pub allowed_tokens : Vec < String > ,
67- pub allowed_spl_paid_tokens : Vec < String > ,
115+ pub allowed_spl_paid_tokens : SplTokenConfig ,
68116 pub disallowed_accounts : Vec < String > ,
69117 pub price_source : PriceSource ,
70118 #[ serde( default ) ] // Default for backward compatibility
@@ -81,7 +129,7 @@ impl ValidationConfig {
81129 }
82130
83131 pub fn supports_token ( & self , token : & str ) -> bool {
84- self . allowed_spl_paid_tokens . iter ( ) . any ( |s| s == token)
132+ self . allowed_spl_paid_tokens . has_token ( token)
85133 }
86134}
87135
@@ -378,7 +426,7 @@ mod tests {
378426 let config = ConfigBuilder :: new ( )
379427 . with_programs ( vec ! [ "program1" , "program2" ] )
380428 . with_tokens ( vec ! [ "token1" , "token2" ] )
381- . with_spl_paid_tokens ( vec ! [ "token3" ] )
429+ . with_spl_paid_tokens ( SplTokenConfig :: Allowlist ( vec ! [ "token3" . to_string ( ) ] ) )
382430 . with_disallowed_accounts ( vec ! [ "account1" ] )
383431 . build_config ( )
384432 . unwrap ( ) ;
@@ -387,7 +435,10 @@ mod tests {
387435 assert_eq ! ( config. validation. max_signatures, 10 ) ;
388436 assert_eq ! ( config. validation. allowed_programs, vec![ "program1" , "program2" ] ) ;
389437 assert_eq ! ( config. validation. allowed_tokens, vec![ "token1" , "token2" ] ) ;
390- assert_eq ! ( config. validation. allowed_spl_paid_tokens, vec![ "token3" ] ) ;
438+ assert_eq ! (
439+ config. validation. allowed_spl_paid_tokens,
440+ SplTokenConfig :: Allowlist ( vec![ "token3" . to_string( ) ] )
441+ ) ;
391442 assert_eq ! ( config. validation. disallowed_accounts, vec![ "account1" ] ) ;
392443 assert_eq ! ( config. validation. price_source, PriceSource :: Jupiter ) ;
393444 assert_eq ! ( config. kora. rate_limit, 100 ) ;
@@ -400,7 +451,7 @@ mod tests {
400451 let config = ConfigBuilder :: new ( )
401452 . with_programs ( vec ! [ "program1" , "program2" ] )
402453 . with_tokens ( vec ! [ "token1" , "token2" ] )
403- . with_spl_paid_tokens ( vec ! [ "token3" ] )
454+ . with_spl_paid_tokens ( SplTokenConfig :: Allowlist ( vec ! [ "token3" . to_string ( ) ] ) )
404455 . with_disallowed_accounts ( vec ! [ "account1" ] )
405456 . with_enabled_methods ( & [
406457 ( "liveness" , true ) ,
@@ -441,6 +492,14 @@ mod tests {
441492 assert ! ( result. is_err( ) ) ;
442493 }
443494
495+ #[ test]
496+ fn test_parse_spl_payment_config ( ) {
497+ let config =
498+ ConfigBuilder :: new ( ) . with_spl_paid_tokens ( SplTokenConfig :: All ) . build_config ( ) . unwrap ( ) ;
499+
500+ assert_eq ! ( config. validation. allowed_spl_paid_tokens, SplTokenConfig :: All ) ;
501+ }
502+
444503 #[ test]
445504 fn test_parse_margin_price_config ( ) {
446505 let config = ConfigBuilder :: new ( ) . with_margin_price ( 0.1 ) . build_config ( ) . unwrap ( ) ;
0 commit comments