@@ -115,36 +115,35 @@ fn handle_settle_auction_complete(
115
115
amount : u64 ,
116
116
}
117
117
118
- let ( executor_result, best_offer_result) = match execute_penalty {
118
+ let ( base_fee_result, best_offer_result) = match execute_penalty {
119
+ // When there is no penalty, we will give everything to the best offer token account.
119
120
None => {
120
121
// If the token account happens to not exist anymore, we will revert.
121
- let best_offer =
122
+ let best_offer_token_data =
122
123
utils:: checked_deserialize_token_account ( best_offer_token, & common:: USDC_MINT )
123
124
. ok_or_else ( || MatchingEngineError :: BestOfferTokenRequired ) ?;
124
125
125
126
(
126
- None , // executor_result
127
+ None , // base_fee_result
127
128
TokenAccountResult {
128
- balance_before : best_offer . amount ,
129
+ balance_before : best_offer_token_data . amount ,
129
130
amount : repayment,
130
131
}
131
132
. into ( ) ,
132
133
)
133
134
}
135
+ // Otherwise, determine how the repayment should be divvied up.
134
136
_ => {
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
-
139
- // If the token account happens to not exist anymore, we will give everything to the
140
- // base fee token account.
141
- match utils:: checked_deserialize_token_account ( best_offer_token, & common:: USDC_MINT ) {
142
- Some ( best_offer) => {
137
+ match (
138
+ utils:: checked_deserialize_token_account ( base_fee_token, & common:: USDC_MINT ) ,
139
+ utils:: checked_deserialize_token_account ( best_offer_token, & common:: USDC_MINT ) ,
140
+ ) {
141
+ ( Some ( base_fee_token_data) , Some ( best_offer_token_data) ) => {
143
142
if base_fee_token. key ( ) == best_offer_token. key ( ) {
144
143
(
145
- None , // executor_result
144
+ None , // base_fee_result
146
145
TokenAccountResult {
147
- balance_before : best_offer . amount ,
146
+ balance_before : best_offer_token_data . amount ,
148
147
amount : repayment,
149
148
}
150
149
. into ( ) ,
@@ -157,27 +156,43 @@ fn handle_settle_auction_complete(
157
156
}
158
157
. into ( ) ,
159
158
TokenAccountResult {
160
- balance_before : best_offer . amount ,
159
+ balance_before : best_offer_token_data . amount ,
161
160
amount : repayment. saturating_sub ( base_fee) ,
162
161
}
163
162
. into ( ) ,
164
163
)
165
164
}
166
165
}
167
- None => (
166
+ // If the best offer token account does not exist, we will give everything to the
167
+ // base fee token account.
168
+ ( Some ( base_fee_token_data) , None ) => (
168
169
TokenAccountResult {
169
170
balance_before : base_fee_token_data. amount ,
170
171
amount : repayment,
171
172
}
172
173
. into ( ) ,
173
174
None , // best_offer_result
174
175
) ,
176
+ // If the base fee token account does not exist, we will give everything to the best
177
+ // offer token account.
178
+ ( None , Some ( best_offer_data) ) => {
179
+ (
180
+ None , // base_fee_result
181
+ TokenAccountResult {
182
+ balance_before : best_offer_data. amount ,
183
+ amount : repayment,
184
+ }
185
+ . into ( ) ,
186
+ )
187
+ }
188
+ // Otherwise revert.
189
+ _ => return err ! ( MatchingEngineError :: BestOfferTokenRequired ) ,
175
190
}
176
191
}
177
192
} ;
178
193
179
194
// Transfer base fee token his bounty if there are any.
180
- let settled_executor_result = match executor_result {
195
+ let settled_base_fee_result = match base_fee_result {
181
196
Some ( TokenAccountResult {
182
197
balance_before,
183
198
amount,
@@ -235,7 +250,7 @@ fn handle_settle_auction_complete(
235
250
emit ! ( crate :: events:: AuctionSettled {
236
251
auction: ctx. accounts. auction. key( ) ,
237
252
best_offer_token: settled_best_offer_result,
238
- base_fee_token: settled_executor_result ,
253
+ base_fee_token: settled_base_fee_result ,
239
254
with_execute: Default :: default ( ) ,
240
255
} ) ;
241
256
0 commit comments