@@ -42,7 +42,7 @@ use pumpx::{
42
42
use signer_client:: { ChainType , SignerClient } ;
43
43
use std:: { collections:: HashMap , marker:: PhantomData , sync:: Arc } ;
44
44
use tokio:: sync:: { mpsc, oneshot} ;
45
- use tracing:: { debug, error, info, warn } ;
45
+ use tracing:: { debug, error, info} ;
46
46
47
47
pub use aes256_key_store:: Aes256KeyStore ;
48
48
pub use types:: { NativeTaskError , NativeTaskOk , PumpxApiError , PumpxSignerError } ;
@@ -217,66 +217,6 @@ fn get_supported_tokens() -> std::collections::HashMap<(u64, &'static str), Toke
217
217
tokens
218
218
}
219
219
220
- // Dynamic token discovery using Binance API
221
- // Fetch all available trading symbols from Binance to potentially expand supported tokens
222
- async fn discover_tokens_from_binance (
223
- binance_api : & dyn BinancePaymasterApi ,
224
- ) -> Result < Vec < String > , String > {
225
- binance_api
226
- . get_all_trading_symbols ( )
227
- . await
228
- . map_err ( |e| format ! ( "Failed to fetch trading symbols from Binance: {:?}" , e) )
229
- }
230
-
231
- // Enhanced token lookup that first checks hardcoded list, then attempts dynamic discovery
232
- async fn get_token_info_for_binance_enhanced (
233
- token_address : & Address ,
234
- chain_id : u64 ,
235
- binance_api_client : Option < & dyn BinancePaymasterApi > ,
236
- ) -> Option < ( String , u8 ) > {
237
- // First try the existing hardcoded lookup
238
- if let Some ( result) = get_token_info_from_mapping ( token_address, chain_id) . await {
239
- return Some ( result) ;
240
- }
241
-
242
- // If not found in hardcoded list and we have a Binance API client, try dynamic discovery
243
- if let Some ( binance_client) = binance_api_client {
244
- info ! ( "Token {} not found in hardcoded list, attempting dynamic discovery" , token_address) ;
245
-
246
- match discover_tokens_from_binance ( binance_client) . await {
247
- Ok ( symbols) => {
248
- // Look for common patterns that might match our token
249
- // This is a heuristic approach - in a real implementation you'd want a more sophisticated
250
- // mapping service that knows token symbols across different chains
251
- for symbol in symbols {
252
- // Look for ETH-based pairs (ETHUSDC, ETHUSDT, etc.)
253
- if symbol. starts_with ( "ETH" ) && symbol. len ( ) > 3 {
254
- let token_symbol = & symbol[ 3 ..] ; // Remove "ETH" prefix
255
-
256
- // Try to get decimals from the exchange
257
- if let Ok ( decimals) = binance_client. get_symbol_precision ( & symbol) . await {
258
- info ! (
259
- "Found potential token {} via dynamic discovery with symbol {} and {} decimals" ,
260
- token_address, token_symbol, decimals
261
- ) ;
262
- return Some ( ( symbol, decimals) ) ;
263
- }
264
- }
265
- }
266
- warn ! (
267
- "Dynamic discovery did not find a suitable match for token {}" ,
268
- token_address
269
- ) ;
270
- } ,
271
- Err ( e) => {
272
- warn ! ( "Dynamic token discovery failed: {}" , e) ;
273
- } ,
274
- }
275
- }
276
-
277
- None
278
- }
279
-
280
220
// Map token address to Binance symbol and return (symbol, decimals) from hardcoded mapping
281
221
async fn get_token_info_from_mapping (
282
222
token_address : & Address ,
@@ -362,11 +302,10 @@ async fn process_erc20_paymaster_data(
362
302
token_address, original_rate, valid_until, valid_after
363
303
) ;
364
304
365
- // Get token symbol and decimals for Binance API (with dynamic discovery fallback)
366
- let ( token_symbol, token_decimals) = match get_token_info_for_binance_enhanced (
305
+ // Get token symbol and decimals from hardcoded mapping
306
+ let ( token_symbol, token_decimals) = match get_token_info_from_mapping (
367
307
& token_address,
368
308
chain_id,
369
- Some ( binance_api) ,
370
309
)
371
310
. await
372
311
{
@@ -2482,36 +2421,6 @@ mod erc20_paymaster_tests {
2482
2421
assert_eq ! ( PAYMASTER_DATA_OFFSET , 52 ) ;
2483
2422
}
2484
2423
2485
- #[ cfg( feature = "mocks" ) ]
2486
- #[ test]
2487
- fn test_discover_tokens_from_binance ( ) {
2488
- use binance_api:: mocks:: MockBinanceApiClient ;
2489
- use binance_api:: BinancePaymasterApi ;
2490
-
2491
- let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
2492
- let mut mock_client = MockBinanceApiClient :: new ( ) ;
2493
-
2494
- // Mock the get_all_trading_symbols call
2495
- mock_client. expect_get_all_trading_symbols ( ) . times ( 1 ) . returning ( || {
2496
- Ok ( vec ! [
2497
- "ETHUSDC" . to_string( ) ,
2498
- "ETHUSDT" . to_string( ) ,
2499
- "ETHDAI" . to_string( ) ,
2500
- "BTCUSDT" . to_string( ) , // Should be ignored as it doesn't start with ETH
2501
- ] )
2502
- } ) ;
2503
-
2504
- let result = rt. block_on ( discover_tokens_from_binance ( & mock_client) ) ;
2505
- assert ! ( result. is_ok( ) ) ;
2506
-
2507
- let symbols = result. unwrap ( ) ;
2508
- assert_eq ! ( symbols. len( ) , 4 ) ;
2509
- assert ! ( symbols. contains( & "ETHUSDC" . to_string( ) ) ) ;
2510
- assert ! ( symbols. contains( & "ETHUSDT" . to_string( ) ) ) ;
2511
- assert ! ( symbols. contains( & "ETHDAI" . to_string( ) ) ) ;
2512
- assert ! ( symbols. contains( & "BTCUSDT" . to_string( ) ) ) ;
2513
- }
2514
-
2515
2424
#[ test]
2516
2425
fn test_paymaster_data_alignment_with_contract ( ) {
2517
2426
// This test ensures our format exactly matches ERC20PaymasterV1.sol
@@ -2564,86 +2473,6 @@ mod erc20_paymaster_tests {
2564
2473
assert_eq ! ( redecoded. 2 , until + 100 ) ; // Until updated
2565
2474
assert_eq ! ( redecoded. 3 , after + 100 ) ; // After updated
2566
2475
}
2567
-
2568
- #[ test]
2569
- fn test_get_token_info_for_binance_enhanced_hardcoded_mapping ( ) {
2570
- let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
2571
-
2572
- // Test USDC on Ethereum mainnet (should be found in hardcoded mapping)
2573
- // USDC address: 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
2574
- let usdc_address = Address :: from ( [
2575
- 0xa0 , 0xb8 , 0x69 , 0x91 , 0xc6 , 0x21 , 0x8b , 0x36 , 0xc1 , 0xd1 , 0x9d , 0x4a , 0x2e , 0x9e ,
2576
- 0xb0 , 0xce , 0x36 , 0x06 , 0xeb , 0x48 ,
2577
- ] ) ;
2578
- let result = rt. block_on ( get_token_info_for_binance_enhanced ( & usdc_address, 1 , None ) ) ;
2579
-
2580
- assert ! ( result. is_some( ) ) ;
2581
- let ( symbol, decimals) = result. unwrap ( ) ;
2582
- assert_eq ! ( symbol, "ETHUSDC" ) ;
2583
- assert_eq ! ( decimals, 6 ) ;
2584
- }
2585
-
2586
- #[ test]
2587
- fn test_get_token_info_for_binance_enhanced_unknown_token_no_api ( ) {
2588
- let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
2589
-
2590
- // Test unknown token without Binance API client
2591
- let unknown_address = Address :: from ( [ 0xFF ; 20 ] ) ;
2592
- let result = rt. block_on ( get_token_info_for_binance_enhanced ( & unknown_address, 1 , None ) ) ;
2593
-
2594
- assert ! ( result. is_none( ) ) ;
2595
- }
2596
-
2597
- #[ cfg( feature = "mocks" ) ]
2598
- #[ test]
2599
- fn test_get_token_info_for_binance_enhanced_unknown_token_with_api ( ) {
2600
- use binance_api:: mocks:: MockBinanceApiClient ;
2601
- use binance_api:: BinancePaymasterApi ;
2602
-
2603
- let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
2604
- let mut mock_client = MockBinanceApiClient :: new ( ) ;
2605
-
2606
- // Mock the get_all_trading_symbols call to return some example symbols
2607
- mock_client. expect_get_all_trading_symbols ( ) . times ( 1 ) . returning ( || {
2608
- Ok ( vec ! [ "ETHUSDC" . to_string( ) , "ETHUSDT" . to_string( ) , "ETHDAI" . to_string( ) ] )
2609
- } ) ;
2610
-
2611
- // Test unknown token with Binance API client
2612
- let unknown_address = Address :: from ( [ 0xFF ; 20 ] ) ;
2613
- let result = rt. block_on ( get_token_info_for_binance_enhanced (
2614
- & unknown_address,
2615
- 1 ,
2616
- Some ( & mock_client as & dyn BinancePaymasterApi ) ,
2617
- ) ) ;
2618
-
2619
- // Should still return None as dynamic discovery would need actual token contract calls
2620
- // which are not implemented in this simple mock test
2621
- assert ! ( result. is_none( ) ) ;
2622
- }
2623
-
2624
- #[ test]
2625
- fn test_get_token_info_for_binance_enhanced_different_chains ( ) {
2626
- let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
2627
-
2628
- // Test USDC on Arbitrum (should be found in hardcoded mapping)
2629
- // USDC Arbitrum address: 0xaf88d065e77c8cc2239327c5edb3a432268e5831
2630
- let usdc_arbitrum_address = Address :: from ( [
2631
- 0xaf , 0x88 , 0xd0 , 0x65 , 0xe7 , 0x7c , 0x8c , 0xc2 , 0x23 , 0x93 , 0x27 , 0xc5 , 0xed , 0xb3 ,
2632
- 0xa4 , 0x32 , 0x26 , 0x8e , 0x58 , 0x31 ,
2633
- ] ) ;
2634
- let result =
2635
- rt. block_on ( get_token_info_for_binance_enhanced ( & usdc_arbitrum_address, 42161 , None ) ) ;
2636
-
2637
- assert ! ( result. is_some( ) ) ;
2638
- let ( symbol, decimals) = result. unwrap ( ) ;
2639
- assert_eq ! ( symbol, "ETHUSDC" ) ;
2640
- assert_eq ! ( decimals, 6 ) ;
2641
-
2642
- // Test same address on different chain (should return None)
2643
- let result_wrong_chain =
2644
- rt. block_on ( get_token_info_for_binance_enhanced ( & usdc_arbitrum_address, 1 , None ) ) ;
2645
- assert ! ( result_wrong_chain. is_none( ) ) ;
2646
- }
2647
2476
}
2648
2477
2649
2478
#[ cfg( test) ]
0 commit comments