Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions solana/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion solana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bytemuck = "1.13.0"
wormhole-svm-shim = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "33dd6a56541c2d15d3e20faa1330ba542a5fa727" }
wormhole-svm-definitions = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "33dd6a56541c2d15d3e20faa1330ba542a5fa727", features = ["borsh"] }

[patch."https://github.com/wormholelabs-xyz/wormhole.git"]
[patch."https://github.com/wormhole-foundation/wormhole.git"]
wormhole-svm-shim = { path = "lib/wormhole/svm/wormhole-core-shims/crates/shim" }
wormhole-svm-definitions = { path = "lib/wormhole/svm/wormhole-core-shims/crates/definitions" }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::testing_engine::config::{ExecuteOrderInstructionConfig, InstructionConfig};
use crate::testing_engine::config::{ExecuteOrderInstructionConfig, InstructionConfig, OverwriteAccountField};
use crate::testing_engine::setup::{TestingContext, TransferDirection};
use crate::testing_engine::state::{OrderExecutedState, TestingEngineState};

use super::super::utils;
use anchor_spl::token::spl_token;
use common::wormhole_cctp_solana::cctp::{
MESSAGE_TRANSMITTER_PROGRAM_ID, TOKEN_MESSENGER_MINTER_PROGRAM_ID,
};
use matching_engine::accounts::CctpDepositForBurn;
use matching_engine::fallback::execute_order::{ExecuteOrderCctpShim, ExecuteOrderShimAccounts};
use matching_engine::fallback::execute_order::{ExecuteOrderCctpShim, ExecuteOrderV2Accounts};
use solana_program_test::ProgramTestContext;
use solana_sdk::{pubkey::Pubkey, signer::Signer, sysvar::SysvarId};
use utils::constants::*;
Expand Down Expand Up @@ -49,7 +48,6 @@ pub async fn execute_order_shimful(
current_state,
config,
&fixture_accounts,
config.fast_market_order_address,
);
let program_id = &testing_context.get_matching_engine_program_id();
let payer_signer = config
Expand Down Expand Up @@ -107,7 +105,7 @@ pub async fn execute_order_shimful(
}

