@@ -3,9 +3,8 @@ use wormhole_svm_definitions::make_anchor_discriminator;
3
3
4
4
use crate :: ID ;
5
5
6
- use super :: close_fast_market_order:: close_fast_market_order;
7
6
use super :: execute_order:: handle_execute_order_shim;
8
- use super :: initialize_fast_market_order:: { self , InitializeFastMarketOrderData } ;
7
+ use super :: initialize_fast_market_order:: InitializeFastMarketOrderData ;
9
8
use super :: place_initial_offer:: { place_initial_offer_cctp_shim, PlaceInitialOfferCctpShimData } ;
10
9
use super :: prepare_order_response:: {
11
10
prepare_order_response_cctp_shim, PrepareOrderResponseCctpShimData ,
@@ -29,6 +28,7 @@ impl<'ix> FallbackMatchingEngineInstruction<'ix> {
29
28
pub enum FallbackMatchingEngineInstruction < ' ix > {
30
29
InitializeFastMarketOrder ( & ' ix InitializeFastMarketOrderData ) ,
31
30
CloseFastMarketOrder ,
31
+ // TODO: Replace with u64.
32
32
PlaceInitialOfferCctpShim ( & ' ix PlaceInitialOfferCctpShimData ) ,
33
33
ExecuteOrderCctpShim ,
34
34
PrepareOrderResponseCctpShim ( PrepareOrderResponseCctpShimData ) ,
@@ -48,10 +48,10 @@ pub fn process_instruction(
48
48
49
49
match instruction {
50
50
FallbackMatchingEngineInstruction :: InitializeFastMarketOrder ( data) => {
51
- initialize_fast_market_order:: process ( accounts, data)
51
+ super :: initialize_fast_market_order:: process ( accounts, data)
52
52
}
53
53
FallbackMatchingEngineInstruction :: CloseFastMarketOrder => {
54
- close_fast_market_order ( accounts)
54
+ super :: close_fast_market_order:: process ( accounts)
55
55
}
56
56
FallbackMatchingEngineInstruction :: PlaceInitialOfferCctpShim ( data) => {
57
57
place_initial_offer_cctp_shim ( accounts, data)
@@ -73,15 +73,14 @@ impl<'ix> FallbackMatchingEngineInstruction<'ix> {
73
73
74
74
match instruction_data[ ..SELECTOR_SIZE ] . try_into ( ) . unwrap ( ) {
75
75
FallbackMatchingEngineInstruction :: PLACE_INITIAL_OFFER_CCTP_SHIM_SELECTOR => {
76
- Some ( Self :: PlaceInitialOfferCctpShim (
77
- PlaceInitialOfferCctpShimData :: from_bytes ( & instruction_data[ SELECTOR_SIZE ..] )
78
- . unwrap ( ) ,
79
- ) )
76
+ bytemuck:: try_from_bytes ( & instruction_data[ SELECTOR_SIZE ..] )
77
+ . ok ( )
78
+ . map ( Self :: PlaceInitialOfferCctpShim )
80
79
}
81
80
FallbackMatchingEngineInstruction :: INITIALIZE_FAST_MARKET_ORDER_SELECTOR => {
82
- Some ( Self :: InitializeFastMarketOrder ( bytemuck:: from_bytes (
83
- & instruction_data [ SELECTOR_SIZE .. ] ,
84
- ) ) )
81
+ bytemuck:: try_from_bytes ( & instruction_data [ SELECTOR_SIZE .. ] )
82
+ . ok ( )
83
+ . map ( Self :: InitializeFastMarketOrder )
85
84
}
86
85
FallbackMatchingEngineInstruction :: CLOSE_FAST_MARKET_ORDER_SELECTOR => {
87
86
Some ( Self :: CloseFastMarketOrder )
@@ -90,6 +89,7 @@ impl<'ix> FallbackMatchingEngineInstruction<'ix> {
90
89
Some ( Self :: ExecuteOrderCctpShim )
91
90
}
92
91
FallbackMatchingEngineInstruction :: PREPARE_ORDER_RESPONSE_CCTP_SHIM_SELECTOR => {
92
+ // TODO: Fix this
93
93
Some ( Self :: PrepareOrderResponseCctpShim (
94
94
PrepareOrderResponseCctpShimData :: from_bytes (
95
95
& instruction_data[ SELECTOR_SIZE ..] ,
@@ -107,7 +107,7 @@ impl FallbackMatchingEngineInstruction<'_> {
107
107
match self {
108
108
Self :: InitializeFastMarketOrder ( data) => {
109
109
let mut out = Vec :: with_capacity (
110
- std:: mem:: size_of :: < InitializeFastMarketOrderData > ( ) . saturating_add ( 8 ) ,
110
+ SELECTOR_SIZE + std:: mem:: size_of :: < InitializeFastMarketOrderData > ( ) ,
111
111
) ;
112
112
113
113
out. extend_from_slice (
@@ -118,53 +118,32 @@ impl FallbackMatchingEngineInstruction<'_> {
118
118
out
119
119
}
120
120
Self :: PlaceInitialOfferCctpShim ( data) => {
121
- // Calculate the total capacity needed
122
- let data_slice = bytemuck:: bytes_of ( * data) ;
123
- let total_capacity = 8_usize . saturating_add ( data_slice. len ( ) ) ; // 8 for the selector, plus the data length
124
-
125
- // Create a vector with the calculated capacity
126
- let mut out = Vec :: with_capacity ( total_capacity) ;
121
+ let mut out = Vec :: with_capacity ( SELECTOR_SIZE + std:: mem:: size_of :: < u64 > ( ) ) ;
127
122
128
- // Add the selector
129
123
out. extend_from_slice (
130
124
& FallbackMatchingEngineInstruction :: PLACE_INITIAL_OFFER_CCTP_SHIM_SELECTOR ,
131
125
) ;
132
- out. extend_from_slice ( data_slice ) ;
126
+ out. extend_from_slice ( bytemuck :: bytes_of ( * data ) ) ;
133
127
134
128
out
135
129
}
136
130
Self :: ExecuteOrderCctpShim => {
137
- let total_capacity = 8 ; // 8 for the selector (no data)
138
-
139
- let mut out = Vec :: with_capacity ( total_capacity) ;
140
-
141
- out. extend_from_slice (
142
- & FallbackMatchingEngineInstruction :: EXECUTE_ORDER_CCTP_SHIM_SELECTOR ,
143
- ) ;
144
-
145
- out
131
+ FallbackMatchingEngineInstruction :: EXECUTE_ORDER_CCTP_SHIM_SELECTOR . to_vec ( )
146
132
}
147
133
Self :: CloseFastMarketOrder => {
148
- let total_capacity = 8 ; // 8 for the selector (no data)
149
-
150
- let mut out = Vec :: with_capacity ( total_capacity) ;
151
-
152
- out. extend_from_slice (
153
- & FallbackMatchingEngineInstruction :: CLOSE_FAST_MARKET_ORDER_SELECTOR ,
154
- ) ;
155
-
156
- out
134
+ FallbackMatchingEngineInstruction :: CLOSE_FAST_MARKET_ORDER_SELECTOR . to_vec ( )
157
135
}
158
136
Self :: PrepareOrderResponseCctpShim ( data) => {
159
- let data_slice = data. try_to_vec ( ) . unwrap ( ) ;
160
- let total_capacity = 8_usize . saturating_add ( data_slice. len ( ) ) ; // 8 for the selector, plus the data length
137
+ // Use a temporary vector, which will be consumed by the output vector when it is
138
+ // extended.
139
+ let tmp_data = data. try_to_vec ( ) . unwrap ( ) ;
161
140
162
- let mut out = Vec :: with_capacity ( total_capacity ) ;
141
+ let mut out = Vec :: with_capacity ( tmp_data . len ( ) . saturating_add ( SELECTOR_SIZE ) ) ;
163
142
164
143
out. extend_from_slice (
165
144
& FallbackMatchingEngineInstruction :: PREPARE_ORDER_RESPONSE_CCTP_SHIM_SELECTOR ,
166
145
) ;
167
- out. extend_from_slice ( & data_slice ) ;
146
+ out. extend ( tmp_data ) ;
168
147
169
148
out
170
149
}
0 commit comments