Skip to content

Commit 2596c9a

Browse files
author
Bengt Lofgren
committed
added instruction for settle auction none cctp shim
1 parent db8d870 commit 2596c9a

File tree

15 files changed

+1036
-278
lines changed

15 files changed

+1036
-278
lines changed

solana/modules/matching-engine-testing/tests/shimful/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ pub mod post_message;
44
pub mod shims_execute_order;
55
pub mod shims_make_offer;
66
pub mod shims_prepare_order_response;
7+
pub mod shims_settle_auction_none;
78
pub mod verify_shim;

solana/modules/matching-engine-testing/tests/shimful/shims_execute_order.rs

Lines changed: 226 additions & 224 deletions
Large diffs are not rendered by default.
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
use anchor_lang::prelude::*;
2+
use anchor_spl::token::spl_token;
3+
use matching_engine::{
4+
fallback::{
5+
settle_auction_none_cctp::{
6+
SettleAuctionNoneCctpShimAccounts, SettleAuctionNoneCctpShimData,
7+
},
8+
FallbackMatchingEngineInstruction,
9+
},
10+
state::Auction,
11+
};
12+
use solana_program::instruction::Instruction;
13+
use solana_program_test::ProgramTestContext;
14+
use solana_sdk::{signature::Signer, sysvar::SysvarId, transaction::Transaction};
15+
use wormhole_svm_definitions::solana::{
16+
CORE_BRIDGE_PROGRAM_ID, POST_MESSAGE_SHIM_EVENT_AUTHORITY, POST_MESSAGE_SHIM_PROGRAM_ID,
17+
};
18+
19+
use crate::{
20+
testing_engine::{
21+
config::{InstructionConfig, SettleAuctionNoneShimInstructionConfig},
22+
setup::TestingContext,
23+
state::{OrderPreparedState, TestingEngineState},
24+
},
25+
utils::{auction::AuctionState, CORE_BRIDGE_CONFIG, CORE_BRIDGE_FEE_COLLECTOR},
26+
};
27+
28+
use super::shims_execute_order::{create_cctp_accounts, CctpAccounts};
29+
30+
pub struct SettleAuctionNoneCctpShim<'ix> {
31+
pub program_id: &'ix Pubkey,
32+
pub accounts: SettleAuctionNoneCctpShimAccounts<'ix>,
33+
pub data: SettleAuctionNoneCctpShimData,
34+
}
35+
36+
impl SettleAuctionNoneCctpShim<'_> {
37+
pub fn instruction(self) -> Instruction {
38+
Instruction {
39+
program_id: *self.program_id,
40+
accounts: self.accounts.to_account_metas(),
41+
data: FallbackMatchingEngineInstruction::SettleAuctionNoneCctp(self.data).to_vec(),
42+
}
43+
}
44+
}
45+
46+
pub async fn settle_auction_none_shimful(
47+
testing_context: &TestingContext,
48+
test_context: &mut ProgramTestContext,
49+
current_state: &TestingEngineState,
50+
config: &SettleAuctionNoneShimInstructionConfig,
51+
) -> AuctionState {
52+
let payer_signer = &config
53+
.payer_signer
54+
.clone()
55+
.unwrap_or_else(|| testing_context.testing_actors.payer_signer.clone());
56+
57+
let settle_auction_none_cctp_accounts =
58+
create_settle_auction_none_cctp_accounts(testing_context, current_state, config);
59+
let settle_auction_none_cctp_data = settle_auction_none_cctp_accounts.bumps;
60+
61+
let settle_auction_none_cctp_ix = SettleAuctionNoneCctpShim {
62+
program_id: &testing_context.get_matching_engine_program_id(),
63+
accounts: settle_auction_none_cctp_accounts.as_ref(),
64+
data: settle_auction_none_cctp_data,
65+
}
66+
.instruction();
67+
let last_blockhash = test_context.get_new_latest_blockhash().await.unwrap();
68+
let tx = Transaction::new_signed_with_payer(
69+
&[settle_auction_none_cctp_ix],
70+
Some(&payer_signer.pubkey()),
71+
&[&payer_signer],
72+
last_blockhash,
73+
);
74+
testing_context
75+
.execute_and_verify_transaction(test_context, tx, config.expected_error())
76+
.await;
77+
if config.expected_error().is_some() {
78+
return current_state.auction_state().clone();
79+
}
80+
81+
AuctionState::Settled
82+
}
83+
84+
struct SettleAuctionNoneCctpShimAccountsOwned {
85+
pub payer: Pubkey,
86+
pub post_message_message: Pubkey,
87+
pub post_message_sequence: Pubkey,
88+
pub post_message_shim_event_authority: Pubkey,
89+
pub post_message_shim_program: Pubkey,
90+
pub cctp_message: Pubkey,
91+
pub custodian: Pubkey,
92+
pub fee_recipient_token: Pubkey,
93+
pub closed_prepared_order_response_actor: Pubkey,
94+
pub closed_prepared_order_response: Pubkey,
95+
pub closed_prepared_order_response_custody_token: Pubkey,
96+
pub auction: Pubkey,
97+
pub cctp_mint: Pubkey,
98+
pub cctp_local_token: Pubkey,
99+
pub cctp_token_messenger_minter_event_authority: Pubkey,
100+
pub cctp_remote_token_messenger: Pubkey,
101+
pub cctp_token_messenger: Pubkey,
102+
pub cctp_token_messenger_minter_sender_authority: Pubkey,
103+
pub cctp_token_minter: Pubkey,
104+
pub cctp_token_messenger_minter_program: Pubkey,
105+
pub cctp_message_transmitter_config: Pubkey,
106+
pub cctp_message_transmitter_program: Pubkey,
107+
pub core_bridge_program: Pubkey,
108+
pub core_bridge_fee_collector: Pubkey,
109+
pub core_bridge_config: Pubkey,
110+
pub token_program: Pubkey,
111+
pub system_program: Pubkey,
112+
pub clock: Pubkey,
113+
pub rent: Pubkey,
114+
pub bumps: SettleAuctionNoneCctpShimData,
115+
}
116+
117+
impl SettleAuctionNoneCctpShimAccountsOwned {
118+
pub fn as_ref(&self) -> SettleAuctionNoneCctpShimAccounts {
119+
SettleAuctionNoneCctpShimAccounts {
120+
payer: &self.payer,
121+
post_message_message: &self.post_message_message,
122+
post_message_sequence: &self.post_message_sequence,
123+
post_message_shim_event_authority: &self.post_message_shim_event_authority,
124+
post_message_shim_program: &self.post_message_shim_program,
125+
cctp_message: &self.cctp_message,
126+
custodian: &self.custodian,
127+
fee_recipient_token: &self.fee_recipient_token,
128+
closed_prepared_order_response_actor: &self.closed_prepared_order_response_actor,
129+
closed_prepared_order_response: &self.closed_prepared_order_response,
130+
closed_prepared_order_response_custody_token: &self
131+
.closed_prepared_order_response_custody_token,
132+
auction: &self.auction,
133+
cctp_mint: &self.cctp_mint,
134+
cctp_local_token: &self.cctp_local_token,
135+
cctp_token_messenger_minter_event_authority: &self
136+
.cctp_token_messenger_minter_event_authority,
137+
cctp_remote_token_messenger: &self.cctp_remote_token_messenger,
138+
cctp_token_messenger: &self.cctp_token_messenger,
139+
cctp_token_messenger_minter_sender_authority: &self
140+
.cctp_token_messenger_minter_sender_authority,
141+
cctp_token_minter: &self.cctp_token_minter,
142+
cctp_token_messenger_minter_program: &self.cctp_token_messenger_minter_program,
143+
cctp_message_transmitter_config: &self.cctp_message_transmitter_config,
144+
cctp_message_transmitter_program: &self.cctp_message_transmitter_program,
145+
core_bridge_program: &self.core_bridge_program,
146+
core_bridge_fee_collector: &self.core_bridge_fee_collector,
147+
core_bridge_config: &self.core_bridge_config,
148+
token_program: &self.token_program,
149+
system_program: &self.system_program,
150+
clock: &self.clock,
151+
rent: &self.rent,
152+
}
153+
}
154+
}
155+
156+
fn create_settle_auction_none_cctp_accounts(
157+
testing_context: &TestingContext,
158+
current_state: &TestingEngineState,
159+
config: &SettleAuctionNoneShimInstructionConfig,
160+
) -> SettleAuctionNoneCctpShimAccountsOwned {
161+
let payer_signer = &config
162+
.payer_signer
163+
.clone()
164+
.unwrap_or_else(|| testing_context.testing_actors.payer_signer.clone());
165+
166+
let order_prepared_state = current_state.order_prepared().unwrap();
167+
let OrderPreparedState {
168+
prepared_order_response_address,
169+
prepared_custody_token,
170+
base_fee_token,
171+
actor_enum,
172+
} = *order_prepared_state;
173+
174+
let prepared_order_by = actor_enum
175+
.get_actor(&testing_context.testing_actors)
176+
.pubkey();
177+
178+
let custodian = current_state
179+
.custodian_address()
180+
.expect("Custodian address not found");
181+
182+
let fast_market_order = current_state.fast_market_order().unwrap().fast_market_order;
183+
let fast_vaa_hash = fast_market_order.digest();
184+
let (auction, auction_bump) = Pubkey::find_program_address(
185+
&[Auction::SEED_PREFIX, fast_vaa_hash.as_ref()],
186+
&testing_context.get_matching_engine_program_id(),
187+
);
188+
189+
let (cctp_message, cctp_message_bump) = Pubkey::find_program_address(
190+
&[common::CCTP_MESSAGE_SEED_PREFIX, &auction.to_bytes()],
191+
&testing_context.get_matching_engine_program_id(),
192+
);
193+
194+
let post_message_sequence = wormhole_svm_definitions::find_emitter_sequence_address(
195+
&custodian,
196+
&CORE_BRIDGE_PROGRAM_ID,
197+
)
198+
.0;
199+
let post_message_message = wormhole_svm_definitions::find_shim_message_address(
200+
&custodian,
201+
&POST_MESSAGE_SHIM_PROGRAM_ID,
202+
)
203+
.0;
204+
205+
let CctpAccounts {
206+
mint,
207+
local_token,
208+
token_messenger_minter_event_authority,
209+
remote_token_messenger,
210+
token_messenger,
211+
token_messenger_minter_sender_authority,
212+
token_minter,
213+
token_messenger_minter_program,
214+
message_transmitter_config,
215+
message_transmitter_program,
216+
} = create_cctp_accounts(current_state, testing_context);
217+
SettleAuctionNoneCctpShimAccountsOwned {
218+
payer: payer_signer.pubkey(),
219+
post_message_message,
220+
post_message_sequence,
221+
post_message_shim_event_authority: POST_MESSAGE_SHIM_EVENT_AUTHORITY,
222+
post_message_shim_program: POST_MESSAGE_SHIM_PROGRAM_ID,
223+
cctp_message,
224+
custodian,
225+
fee_recipient_token: base_fee_token,
226+
closed_prepared_order_response_actor: prepared_order_by,
227+
closed_prepared_order_response: prepared_order_response_address,
228+
closed_prepared_order_response_custody_token: prepared_custody_token,
229+
auction,
230+
cctp_mint: mint,
231+
cctp_local_token: local_token,
232+
cctp_token_messenger_minter_event_authority: token_messenger_minter_event_authority,
233+
cctp_remote_token_messenger: remote_token_messenger,
234+
cctp_token_messenger: token_messenger,
235+
cctp_token_messenger_minter_sender_authority: token_messenger_minter_sender_authority,
236+
cctp_token_minter: token_minter,
237+
cctp_token_messenger_minter_program: token_messenger_minter_program,
238+
cctp_message_transmitter_config: message_transmitter_config,
239+
cctp_message_transmitter_program: message_transmitter_program,
240+
core_bridge_program: CORE_BRIDGE_PROGRAM_ID,
241+
core_bridge_fee_collector: CORE_BRIDGE_FEE_COLLECTOR,
242+
core_bridge_config: CORE_BRIDGE_CONFIG,
243+
token_program: spl_token::ID,
244+
system_program: solana_program::system_program::ID,
245+
clock: solana_program::clock::Clock::id(),
246+
rent: solana_program::rent::Rent::id(),
247+
bumps: SettleAuctionNoneCctpShimData {
248+
cctp_message_bump,
249+
auction_bump,
250+
},
251+
}
252+
}