/// A helper struct for the accounts for the execute order shimful instruction that disregards the lifetime
struct ExecuteOrderShimfulAccounts {
pub struct ExecuteOrderShimfulAccounts {
pub signer: Pubkey,
pub custodian: Pubkey,
pub fast_market_order_address: Pubkey,
Expand Down Expand Up @@ -137,7 +135,6 @@ impl ExecuteOrderShimfulAccounts {
current_state: &TestingEngineState,
config: &ExecuteOrderInstructionConfig,
fixture_accounts: &utils::account_fixtures::FixtureAccounts,
override_fast_market_order_address: Option<Pubkey>,
) -> Self {
let payer_signer = config
.payer_signer
Expand All @@ -149,12 +146,6 @@ impl ExecuteOrderShimfulAccounts {
let initial_participant = active_auction_state.initial_offer.participant;
let active_auction = active_auction_state.auction_address;
let custodian = auction_accounts.custodian;
let fast_market_order_address = override_fast_market_order_address.unwrap_or_else(|| {
current_state
.fast_market_order()
.unwrap()
.fast_market_order_address
});
let remote_token_messenger = match transfer_direction {
TransferDirection::FromEthereumToArbitrum => {
fixture_accounts.arbitrum_remote_token_messenger
Expand Down Expand Up @@ -208,8 +199,13 @@ impl ExecuteOrderShimfulAccounts {
.0;
let solver = config.actor_enum.get_actor(&testing_context.testing_actors);
let executor_token = solver.token_account_address(&config.token_enum).unwrap();

Self {
let fast_market_order_address = current_state
.fast_market_order()
.map(|fast_market_order| fast_market_order.fast_market_order_address)
.unwrap_or_else(|| {
Pubkey::new_unique()
});
let mut accounts = Self {
signer: payer_signer.pubkey(),
custodian: auction_accounts.custodian,
fast_market_order_address,
Expand All @@ -231,7 +227,17 @@ impl ExecuteOrderShimfulAccounts {
cctp_message,
post_message_sequence,
post_message_message,
};
if let Some(overwrite_accounts) = &config.overwrite_accounts {
for field in overwrite_accounts.iter() {
match field {
OverwriteAccountField::CctpTokenMessengerMinter(value) => {
accounts.token_messenger_minter_sender_authority = *value;
}
}
}
}
accounts
}
}

Expand Down Expand Up @@ -261,24 +267,24 @@ fn create_order_executed_state(
fn create_execute_order_shim_accounts<'ix>(
execute_order_fallback_accounts: &'ix ExecuteOrderShimfulAccounts,
clock_id: &'ix Pubkey,
) -> ExecuteOrderShimAccounts<'ix> {
ExecuteOrderShimAccounts {
signer: &execute_order_fallback_accounts.signer, // 0
cctp_message: &execute_order_fallback_accounts.cctp_message, // 1
) -> ExecuteOrderV2Accounts<'ix> {
ExecuteOrderV2Accounts {
payer: &execute_order_fallback_accounts.signer, // 0
new_cctp_message: &execute_order_fallback_accounts.cctp_message, // 1
custodian: &execute_order_fallback_accounts.custodian, // 2
fast_market_order: &execute_order_fallback_accounts.fast_market_order_address, // 3
active_auction: &execute_order_fallback_accounts.active_auction, // 4
active_auction_custody_token: &execute_order_fallback_accounts.active_auction_custody_token, // 5
active_auction_config: &execute_order_fallback_accounts.active_auction_config, // 6
active_auction_best_offer_token: &execute_order_fallback_accounts
auction_custody: &execute_order_fallback_accounts.active_auction_custody_token, // 5
auction_config: &execute_order_fallback_accounts.active_auction_config, // 6
auction_best_offer_token: &execute_order_fallback_accounts
.active_auction_best_offer_token, // 7
executor_token: &execute_order_fallback_accounts.executor_token, // 8
initial_offer_token: &execute_order_fallback_accounts.initial_offer_token, // 9
initial_participant: &execute_order_fallback_accounts.initial_participant, // 10
to_router_endpoint: &execute_order_fallback_accounts.to_router_endpoint, // 11
auction_initial_offer_token: &execute_order_fallback_accounts.initial_offer_token, // 9
auction_initial_participant: &execute_order_fallback_accounts.initial_participant, // 10
to_endpoint: &execute_order_fallback_accounts.to_router_endpoint, // 11
post_message_shim_program: &POST_MESSAGE_SHIM_PROGRAM_ID, // 12
core_bridge_emitter_sequence: &execute_order_fallback_accounts.post_message_sequence, // 13
post_shim_message: &execute_order_fallback_accounts.post_message_message, // 14
shim_message: &execute_order_fallback_accounts.post_message_message, // 14
cctp_deposit_for_burn_mint: &USDC_MINT, // 15
cctp_deposit_for_burn_token_messenger_minter_sender_authority:
&execute_order_fallback_accounts.token_messenger_minter_sender_authority, // 16
Expand All @@ -297,9 +303,6 @@ fn create_execute_order_shim_accounts<'ix>(
core_bridge_config: &CORE_BRIDGE_CONFIG, // 26
core_bridge_fee_collector: &CORE_BRIDGE_FEE_COLLECTOR, // 27
post_message_shim_event_authority: &POST_MESSAGE_SHIM_EVENT_AUTHORITY, // 28
system_program: &solana_program::system_program::ID, // 29
token_program: &spl_token::ID, // 30
clock: clock_id, // 31
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//!

use std::collections::HashSet;

use anchor_lang::prelude::Pubkey;
use crate::test_scenarios::make_offer::place_initial_offer_shimless;
use crate::testing_engine;
use crate::testing_engine::config::{
Expand Down Expand Up @@ -1084,6 +1084,39 @@ pub async fn test_execute_order_shim_emitter_chain_mismatch() {
.await;
}

/// Cannot execute order shim when the cctp token messenger minter program is not the expected program
#[tokio::test]
pub async fn test_execute_order_shim_cctp_token_messenger_minter_program_mismatch() {
let transfer_direction = TransferDirection::FromEthereumToArbitrum;
let (place_initial_offer_state, mut test_context, testing_engine) =
Box::pin(place_initial_offer_shim(
PlaceInitialOfferInstructionConfig::default(),
None,
transfer_direction,
))
.await;
let instruction_triggers = vec![InstructionTrigger::ExecuteOrderShim(
ExecuteOrderInstructionConfig {
expected_error: Some(ExpectedError {
instruction_index: 2,
error_code: 2006,
error_string: "ConstraintSeeds".to_string(),
}),
overwrite_accounts: Some(OverwriteAccounts(vec![OverwriteAccountField::CctpTokenMessengerMinter(
Pubkey::new_unique(),
)])),
..ExecuteOrderInstructionConfig::default()
},
)];
testing_engine
.execute(
&mut test_context,
instruction_triggers,
Some(place_initial_offer_state),
)
.await;
}

/// Cannot execute order shim before auction duration is over
#[tokio::test]
pub async fn test_execute_order_shim_before_auction_duration_is_over() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,26 @@ impl InstructionConfig for PrepareOrderResponseInstructionConfig {
}
}

#[derive(Clone)]
pub struct OverwriteAccounts(pub Vec<OverwriteAccountField>);

impl Deref for OverwriteAccounts {
type Target = Vec<OverwriteAccountField>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

#[derive(Clone)]
pub enum OverwriteAccountField {
CctpTokenMessengerMinter(Pubkey),
// Add other fields here if needed
}

#[derive(Clone)]
pub struct ExecuteOrderInstructionConfig {
pub fast_market_order_address: OverwriteCurrentState<Pubkey>,
pub overwrite_accounts: OverwriteCurrentState<OverwriteAccounts>,
pub actor_enum: TestingActorEnum,
pub token_enum: SplTokenEnum,
pub vaa_index: usize,
Expand All @@ -194,7 +211,7 @@ impl Default for ExecuteOrderInstructionConfig {
Self {
fast_forward_slots: 3,
actor_enum: TestingActorEnum::default(),
fast_market_order_address: None,
overwrite_accounts: None,
token_enum: SplTokenEnum::default(),
vaa_index: 0,
payer_signer: None,
Expand Down
Loading
Loading