@@ -19,13 +19,20 @@ use {
19
19
BidStatus ,
20
20
ChainStoreEvm ,
21
21
ChainStoreSvm ,
22
+ ExpressRelaySvm ,
23
+ PermissionKey ,
22
24
SimulatedBid ,
23
25
Store ,
24
26
} ,
25
27
traced_client:: TracedClient ,
26
28
} ,
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
+ } ,
29
36
anyhow:: {
30
37
anyhow,
31
38
Result ,
82
89
Deserializer ,
83
90
Serialize ,
84
91
} ,
85
- solana_sdk:: transaction:: VersionedTransaction ,
92
+ solana_sdk:: {
93
+ instruction:: CompiledInstruction ,
94
+ pubkey:: Pubkey ,
95
+ transaction:: VersionedTransaction ,
96
+ } ,
86
97
sqlx:: types:: time:: OffsetDateTime ,
87
98
std:: {
88
99
result,
@@ -880,8 +891,8 @@ pub async fn run_tracker_loop(store: Arc<Store>, chain_id: String) -> Result<()>
880
891
pub fn verify_submit_bid_instruction_svm (
881
892
chain_store : & ChainStoreSvm ,
882
893
transaction : VersionedTransaction ,
883
- ) -> Result < ( ) , RestError > {
884
- if transaction
894
+ ) -> Result < CompiledInstruction , RestError > {
895
+ let submit_bid_instructions : Vec < CompiledInstruction > = transaction
885
896
. message
886
897
. instructions ( )
887
898
. iter ( )
@@ -895,15 +906,69 @@ pub fn verify_submit_bid_instruction_svm(
895
906
. data
896
907
. starts_with ( & express_relay_svm:: instruction:: SubmitBid :: discriminator ( ) )
897
908
} )
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 (
902
915
"Bid has to include exactly one submit_bid instruction to Express Relay program"
903
916
. to_string ( ) ,
904
- ) ) ;
917
+ ) ) ,
905
918
}
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 ( ) ) )
907
972
}
908
973
909
974
#[ tracing:: instrument( skip_all) ]
@@ -918,7 +983,13 @@ pub async fn handle_bid_svm(
918
983
. get ( & bid. chain_id )
919
984
. ok_or ( RestError :: InvalidChainId ) ?;
920
985
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
+ ) ?;
922
993
923
994
// TODO implement this
924
995
Err ( RestError :: NotImplemented )
0 commit comments