Skip to content

Commit f495a17

Browse files
committed
solana: more place initial offer fixes
1 parent 3ef7c44 commit f495a17

File tree

2 files changed

+39
-41
lines changed

2 files changed

+39
-41
lines changed

solana/programs/matching-engine/src/fallback/processor/initialize_fast_market_order.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bytemuck::{Pod, Zeroable};
33
use solana_program::{instruction::Instruction, keccak, program::invoke_signed_unchecked};
44
use wormhole_svm_shim::verify_vaa;
55

6-
use crate::{error::MatchingEngineError, state::FastMarketOrder, ID};
6+
use crate::{state::FastMarketOrder, ID};
77

88
pub struct InitializeFastMarketOrderAccounts<'ix> {
99
/// Lamports from this signer will be used to create the new fast market

solana/programs/matching-engine/src/fallback/processor/place_initial_offer.rs

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct PlaceInitialOfferCctpShimData {
2222
pub offer_price: u64,
2323
}
2424

25+
// TODO: Rename to "PlaceInitialOfferCctpV2Accounts".
2526
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
2627
pub struct PlaceInitialOfferCctpShimAccounts<'ix> {
2728
/// The signer account
@@ -58,6 +59,7 @@ pub struct PlaceInitialOfferCctpShimAccounts<'ix> {
5859
pub token_program: &'ix Pubkey,
5960
}
6061

62+
// TODO: Rename to "PlaceInitialOfferCctpV2".
6163
#[derive(Debug, Clone, Copy)]
6264
pub struct PlaceInitialOfferCctpShim<'ix> {
6365
pub program_id: &'ix Pubkey,
@@ -117,9 +119,9 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
117119
// This transfer authority must have been delegated authority to transfer
118120
// USDC so it can transfer tokens to the auction custody token account.
119121
//
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];
123125

124126
let custodian = super::helpers::try_custodian_account(
125127
&accounts[2],
@@ -157,7 +159,26 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
157159
);
158160

159161
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);
161182

162183
// This account must be the USDC mint. This instruction does not refer to
163184
// 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) -
171192
}
172193

173194
let offer_price = data.offer_price;
174-
let vaa_timestamp = fast_market_order.vaa_timestamp;
175195

176196
// Check contents of fast_market_order
177197
// TODO: Use shared method that both place initial offer instructions can
@@ -196,37 +216,35 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
196216
let offer_token_info = &accounts[8];
197217
let new_auction_custody_info = &accounts[9];
198218

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(
203222
&[
204223
crate::AUCTION_CUSTODY_TOKEN_SEED_PREFIX,
205-
new_auction_key.as_ref(),
224+
expected_auction_key.as_ref(),
206225
],
207226
&ID,
208227
);
209228

210229
super::helpers::create_usdc_token_account_reliably(
211230
payer_info.key,
212-
new_auction_custody_info.key,
231+
&expected_auction_custody_key,
213232
new_auction_info.key,
214233
new_auction_custody_info.lamports(),
215234
accounts,
216235
&[&[
217236
crate::AUCTION_CUSTODY_TOKEN_SEED_PREFIX,
218-
new_auction_key.as_ref(),
237+
expected_auction_key.as_ref(),
219238
&[new_auction_custody_bump],
220239
]],
221240
)?;
222241

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(
227245
&[
228246
TRANSFER_AUTHORITY_SEED_PREFIX,
229-
new_auction_key.as_ref(),
247+
expected_auction_key.as_ref(),
230248
&offer_price.to_be_bytes(),
231249
],
232250
&ID,
@@ -245,7 +263,7 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
245263
&spl_token::ID,
246264
offer_token_info.key,
247265
new_auction_custody_info.key,
248-
transfer_authority.key,
266+
&expected_transfer_authority_key,
249267
&[],
250268
fast_market_order
251269
.amount_in
@@ -259,36 +277,16 @@ pub fn process(accounts: &[AccountInfo], data: &PlaceInitialOfferCctpShimData) -
259277
accounts,
260278
&[&[
261279
TRANSFER_AUTHORITY_SEED_PREFIX,
262-
new_auction_key.as_ref(),
280+
expected_auction_key.as_ref(),
263281
&offer_price.to_be_bytes(),
264282
&[transfer_authority_bump],
265283
]],
266284
)?;
267285

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-
288286
// Create the auction account and serialize its data into it.
289287
super::helpers::create_account_reliably(
290288
payer_info.key,
291-
new_auction_key,
289+
&expected_auction_key,
292290
new_auction_info.lamports(),
293291
8 + Auction::INIT_SPACE,
294292
accounts,

0 commit comments

Comments
 (0)