@@ -5,10 +5,7 @@ use crate::{
5
5
utils,
6
6
} ;
7
7
use anchor_lang:: prelude:: * ;
8
- use anchor_spl:: {
9
- associated_token:: get_associated_token_address,
10
- token:: { self , TokenAccount } ,
11
- } ;
8
+ use anchor_spl:: token:: { self , TokenAccount } ;
12
9
13
10
#[ derive( Accounts ) ]
14
11
pub struct SettleAuctionComplete < ' info > {
@@ -18,20 +15,24 @@ pub struct SettleAuctionComplete<'info> {
18
15
mut ,
19
16
address = prepared_order_response. prepared_by,
20
17
) ]
21
- executor : UncheckedAccount < ' info > ,
18
+ beneficiary : UncheckedAccount < ' info > ,
22
19
20
+ /// This token account will receive the base fee only if there was a penalty when executing the
21
+ /// order. If it does not exist when there is a penalty, this instruction handler will revert.
22
+ ///
23
+ /// CHECK: This account must be the same as the base fee token in the prepared order response.
23
24
#[ account(
24
25
mut ,
25
- token :: mint = common :: USDC_MINT ,
26
+ address = prepared_order_response . base_fee_token ,
26
27
) ]
27
- executor_token : Box < Account < ' info , TokenAccount > > ,
28
+ base_fee_token : UncheckedAccount < ' info > ,
28
29
29
30
/// Destination token account, which the redeemer may not own. But because the redeemer is a
30
31
/// signer and is the one encoded in the Deposit Fill message, he may have the tokens be sent
31
32
/// to any account he chooses (this one).
32
33
///
33
34
/// CHECK: This token account may exist. If it doesn't and there is a penalty, we will send all
34
- /// of the tokens to the executor token account.
35
+ /// of the tokens to the base fee token account.
35
36
#[ account(
36
37
mut ,
37
38
address = auction. info. as_ref( ) . unwrap( ) . best_offer_token,
@@ -40,7 +41,7 @@ pub struct SettleAuctionComplete<'info> {
40
41
41
42
#[ account(
42
43
mut ,
43
- close = executor ,
44
+ close = beneficiary ,
44
45
seeds = [
45
46
PreparedOrderResponse :: SEED_PREFIX ,
46
47
prepared_order_response. seeds. fast_vaa_hash. as_ref( )
@@ -101,8 +102,8 @@ fn handle_settle_auction_complete(
101
102
& [ prepared_order_response. seeds . bump ] ,
102
103
] ;
103
104
104
- let executor = & ctx. accounts . executor ;
105
- let executor_token = & ctx. accounts . executor_token ;
105
+ let beneficiary = & ctx. accounts . beneficiary ;
106
+ let base_fee_token = & ctx. accounts . base_fee_token ;
106
107
let best_offer_token = & ctx. accounts . best_offer_token ;
107
108
let token_program = & ctx. accounts . token_program ;
108
109
let prepared_custody_token = & ctx. accounts . prepared_custody_token ;
@@ -131,11 +132,15 @@ fn handle_settle_auction_complete(
131
132
)
132
133
}
133
134
_ => {
135
+ let base_fee_token_data =
136
+ utils:: checked_deserialize_token_account ( base_fee_token, & common:: USDC_MINT )
137
+ . ok_or_else ( || MatchingEngineError :: BaseFeeTokenRequired ) ?;
138
+
134
139
// If the token account happens to not exist anymore, we will give everything to the
135
- // executor .
140
+ // base fee token account .
136
141
match utils:: checked_deserialize_token_account ( best_offer_token, & common:: USDC_MINT ) {
137
142
Some ( best_offer) => {
138
- if executor_token . key ( ) == best_offer_token. key ( ) {
143
+ if base_fee_token . key ( ) == best_offer_token. key ( ) {
139
144
(
140
145
None , // executor_result
141
146
TokenAccountResult {
@@ -145,31 +150,9 @@ fn handle_settle_auction_complete(
145
150
. into ( ) ,
146
151
)
147
152
} else {
148
- // Because the auction participant was penalized for executing the order
149
- // late, he will be deducted the base fee. This base fee will be sent to the
150
- // executor token account if it is not the same as the best offer token
151
- // account.
152
-
153
- // We require that the executor token account be an ATA.
154
- require_keys_eq ! (
155
- executor_token. key( ) ,
156
- get_associated_token_address(
157
- & executor_token. owner,
158
- & executor_token. mint
159
- ) ,
160
- ErrorCode :: AccountNotAssociatedTokenAccount
161
- ) ;
162
-
163
- // And enforce that the owner of this ATA is the executor.
164
- require_keys_eq ! (
165
- executor. key( ) ,
166
- executor_token. owner,
167
- ErrorCode :: ConstraintTokenOwner ,
168
- ) ;
169
-
170
153
(
171
154
TokenAccountResult {
172
- balance_before : executor_token . amount ,
155
+ balance_before : base_fee_token_data . amount ,
173
156
amount : base_fee,
174
157
}
175
158
. into ( ) ,
@@ -183,7 +166,7 @@ fn handle_settle_auction_complete(
183
166
}
184
167
None => (
185
168
TokenAccountResult {
186
- balance_before : executor_token . amount ,
169
+ balance_before : base_fee_token_data . amount ,
187
170
amount : repayment,
188
171
}
189
172
. into ( ) ,
@@ -193,7 +176,7 @@ fn handle_settle_auction_complete(
193
176
}
194
177
} ;
195
178
196
- // Transfer executor his bounty if there are any.
179
+ // Transfer base fee token his bounty if there are any.
197
180
let settled_executor_result = match executor_result {
198
181
Some ( TokenAccountResult {
199
182
balance_before,
@@ -204,7 +187,7 @@ fn handle_settle_auction_complete(
204
187
token_program. to_account_info ( ) ,
205
188
token:: Transfer {
206
189
from : prepared_custody_token. to_account_info ( ) ,
207
- to : executor_token . to_account_info ( ) ,
190
+ to : base_fee_token . to_account_info ( ) ,
208
191
authority : prepared_order_response. to_account_info ( ) ,
209
192
} ,
210
193
& [ prepared_order_response_signer_seeds] ,
@@ -213,7 +196,7 @@ fn handle_settle_auction_complete(
213
196
) ?;
214
197
215
198
SettledTokenAccountInfo {
216
- key : executor_token . key ( ) ,
199
+ key : base_fee_token . key ( ) ,
217
200
balance_after : balance_before. saturating_add ( amount) ,
218
201
}
219
202
. into ( )
@@ -252,7 +235,7 @@ fn handle_settle_auction_complete(
252
235
emit ! ( crate :: events:: AuctionSettled {
253
236
auction: ctx. accounts. auction. key( ) ,
254
237
best_offer_token: settled_best_offer_result,
255
- executor_token : settled_executor_result,
238
+ base_fee_token : settled_executor_result,
256
239
with_execute: Default :: default ( ) ,
257
240
} ) ;
258
241
@@ -261,7 +244,7 @@ fn handle_settle_auction_complete(
261
244
token_program. to_account_info ( ) ,
262
245
token:: CloseAccount {
263
246
account : prepared_custody_token. to_account_info ( ) ,
264
- destination : executor . to_account_info ( ) ,
247
+ destination : beneficiary . to_account_info ( ) ,
265
248
authority : prepared_order_response. to_account_info ( ) ,
266
249
} ,
267
250
& [ prepared_order_response_signer_seeds] ,
0 commit comments