@@ -29,6 +29,7 @@ pub struct PrepareMarketOrder<'info> {
29
29
TRANSFER_AUTHORITY_SEED_PREFIX ,
30
30
prepared_order. key( ) . as_ref( ) ,
31
31
& args. hash( ) . 0 ,
32
+ refund_token. key( ) . as_ref( )
32
33
] ,
33
34
bump,
34
35
constraint = {
@@ -175,6 +176,14 @@ pub fn prepare_market_order(
175
176
redeemer_message,
176
177
} = args;
177
178
179
+ let token_program = & ctx. accounts . token_program ;
180
+ let sender_token = & ctx. accounts . sender_token ;
181
+ let custody_token = & ctx. accounts . prepared_custody_token ;
182
+ let refund_token = & ctx. accounts . refund_token ;
183
+
184
+ let prepared_order = & mut ctx. accounts . prepared_order ;
185
+ let prepared_order_key = prepared_order. key ( ) ;
186
+
178
187
// Finally transfer amount to custody token account. We perform exclusive or because we do not
179
188
// want to allow specifying more than one authority.
180
189
let order_sender = match (
@@ -184,10 +193,10 @@ pub fn prepare_market_order(
184
193
( Some ( sender) , None ) => {
185
194
token:: transfer (
186
195
CpiContext :: new (
187
- ctx . accounts . token_program . to_account_info ( ) ,
196
+ token_program. to_account_info ( ) ,
188
197
token:: Transfer {
189
- from : ctx . accounts . sender_token . to_account_info ( ) ,
190
- to : ctx . accounts . prepared_custody_token . to_account_info ( ) ,
198
+ from : sender_token. to_account_info ( ) ,
199
+ to : custody_token . to_account_info ( ) ,
191
200
authority : sender. to_account_info ( ) ,
192
201
} ,
193
202
) ,
@@ -197,20 +206,19 @@ pub fn prepare_market_order(
197
206
sender. key ( )
198
207
}
199
208
( None , Some ( program_transfer_authority) ) => {
200
- let sender_token = & ctx. accounts . sender_token ;
201
-
202
209
token:: transfer (
203
210
CpiContext :: new_with_signer (
204
- ctx . accounts . token_program . to_account_info ( ) ,
211
+ token_program. to_account_info ( ) ,
205
212
token:: Transfer {
206
213
from : sender_token. to_account_info ( ) ,
207
- to : ctx . accounts . prepared_custody_token . to_account_info ( ) ,
214
+ to : custody_token . to_account_info ( ) ,
208
215
authority : program_transfer_authority. to_account_info ( ) ,
209
216
} ,
210
217
& [ & [
211
218
TRANSFER_AUTHORITY_SEED_PREFIX ,
212
- ctx . accounts . prepared_order . key ( ) . as_ref ( ) ,
219
+ prepared_order_key . as_ref ( ) ,
213
220
& hashed_args. 0 ,
221
+ refund_token. key ( ) . as_ref ( ) ,
214
222
& [ ctx. bumps . program_transfer_authority . unwrap ( ) ] ,
215
223
] ] ,
216
224
) ,
@@ -223,13 +231,13 @@ pub fn prepare_market_order(
223
231
} ;
224
232
225
233
// Set the values in prepared order account.
226
- ctx . accounts . prepared_order . set_inner ( PreparedOrder {
234
+ prepared_order. set_inner ( PreparedOrder {
227
235
info : PreparedOrderInfo {
228
236
order_sender,
229
237
prepared_by : ctx. accounts . payer . key ( ) ,
230
238
order_type : OrderType :: Market { min_amount_out } ,
231
- src_token : ctx . accounts . sender_token . key ( ) ,
232
- refund_token : ctx . accounts . refund_token . key ( ) ,
239
+ src_token : sender_token. key ( ) ,
240
+ refund_token : refund_token. key ( ) ,
233
241
target_chain,
234
242
redeemer,
235
243
prepared_custody_token_bump : ctx. bumps . prepared_custody_token ,
0 commit comments