@@ -41,6 +41,7 @@ use heima_authentication::auth_token::AUTH_TOKEN_ACCESS_TYPE;
41
41
use rust_decimal:: prelude:: * ;
42
42
use rust_decimal:: Decimal ;
43
43
use solana:: { signer:: RemoteSigner , SolanaClient } ;
44
+ use std:: str:: FromStr ;
44
45
use tokio:: {
45
46
runtime:: Handle ,
46
47
time:: { sleep, Duration } ,
@@ -437,6 +438,15 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
437
438
log:: error!( "Could not get from_wallet from pumpx-signer: {:?}" , e)
438
439
} ) ?;
439
440
441
+ let from_address = match from_chain_type {
442
+ ChainType :: Evm => pubkey_to_evm_address ( & from_wallet_address) ?,
443
+ ChainType :: Solana => pubkey_to_solana_address ( & from_wallet_address) ?,
444
+ _ => {
445
+ log:: error!( "Unsupported {:?} wallet address" , from_chain_type) ;
446
+ return Err ( ( ) ) ;
447
+ } ,
448
+ } ;
449
+
440
450
let to_wallet_address = self
441
451
. pumpx_signer_client
442
452
. request_wallet (
@@ -449,11 +459,11 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
449
459
log:: error!( "Could not get to_wallet from pumpx-signer: {:?}" , e)
450
460
} ) ?;
451
461
452
- let from_address = match from_chain_type {
453
- ChainType :: Evm => pubkey_to_evm_address ( & from_wallet_address ) ?,
454
- ChainType :: Solana => pubkey_to_solana_address ( & from_wallet_address ) ?,
462
+ let to_address = match to_chain_type {
463
+ ChainType :: Evm => pubkey_to_evm_address ( & to_wallet_address ) ?,
464
+ ChainType :: Solana => pubkey_to_solana_address ( & to_wallet_address ) ?,
455
465
_ => {
456
- log:: error!( "Unsupported {:?} wallet address" , from_chain_type ) ;
466
+ log:: error!( "Unsupported {:?} wallet address" , to_chain_type ) ;
457
467
return Err ( ( ) ) ;
458
468
} ,
459
469
} ;
@@ -633,6 +643,8 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
633
643
}
634
644
635
645
debug ! ( "Waiting for deposit to be confirmed on Binance..." ) ;
646
+ debug ! ( "Deposit tx_id: {:?}" , tx_id) ;
647
+ debug ! ( "Source address: {:?}" , from_address) ;
636
648
let mut deposit_confirmed = false ;
637
649
let start_time = std:: time:: Instant :: now ( ) ;
638
650
let timeout = Duration :: from_secs ( 300 ) ; // 5 minute timeout
@@ -650,13 +662,7 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
650
662
651
663
// Check if there's a recent successful deposit
652
664
for deposit in deposit_history {
653
- let deposit_amount: u64 = match Decimal :: from_str ( & deposit. amount ) {
654
- Ok ( deposit_amount) => deposit_amount. to_u64 ( ) . unwrap_or ( 0 ) ,
655
- Err ( _) => {
656
- log:: error!( "Failed to parse deposit amount" ) ;
657
- continue ;
658
- } ,
659
- } ;
665
+ debug ! ( "Deposit: {:?}" , deposit) ;
660
666
if deposit. status == 2 || deposit. status == 7 {
661
667
// 2 = rejected, 7 = Wrong Deposit
662
668
log:: error!( "Deposit failed with status: {}" , deposit. status) ;
@@ -677,8 +683,7 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
677
683
if deposit. status == 1 && // 1 = success
678
684
deposit. coin == binance_coin_name &&
679
685
deposit. network == binance_network_info. network &&
680
- deposit. source_address == Some ( from_address. clone ( ) ) &&
681
- deposit_amount == amount_to_transfer
686
+ deposit. source_address == Some ( from_address. clone ( ) )
682
687
{
683
688
deposit_confirmed = true ;
684
689
debug ! (
@@ -687,6 +692,7 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
687
692
) ;
688
693
break ;
689
694
}
695
+ debug ! ( "Deposit not confirmed yet, status: {}" , deposit. status) ;
690
696
}
691
697
692
698
if !deposit_confirmed {
@@ -856,7 +862,9 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
856
862
857
863
debug ! ( "Total received {} bnb" , bnb_received) ;
858
864
859
- let payout_address: Address = Address :: from_slice ( & to_wallet_address) ;
865
+ let payout_address = Address :: from_str ( & to_address) . map_err ( |_| {
866
+ log:: error!( "Failed to parse payout address" ) ;
867
+ } ) ?;
860
868
let payout_amount = match str_to_u256 ( & bnb_received, 18 ) {
861
869
Some ( a) => a,
862
870
None => {
@@ -885,6 +893,7 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
885
893
) ?;
886
894
887
895
debug ! ( "Received {:?} nonce" , user_nonce) ;
896
+ let user_nonce = user_nonce + U256 :: from ( 1u64 ) ;
888
897
debug ! ( "Calling accounting contract payout with address {:?}, nonce {:?} and amount {:?}" , payout_address, user_nonce, payout_amount) ;
889
898
890
899
self . accounting_contract_client
@@ -895,31 +904,43 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
895
904
} ) ?;
896
905
897
906
debug ! ( "Calling pumpx get_gas_info, chain_id: {}" , pumpx_config. to_chain_id) ;
898
- let gas_info = self
907
+ let res = self
899
908
. pumpx_api
900
909
. get_gas_info ( & access_token, pumpx_config. to_chain_id )
901
910
. await
902
911
. map_err ( |_| {
903
912
log:: error!( "Failed to get gas info" ) ;
904
913
} ) ?;
905
- debug ! ( "Response get_gas_info: {:?}" , gas_info ) ;
914
+ debug ! ( "Response get_gas_info: {:?}" , res ) ;
906
915
907
- let Some ( gas_info_data) = gas_info . data else {
916
+ let Some ( gas_info_data) = res . data else {
908
917
log:: error!( "Response data of call get gas info is none" ) ;
909
918
return Err ( ( ) ) ;
910
919
} ;
920
+ let Some ( gas_info) = gas_info_data
921
+ . gas_info
922
+ . iter ( )
923
+ . find ( |g| g. chain_id == pumpx_config. to_chain_id . to_string ( ) )
924
+ else {
925
+ log:: error!(
926
+ "Could not find matching gas_info with chain_id {}" ,
927
+ pumpx_config. to_chain_id
928
+ ) ;
929
+ return Err ( ( ) ) ;
930
+ } ;
931
+
911
932
let gas_fee = match pumpx_config. gas_type {
912
- 1 => gas_info_data . gas_info . normal ,
913
- 2 => gas_info_data . gas_info . fast ,
914
- 3 => gas_info_data . gas_info . super_fast ,
933
+ 1 => & gas_info. normal ,
934
+ 2 => & gas_info. fast ,
935
+ 3 => & gas_info. super_fast ,
915
936
_ => {
916
937
log:: error!( "Unsupported gas type: {}" , pumpx_config. gas_type) ;
917
938
return Err ( ( ) ) ;
918
939
} ,
919
940
} ;
920
941
debug ! ( "Gas fee for chain_id {} is {}" , pumpx_config. to_chain_id, gas_fee) ;
921
942
922
- let amount_in = match calculate_amount_in ( & bnb_received, & gas_fee) {
943
+ let amount_in = match calculate_amount_in ( & bnb_received, gas_fee) {
923
944
Some ( a) => a,
924
945
None => {
925
946
log:: error!(
0 commit comments