@@ -19,13 +19,20 @@ use {
1919 BidStatus ,
2020 ChainStoreEvm ,
2121 ChainStoreSvm ,
22+ ExpressRelaySvm ,
23+ PermissionKey ,
2224 SimulatedBid ,
2325 Store ,
2426 } ,
2527 traced_client:: TracedClient ,
2628 } ,
27- :: express_relay as express_relay_svm,
28- anchor_lang:: Discriminator ,
29+ :: express_relay:: {
30+ self as express_relay_svm,
31+ } ,
32+ anchor_lang:: {
33+ AnchorDeserialize ,
34+ Discriminator ,
35+ } ,
2936 anyhow:: {
3037 anyhow,
3138 Result ,
8289 Deserializer ,
8390 Serialize ,
8491 } ,
85- solana_sdk:: transaction:: VersionedTransaction ,
92+ solana_sdk:: {
93+ instruction:: CompiledInstruction ,
94+ pubkey:: Pubkey ,
95+ transaction:: VersionedTransaction ,
96+ } ,
8697 sqlx:: types:: time:: OffsetDateTime ,
8798 std:: {
8899 result,
@@ -880,8 +891,8 @@ pub async fn run_tracker_loop(store: Arc<Store>, chain_id: String) -> Result<()>
880891pub fn verify_submit_bid_instruction_svm (
881892 chain_store : & ChainStoreSvm ,
882893 transaction : VersionedTransaction ,
883- ) -> Result < ( ) , RestError > {
884- if transaction
894+ ) -> Result < CompiledInstruction , RestError > {
895+ let submit_bid_instructions : Vec < CompiledInstruction > = transaction
885896 . message
886897 . instructions ( )
887898 . iter ( )
@@ -895,15 +906,69 @@ pub fn verify_submit_bid_instruction_svm(
895906 . data
896907 . starts_with ( & express_relay_svm:: instruction:: SubmitBid :: discriminator ( ) )
897908 } )
898- . count ( )
899- != 1
900- {
901- return Err ( RestError :: BadParameters (
909+ . cloned ( )
910+ . collect ( ) ;
911+
912+ match submit_bid_instructions. len ( ) {
913+ 1 => Ok ( submit_bid_instructions[ 0 ] . clone ( ) ) ,
914+ _ => Err ( RestError :: BadParameters (
902915 "Bid has to include exactly one submit_bid instruction to Express Relay program"
903916 . to_string ( ) ,
904- ) ) ;
917+ ) ) ,
905918 }
906- Ok ( ( ) )
919+ }
920+
921+ fn extract_account_svm (
922+ accounts : & [ Pubkey ] ,
923+ instruction : CompiledInstruction ,
924+ position : usize ,
925+ ) -> Result < Pubkey , RestError > {
926+ let account_position = instruction. accounts . get ( position) . ok_or_else ( || {
927+ tracing:: error!(
928+ "Account position not found in instruction: {:?} - {}" ,
929+ instruction,
930+ position,
931+ ) ;
932+ RestError :: BadParameters ( "Account not found in submit_bid instruction" . to_string ( ) )
933+ } ) ?;
934+
935+ let account_position: usize = ( * account_position) . into ( ) ;
936+ let account = accounts. get ( account_position) . ok_or_else ( || {
937+ tracing:: error!(
938+ "Account not found in transaction accounts: {:?} - {}" ,
939+ accounts,
940+ account_position,
941+ ) ;
942+ RestError :: BadParameters ( "Account not found in transaction accounts" . to_string ( ) )
943+ } ) ?;
944+
945+ Ok ( * account)
946+ }
947+
948+ fn extract_bid_data_svm (
949+ express_relay_svm : ExpressRelaySvm ,
950+ accounts : & [ Pubkey ] ,
951+ instruction : CompiledInstruction ,
952+ ) -> Result < ( u64 , PermissionKey ) , RestError > {
953+ let discriminator = express_relay_svm:: instruction:: SubmitBid :: discriminator ( ) ;
954+ let submit_bid_data = express_relay_svm:: SubmitBidArgs :: try_from_slice (
955+ & instruction. data . as_slice ( ) [ discriminator. len ( ) ..] ,
956+ )
957+ . map_err ( |e| RestError :: BadParameters ( format ! ( "Invalid submit_bid instruction data: {}" , e) ) ) ?;
958+
959+ let permission_account = extract_account_svm (
960+ accounts,
961+ instruction. clone ( ) ,
962+ express_relay_svm. permission_account_position ,
963+ ) ?;
964+ let router_account = extract_account_svm (
965+ accounts,
966+ instruction. clone ( ) ,
967+ express_relay_svm. router_account_position ,
968+ ) ?;
969+
970+ let concat = [ permission_account. to_bytes ( ) , router_account. to_bytes ( ) ] . concat ( ) ;
971+ Ok ( ( submit_bid_data. bid_amount , concat. into ( ) ) )
907972}
908973
909974#[ tracing:: instrument( skip_all) ]
@@ -918,7 +983,13 @@ pub async fn handle_bid_svm(
918983 . get ( & bid. chain_id )
919984 . ok_or ( RestError :: InvalidChainId ) ?;
920985
921- verify_submit_bid_instruction_svm ( chain_store, bid. transaction . clone ( ) ) ?;
986+ let submit_bid_instruction =
987+ verify_submit_bid_instruction_svm ( chain_store, bid. transaction . clone ( ) ) ?;
988+ let ( _bid_amount, _permission_key) = extract_bid_data_svm (
989+ store. express_relay_svm . clone ( ) ,
990+ bid. transaction . message . static_account_keys ( ) ,
991+ submit_bid_instruction,
992+ ) ?;
922993
923994 // TODO implement this
924995 Err ( RestError :: NotImplemented )
0 commit comments