Skip to content

Commit 8a6e5d1

Browse files
author
Bengt Lofgren
committed
burn_and_post.rs + execute_order.rs comments addressed
1 parent 1eca2da commit 8a6e5d1

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,18 @@ use common::wormhole_cctp_solana::{
77
cpi::BurnAndPublishArgs,
88
};
99
use solana_program::program::invoke_signed_unchecked;
10+
use wormhole_svm_definitions::solana::Finality;
1011
use wormhole_svm_definitions::solana::{
1112
CORE_BRIDGE_CONFIG, CORE_BRIDGE_FEE_COLLECTOR, CORE_BRIDGE_PROGRAM_ID,
1213
POST_MESSAGE_SHIM_EVENT_AUTHORITY, POST_MESSAGE_SHIM_PROGRAM_ID,
1314
};
14-
use wormhole_svm_definitions::{
15-
find_emitter_sequence_address, find_shim_message_address, solana::Finality,
16-
};
1715
use wormhole_svm_shim::post_message;
1816

1917
// This is a helper struct to make it easier to pass in the accounts for the post_message instruction.
2018
pub struct PostMessageAccounts {
2119
pub emitter: Pubkey,
2220
pub payer: Pubkey,
23-
derived: PostMessageDerivedAccounts,
24-
}
25-
26-
impl PostMessageAccounts {
27-
pub fn new(emitter: Pubkey, payer: Pubkey) -> Self {
28-
Self {
29-
emitter,
30-
payer,
31-
derived: Self::get_derived_accounts(&emitter),
32-
}
33-
}
34-
fn get_derived_accounts(emitter: &Pubkey) -> PostMessageDerivedAccounts {
35-
PostMessageDerivedAccounts {
36-
message: find_shim_message_address(emitter, &POST_MESSAGE_SHIM_PROGRAM_ID).0,
37-
sequence: find_emitter_sequence_address(emitter, &CORE_BRIDGE_PROGRAM_ID).0,
38-
}
39-
}
21+
pub derived: PostMessageDerivedAccounts,
4022
}
4123

