@@ -22,6 +22,7 @@ pub struct PlaceInitialOfferCctpShimData {
22
22
pub offer_price : u64 ,
23
23
}
24
24
25
+ // TODO: Rename to "PlaceInitialOfferCctpV2Accounts".
25
26
#[ derive( Debug , Clone , PartialEq , Eq , Copy ) ]
26
27
pub struct PlaceInitialOfferCctpShimAccounts < ' ix > {
27
28
/// The signer account
@@ -58,6 +59,7 @@ pub struct PlaceInitialOfferCctpShimAccounts<'ix> {
58
59
pub token_program : & ' ix Pubkey ,
59
60
}
60
61
62
+ // TODO: Rename to "PlaceInitialOfferCctpV2".
61
63
#[ derive( Debug , Clone , Copy ) ]
62
64
pub struct PlaceInitialOfferCctpShim < ' ix > {
63
65
pub program_id : & ' ix Pubkey ,
@@ -117,9 +119,9 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
117
119
// This transfer authority must have been delegated authority to transfer
118
120
// USDC so it can transfer tokens to the auction custody token account.
119
121
//
120
- // We will validate this transfer authority when we will transfer USDC to
121
- // the auction's custody account.
122
- let transfer_authority = & accounts[ 1 ] ;
122
+ // We will validate this transfer authority when we attempt to transfer USDC
123
+ // to the auction's custody account.
124
+ let _transfer_authority = & accounts[ 1 ] ;
123
125
124
126
let custodian = super :: helpers:: try_custodian_account (
125
127
& accounts[ 2 ] ,
@@ -157,7 +159,26 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
157
159
) ;
158
160
159
161
let new_auction_info = & accounts[ 7 ] ;
160
- let new_auction_key = new_auction_info. key ;
162
+
163
+ let vaa_sequence = fast_market_order. vaa_sequence ;
164
+ let vaa_timestamp = fast_market_order. vaa_timestamp ;
165
+ let consistency_level = fast_market_order. vaa_consistency_level ;
166
+
167
+ // Generate the VAA digest. This digest is used as the seed for the newly
168
+ // created auction account.
169
+ let vaa_message_digest = super :: helpers:: VaaMessageBodyHeader {
170
+ consistency_level,
171
+ timestamp : vaa_timestamp,
172
+ sequence : vaa_sequence,
173
+ emitter_chain : from_endpoint_account. chain ,
174
+ emitter_address : from_endpoint_account. address ,
175
+ }
176
+ . digest ( & fast_market_order) ;
177
+
178
+ // Derive the expected auction account key. This key is used for the auction
179
+ // custody token account seed.
180
+ let ( expected_auction_key, new_auction_bump) =
181
+ Pubkey :: find_program_address ( & [ Auction :: SEED_PREFIX , & vaa_message_digest. 0 ] , & ID ) ;
161
182
162
183
// This account must be the USDC mint. This instruction does not refer to
163
184
// this account explicitly. It just needs to exist so that we can create the
@@ -171,7 +192,6 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
171
192
}
172
193
173
194
let offer_price = data. offer_price ;
174
- let vaa_timestamp = fast_market_order. vaa_timestamp ;
175
195
176
196
// Check contents of fast_market_order
177
197
// TODO: Use shared method that both place initial offer instructions can
@@ -196,37 +216,35 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
196
216
let offer_token_info = & accounts[ 8 ] ;
197
217
let new_auction_custody_info = & accounts[ 9 ] ;
198
218
199
- // TODO: Double-check that we do not need verify the derived pubkey is
200
- // correct. We shouldn't have to because the seeds are used to create the
201
- // account, which will only work if the auction custody pubkey is correct.
202
- let ( _, new_auction_custody_bump) = Pubkey :: find_program_address (
219
+ // We will use the expected auction custody token account key to create this
220
+ // account.
221
+ let ( expected_auction_custody_key, new_auction_custody_bump) = Pubkey :: find_program_address (
203
222
& [
204
223
crate :: AUCTION_CUSTODY_TOKEN_SEED_PREFIX ,
205
- new_auction_key . as_ref ( ) ,
224
+ expected_auction_key . as_ref ( ) ,
206
225
] ,
207
226
& ID ,
208
227
) ;
209
228
210
229
super :: helpers:: create_usdc_token_account_reliably (
211
230
payer_info. key ,
212
- new_auction_custody_info . key ,
231
+ & expected_auction_custody_key ,
213
232
new_auction_info. key ,
214
233
new_auction_custody_info. lamports ( ) ,
215
234
accounts,
216
235
& [ & [
217
236
crate :: AUCTION_CUSTODY_TOKEN_SEED_PREFIX ,
218
- new_auction_key . as_ref ( ) ,
237
+ expected_auction_key . as_ref ( ) ,
219
238
& [ new_auction_custody_bump] ,
220
239
] ] ,
221
240
) ?;
222
241
223
- // TODO: Double-check that we do not need verify the derived pubkey is
224
- // correct. We shouldn't have to because the seeds are used to transfer
225
- // tokens, which will only work if the transfer authority pubkey is correct.
226
- let ( _, transfer_authority_bump) = Pubkey :: find_program_address (
242
+ // We will use the expected transfer authority account key to invoke the
243
+ // SPL token transfer instruction.
244
+ let ( expected_transfer_authority_key, transfer_authority_bump) = Pubkey :: find_program_address (
227
245
& [
228
246
TRANSFER_AUTHORITY_SEED_PREFIX ,
229
- new_auction_key . as_ref ( ) ,
247
+ expected_auction_key . as_ref ( ) ,
230
248
& offer_price. to_be_bytes ( ) ,
231
249
] ,
232
250
& ID ,
@@ -245,7 +263,7 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
245
263
& spl_token:: ID ,
246
264
offer_token_info. key ,
247
265
new_auction_custody_info. key ,
248
- transfer_authority . key ,
266
+ & expected_transfer_authority_key ,
249
267
& [ ] ,
250
268
fast_market_order
251
269
. amount_in
@@ -259,36 +277,16 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
259
277
accounts,
260
278
& [ & [
261
279
TRANSFER_AUTHORITY_SEED_PREFIX ,
262
- new_auction_key . as_ref ( ) ,
280
+ expected_auction_key . as_ref ( ) ,
263
281
& offer_price. to_be_bytes ( ) ,
264
282
& [ transfer_authority_bump] ,
265
283
] ] ,
266
284
) ?;
267
285
268
- let vaa_sequence = fast_market_order. vaa_sequence ;
269
- let consistency_level = fast_market_order. vaa_consistency_level ;
270
-
271
- // Generate the VAA digest. This digest is used as the seed for the newly
272
- // created auction account.
273
- let vaa_message_digest = super :: helpers:: VaaMessageBodyHeader {
274
- consistency_level,
275
- timestamp : vaa_timestamp,
276
- sequence : vaa_sequence,
277
- emitter_chain : from_endpoint_account. chain ,
278
- emitter_address : from_endpoint_account. address ,
279
- }
280
- . digest ( & fast_market_order) ;
281
-
282
- // TODO: Double-check that we do not need verify the derived pubkey is
283
- // correct. We shouldn't have to because the seeds are used to create the
284
- // account, which will only work if the auction pubkey is correct.
285
- let ( _, new_auction_bump) =
286
- Pubkey :: find_program_address ( & [ Auction :: SEED_PREFIX , & vaa_message_digest. 0 ] , & ID ) ;
287
-
288
286
// Create the auction account and serialize its data into it.
289
287
super :: helpers:: create_account_reliably (
290
288
payer_info. key ,
291
- new_auction_key ,
289
+ & expected_auction_key ,
292
290
new_auction_info. lamports ( ) ,
293
291
8 + Auction :: INIT_SPACE ,
294
292
accounts,
0 commit comments