solana/modules/matching-engine-testing/tests/test_scenarios/settle_auction.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,62 @@ pub async fn test_settle_auction_base_fee_token_not_best_offer_actor() {
239239
.await;
240240
}
241241

242+
/// Test settle auction none shim
243+
#[tokio::test]
244+
pub async fn test_settle_auction_none_shim() {
245+
let transfer_direction = TransferDirection::FromEthereumToArbitrum;
246+
let (testing_context, mut test_context) = setup_environment(
247+
ShimMode::VerifyAndPostSignature,
248+
transfer_direction,
249+
Some(vec![VaaArgs::default()]),
250+
)
251+
.await;
252+
let testing_engine = TestingEngine::new(testing_context).await;
253+
254+
let instruction_triggers = vec![
255+
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
256+
InstructionTrigger::CreateCctpRouterEndpoints(
257+
CreateCctpRouterEndpointsInstructionConfig::default(),
258+
),
259+
];
260+
let create_cctp_router_endpoints_state = testing_engine
261+
.execute(&mut test_context, instruction_triggers, None)
262+
.await;
263+
264+
// This is just needed to get the router endpoint accounts when prepare order happens before place initial offer, it is not used for anything else
265+
let fake_auction_accounts = AuctionAccounts::fake_auction_accounts(
266+
&create_cctp_router_endpoints_state,
267+
&testing_engine.testing_context,
268+
);
269+
let instruction_triggers = vec![
270+
InstructionTrigger::InitializeFastMarketOrderShim(
271+
InitializeFastMarketOrderShimInstructionConfig::default(),
272+
),
273+
InstructionTrigger::PrepareOrderShim(PrepareOrderResponseInstructionConfig {
274+
overwrite_auction_accounts: Some(fake_auction_accounts),
275+
..Default::default()
276+
}),
277+
];
278+
let prepared_order_state = testing_engine
279+
.execute(
280+
&mut test_context,
281+
instruction_triggers,
282+
Some(create_cctp_router_endpoints_state),
283+
)
284+
.await;
285+
286+
let instruction_triggers = vec![InstructionTrigger::SettleAuctionNoneShim(
287+
SettleAuctionNoneShimInstructionConfig::default(),
288+
)];
289+
testing_engine
290+
.execute(
291+
&mut test_context,
292+
instruction_triggers,
293+
Some(prepared_order_state),
294+
)
295+
.await;
296+
}
297+
242298
/*
243299
Sad path tests section
244300

solana/modules/matching-engine-testing/tests/testing_engine/config.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl InstructionConfig for PrepareOrderResponseInstructionConfig {
177177

178178
#[derive(Clone)]
179179
pub struct ExecuteOrderInstructionConfig {
180-
pub fast_market_order_address: OverwriteCurrentState<Pubkey>,
180+
pub override_fast_market_order_address: OverwriteCurrentState<Pubkey>,
181181
pub actor_enum: TestingActorEnum,
182182
pub token_enum: SplTokenEnum,
183183
pub vaa_index: usize,
@@ -192,7 +192,7 @@ impl Default for ExecuteOrderInstructionConfig {
192192
Self {
193193
fast_forward_slots: 3,
194194
actor_enum: TestingActorEnum::default(),
195-
fast_market_order_address: None,
195+
override_fast_market_order_address: None,
196196
token_enum: SplTokenEnum::default(),
197197
vaa_index: 0,
198198
payer_signer: None,
@@ -619,3 +619,19 @@ pub struct BalanceChange {
619619
pub usdc: i32,
620620
pub usdt: i32,
621621
}
622+
623+
#[derive(Default)]
624+
pub struct SettleAuctionNoneShimInstructionConfig {
625+
pub payer_signer: Option<Rc<Keypair>>,
626+
pub expected_error: Option<ExpectedError>,
627+
pub expected_log_messages: Option<Vec<ExpectedLog>>,
628+
}
629+
630+
impl InstructionConfig for SettleAuctionNoneShimInstructionConfig {
631+
fn expected_error(&self) -> Option<&ExpectedError> {
632+
self.expected_error.as_ref()
633+
}
634+
fn expected_log_messages(&self) -> Option<&Vec<ExpectedLog>> {
635+
self.expected_log_messages.as_ref()
636+
}
637+
}

0 commit comments

Comments
 (0)