4224
pub struct PostMessageDerivedAccounts {

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use super::helpers::check_account_length;
2+
use crate::fallback::burn_and_post::PostMessageDerivedAccounts;
23
use crate::state::{
34
Auction, AuctionConfig, AuctionStatus, Custodian, FastMarketOrder as FastMarketOrderState,
45
MessageProtocol, RouterEndpoint,
56
};
6-
use crate::utils;
77
use crate::utils::auction::DepositPenalty;
8+
use crate::{utils, ID};
89
use anchor_lang::prelude::*;
910
use anchor_spl::token::{spl_token, TokenAccount};
1011
use common::messages::Fill;
@@ -35,7 +36,7 @@ pub struct ExecuteOrderShimAccounts<'ix> {
3536
pub active_auction_config: &'ix Pubkey, // 6
3637
/// The token account of the auction's best offer
3738
pub active_auction_best_offer_token: &'ix Pubkey, // 7
38-
/// ???
39+
/// The token account of the executor
3940
pub executor_token: &'ix Pubkey, // 8
4041
/// The token account of the auction's initial offer
4142
pub initial_offer_token: &'ix Pubkey, // 9
@@ -45,10 +46,10 @@ pub struct ExecuteOrderShimAccounts<'ix> {
4546
pub to_router_endpoint: &'ix Pubkey, // 11
4647
/// The program id of the post message shim program
4748
pub post_message_shim_program: &'ix Pubkey, // 12
48-
/// The sequence account of the post message shim program (can be derived)
49-
pub post_message_sequence: &'ix Pubkey, // 13
49+
/// The emitter sequence of the core bridge program (can be derived)
50+
pub core_bridge_emitter_sequence: &'ix Pubkey, // 13
5051
/// The message account of the post message shim program (can be derived)
51-
pub post_message_message: &'ix Pubkey, // 14
52+
pub post_shim_message: &'ix Pubkey, // 14
5253
/// The mint account of the CCTP token to be burned
5354
pub cctp_deposit_for_burn_mint: &'ix Pubkey, // 15
5455
/// The token messenger minter sender authority account of the CCTP token to be burned
@@ -101,8 +102,8 @@ impl<'ix> ExecuteOrderShimAccounts<'ix> {
101102
AccountMeta::new(*self.initial_participant, false),
102103
AccountMeta::new_readonly(*self.to_router_endpoint, false),
103104
AccountMeta::new_readonly(*self.post_message_shim_program, false),
104-
AccountMeta::new(*self.post_message_sequence, false),
105-
AccountMeta::new(*self.post_message_message, false),
105+
AccountMeta::new(*self.core_bridge_emitter_sequence, false),
106+
AccountMeta::new(*self.post_shim_message, false),
106107
AccountMeta::new(*self.cctp_deposit_for_burn_mint, false),
107108
AccountMeta::new_readonly(
108109
*self.cctp_deposit_for_burn_token_messenger_minter_sender_authority,
@@ -158,7 +159,7 @@ pub fn handle_execute_order_shim(accounts: &[AccountInfo]) -> Result<()> {
158159
// This saves stack space whereas having that in the body does not
159160
check_account_length(accounts, 31)?;
160161

161-
let program_id = &crate::ID;
162+
let program_id = &ID;
162163

163164
// Get the accounts
164165
let signer_account = &accounts[0];
@@ -174,8 +175,8 @@ pub fn handle_execute_order_shim(accounts: &[AccountInfo]) -> Result<()> {
174175
let initial_participant_account = &accounts[10];
175176
let to_router_endpoint_account = &accounts[11];
176177
let _post_message_shim_program_account = &accounts[12];
177-
let _post_message_sequence_account = &accounts[13];
178-
let _post_message_message_account = &accounts[14];
178+
let core_bridge_emitter_sequence_account = &accounts[13];
179+
let post_shim_message_account = &accounts[14];
179180
let cctp_deposit_for_burn_mint_account = &accounts[15];
180181
let cctp_deposit_for_burn_token_messenger_minter_sender_authority_account = &accounts[16];
181182
let cctp_deposit_for_burn_message_transmitter_config_account = &accounts[17];
@@ -441,12 +442,7 @@ pub fn handle_execute_order_shim(accounts: &[AccountInfo]) -> Result<()> {
441442
// the fast fill will most likely require an additional transaction, so this buffer allows
442443
// the best offer participant to perform his duty without the risk of getting slashed by
443444
// another executor.
444-
let additional_grace_period = match active_auction.target_protocol {
445-
MessageProtocol::Local { .. } => {
446-
crate::EXECUTE_FAST_ORDER_LOCAL_ADDITIONAL_GRACE_PERIOD.into()
447-
}
448-
_ => None,
449-
};
445+
let additional_grace_period = Some(crate::EXECUTE_FAST_ORDER_LOCAL_ADDITIONAL_GRACE_PERIOD);
450446

451447
let DepositPenalty {
452448
penalty,
@@ -634,9 +630,14 @@ pub fn handle_execute_order_shim(accounts: &[AccountInfo]) -> Result<()> {
634630
.unwrap(),
635631
};
636632

637-
let post_message_accounts =
638-
PostMessageAccounts::new(custodian_account.key(), signer_account.key());
639-
// Lets print the auction account balance
633+
let post_message_accounts = PostMessageAccounts {
634+
emitter: custodian_account.key(),
635+
payer: signer_account.key(),
636+
derived: PostMessageDerivedAccounts {
637+
message: post_shim_message_account.key(),
638+
sequence: core_bridge_emitter_sequence_account.key(),
639+
},
640+
};
640641

641642
burn_and_post(
642643
CpiContext::new_with_signer(

0 commit comments

Comments
 (0)