Skip to content

Commit bcd0d84

Browse files
author
Bengt Lofgren
committed
from router passed to initialize fast market order
1 parent 890fba8 commit bcd0d84

File tree

8 files changed

+59
-33
lines changed

8 files changed

+59
-33
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub async fn initialize_fast_market_order_fallback(
4444
payer_signer: &Rc<Keypair>,
4545
fast_market_order: FastMarketOrderState,
4646
guardian_signature_info: &GuardianSignatureInfo,
47+
from_endpoint: &Pubkey,
4748
expected_error: Option<&ExpectedError>,
4849
) {
4950
let program_id = &testing_context.get_matching_engine_program_id();
@@ -52,6 +53,7 @@ pub async fn initialize_fast_market_order_fallback(
5253
program_id,
5354
fast_market_order,
5455
guardian_signature_info,
56+
from_endpoint,
5557
);
5658
let transaction = testing_context
5759
.create_transaction(
@@ -89,6 +91,7 @@ fn initialize_fast_market_order_fallback_instruction(
8991
program_id: &Pubkey,
9092
fast_market_order: FastMarketOrderState,
9193
guardian_signature_info: &GuardianSignatureInfo,
94+
from_endpoint: &Pubkey,
9295
) -> solana_program::instruction::Instruction {
9396
let fast_market_order_account = Pubkey::find_program_address(
9497
&[
@@ -105,6 +108,7 @@ fn initialize_fast_market_order_fallback_instruction(
105108
fast_market_order_account: &fast_market_order_account,
106109
guardian_set: &guardian_signature_info.guardian_set_pubkey,
107110
guardian_set_signatures: &guardian_signature_info.guardian_signatures_pubkey,
111+
from_endpoint: from_endpoint,
108112
verify_vaa_shim_program: &WORMHOLE_VERIFY_VAA_SHIM_PID,
109113
system_program: &solana_program::system_program::ID,
110114
};
@@ -220,7 +224,6 @@ pub fn create_fast_market_order_state_from_vaa_data(
220224
close_account_refund_recipient,
221225
vaa_sequence: vaa_data.sequence,
222226
vaa_timestamp: vaa_data.vaa_time,
223-
vaa_nonce: vaa_data.nonce,
224227
vaa_emitter_chain: vaa_data.emitter_chain,
225228
vaa_consistency_level: vaa_data.consistency_level,
226229
vaa_emitter_address: vaa_data.emitter_address,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ pub async fn test_initialize_fast_market_order_fallback() {
6969

7070
let instruction_triggers = vec![
7171
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
72+
InstructionTrigger::CreateCctpRouterEndpoints(
73+
CreateCctpRouterEndpointsInstructionConfig::default(),
74+
),
7275
InstructionTrigger::InitializeFastMarketOrderShim(
7376
InitializeFastMarketOrderShimInstructionConfig::default(),
7477
),
@@ -96,6 +99,9 @@ pub async fn test_close_fast_market_order_fallback() {
9699
let testing_engine = TestingEngine::new(testing_context).await;
97100
let instruction_triggers = vec![
98101
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
102+
InstructionTrigger::CreateCctpRouterEndpoints(
103+
CreateCctpRouterEndpointsInstructionConfig::default(),
104+
),
99105
InstructionTrigger::InitializeFastMarketOrderShim(
100106
InitializeFastMarketOrderShimInstructionConfig::default(),
101107
),
@@ -126,6 +132,9 @@ pub async fn test_close_fast_market_order_fallback_with_custom_refund_recipient(
126132
let testing_engine = TestingEngine::new(testing_context).await;
127133
let instruction_triggers = vec![
128134
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
135+
InstructionTrigger::CreateCctpRouterEndpoints(
136+
CreateCctpRouterEndpointsInstructionConfig::default(),
137+
),
129138
InstructionTrigger::InitializeFastMarketOrderShim(
130139
InitializeFastMarketOrderShimInstructionConfig {
131140
close_account_refund_recipient: Some(solver_1.pubkey()),
@@ -238,6 +247,9 @@ pub async fn test_fast_market_order_cannot_be_closed_twice() {
238247
let testing_engine = TestingEngine::new(testing_context).await;
239248
let instruction_triggers = vec![
240249
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
250+
InstructionTrigger::CreateCctpRouterEndpoints(
251+
CreateCctpRouterEndpointsInstructionConfig::default(),
252+
),
241253
InstructionTrigger::InitializeFastMarketOrderShim(
242254
InitializeFastMarketOrderShimInstructionConfig::default(),
243255
),
@@ -286,6 +298,9 @@ pub async fn test_fast_market_order_can_be_opened_after_being_closed_by_the_same
286298
let testing_engine = TestingEngine::new(testing_context).await;
287299
let instruction_triggers = vec![
288300
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
301+
InstructionTrigger::CreateCctpRouterEndpoints(
302+
CreateCctpRouterEndpointsInstructionConfig::default(),
303+
),
289304
InstructionTrigger::InitializeFastMarketOrderShim(
290305
InitializeFastMarketOrderShimInstructionConfig::default(),
291306
),
@@ -321,6 +336,9 @@ pub async fn test_multiple_fast_market_orders_can_be_opened_and_closed_by_differ
321336
let testing_engine = TestingEngine::new(testing_context).await;
322337
let instruction_triggers = vec![
323338
InstructionTrigger::InitializeProgram(InitializeInstructionConfig::default()),
339+
InstructionTrigger::CreateCctpRouterEndpoints(
340+
CreateCctpRouterEndpointsInstructionConfig::default(),
341+
),
324342
InstructionTrigger::InitializeFastMarketOrderShim(
325343
InitializeFastMarketOrderShimInstructionConfig {
326344
fast_market_order_id: 0,

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,35 +1066,22 @@ pub async fn test_execute_order_shim_emitter_chain_mismatch() {
10661066
InitializeFastMarketOrderShimInstructionConfig {
10671067
fast_market_order_id: 1,
10681068
vaa_index: 1,
1069+
expected_error: Some(ExpectedError {
1070+
instruction_index: 2,
1071+
error_code: u32::from(MatchingEngineError::InvalidEndpoint),
1072+
error_string: "InvalidEndpoint".to_string(),
1073+
}),
10691074
..InitializeFastMarketOrderShimInstructionConfig::default()
10701075
},
10711076
),
10721077
];
1073-
let initialize_second_fast_market_order_state = testing_engine
1078+
testing_engine
10741079
.execute(
10751080
&mut test_context,
10761081
initialize_second_fast_market_order_instruction_triggers,
10771082
Some(initialize_first_fast_market_order_state),
10781083
)
10791084
.await;
1080-
let instruction_triggers = vec![InstructionTrigger::ExecuteOrderShim(
1081-
ExecuteOrderInstructionConfig {
1082-
vaa_index: 1,
1083-
expected_error: Some(ExpectedError {
1084-
instruction_index: 0,
1085-
error_code: u32::from(MatchingEngineError::VaaMismatch),
1086-
error_string: "AccountNotInitialized".to_string(),
1087-
}),
1088-
..ExecuteOrderInstructionConfig::default()
1089-
},
1090-
)];
1091-
testing_engine
1092-
.execute(
1093-
&mut test_context,
1094-
instruction_triggers,
1095-
Some(initialize_second_fast_market_order_state),
1096-
)
1097-
.await;
10981085
}
10991086

11001087
/// Cannot execute order shim before auction duration is over

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ impl TestingEngine {
470470
current_state: &TestingEngineState,
471471
config: &InitializeFastMarketOrderShimInstructionConfig,
472472
) -> TestingEngineState {
473+
let from_router = current_state
474+
.router_endpoints()
475+
.unwrap()
476+
.endpoints
477+
.get_from_and_to_endpoint_addresses(self.testing_context.transfer_direction)
478+
.0;
473479
let test_vaa_pair = current_state.get_test_vaa_pair(config.vaa_index);
474480
let fast_transfer_vaa = test_vaa_pair.fast_transfer_vaa.clone();
475481
let fast_market_order = create_fast_market_order_state_from_vaa_data(
@@ -508,6 +514,7 @@ impl TestingEngine {
508514
&payer_signer,
509515
fast_market_order,
510516
&guardian_signature_info,
517+
&from_router,
511518
config.expected_error(),
512519
)
513520
.await;

solana/modules/matching-engine-testing/tests/utils/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Deref for TestRouterEndpoints {
9898
}
9999

100100
impl TestRouterEndpoints {
101-
#[allow(dead_code)]
101+
102102
pub fn get_from_and_to_endpoint_addresses(
103103
&self,
104104
transfer_direction: TransferDirection,

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

Lines changed: 19 additions & 3 deletions
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::{state::FastMarketOrder, ID};
6+
use crate::{error::MatchingEngineError, state::FastMarketOrder, ID};
77

88
pub struct InitializeFastMarketOrderAccounts<'ix> {
99
/// Lamports from this signer will be used to create the new fast market
@@ -15,6 +15,9 @@ pub struct InitializeFastMarketOrderAccounts<'ix> {
1515
/// instruction).
1616
// TODO: Rename to "new_fast_market_order".
1717
pub fast_market_order_account: &'ix Pubkey,
18+
19+
/// The from router endpoint account for the hash of the fast market order
20+
pub from_endpoint: &'ix Pubkey,
1821
/// Wormhole guardian set account used to check recovered pubkeys using
1922
/// [Self::guardian_set_signatures].
2023
// TODO: Rename to "wormhole_guardian_set"
@@ -68,6 +71,8 @@ impl InitializeFastMarketOrder<'_> {
6871
let InitializeFastMarketOrderAccounts {
6972
signer: payer,
7073
fast_market_order_account: new_fast_market_order,
74+
from_endpoint,
75+
7176
guardian_set: wormhole_guardian_set,
7277
guardian_set_signatures: shim_guardian_signatures,
7378
verify_vaa_shim_program,
@@ -79,6 +84,7 @@ impl InitializeFastMarketOrder<'_> {
7984
accounts: vec![
8085
AccountMeta::new(*payer, true),
8186
AccountMeta::new(*new_fast_market_order, false),
87+
AccountMeta::new_readonly(*from_endpoint, false),
8288
AccountMeta::new_readonly(*wormhole_guardian_set, false),
8389
AccountMeta::new_readonly(*shim_guardian_signatures, false),
8490
AccountMeta::new_readonly(*verify_vaa_shim_program, false),
@@ -119,8 +125,18 @@ pub(super) fn process(
119125
);
120126

121127
// These accounts will be used by the Verify VAA shim program.
122-
let wormhole_guardian_set_info = &accounts[2];
123-
let shim_guardian_signatures_info = &accounts[3];
128+
let from_endpoint = super::helpers::try_live_endpoint_account(&accounts[2], "from_endpoint")
129+
.map_err(|e: Error| e.with_account_name("from_endpoint"))?;
130+
131+
if fast_market_order.vaa_emitter_address != from_endpoint.address
132+
|| fast_market_order.vaa_emitter_chain != from_endpoint.chain
133+
{
134+
return Err(MatchingEngineError::InvalidEndpoint.into());
135+
}
136+
137+
// These accounts will be used by the Verify VAA shim program.
138+
let wormhole_guardian_set_info = &accounts[3];
139+
let shim_guardian_signatures_info = &accounts[4];
124140

125141
// Verify the VAA digest with the Verify VAA shim program.
126142
invoke_signed_unchecked(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ mod tests {
350350
close_account_refund_recipient: Pubkey::default(),
351351
vaa_sequence: 0,
352352
vaa_timestamp: 0,
353-
vaa_nonce: 0,
354353
vaa_emitter_chain: 0,
355354
vaa_consistency_level: 0,
356355
vaa_emitter_address: [0_u8; 32],

solana/programs/matching-engine/src/state/fast_market_order.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@ pub struct FastMarketOrder {
4343
pub vaa_sequence: u64,
4444
/// The timestamp of the fast transfer VAA.
4545
pub vaa_timestamp: u32,
46-
/// The VAA nonce, which is not used and can be set to 0.
47-
// TODO: Can be taken out.
48-
pub vaa_nonce: u32,
4946
/// The source chain of the fast transfer VAA. (represented as a Wormhole
5047
/// chain ID).
5148
pub vaa_emitter_chain: u16,
5249
/// The consistency level of the fast transfer VAA.
5350
pub vaa_consistency_level: u8,
5451
/// Not used, but required for bytemuck serialization.
55-
_padding: [u8; 5],
52+
_padding: [u8; 1],
5653
}
5754

5855
pub struct FastMarketOrderParams {
@@ -70,7 +67,6 @@ pub struct FastMarketOrderParams {
7067
pub close_account_refund_recipient: Pubkey,
7168
pub vaa_sequence: u64,
7269
pub vaa_timestamp: u32,
73-
pub vaa_nonce: u32,
7470
pub vaa_emitter_chain: u16,
7571
pub vaa_consistency_level: u8,
7672
pub vaa_emitter_address: [u8; 32],
@@ -95,11 +91,10 @@ impl FastMarketOrder {
9591
close_account_refund_recipient: params.close_account_refund_recipient,
9692
vaa_sequence: params.vaa_sequence,
9793
vaa_timestamp: params.vaa_timestamp,
98-
vaa_nonce: params.vaa_nonce,
9994
vaa_emitter_chain: params.vaa_emitter_chain,
10095
vaa_consistency_level: params.vaa_consistency_level,
10196
vaa_emitter_address: params.vaa_emitter_address,
102-
_padding: [0_u8; 5],
97+
_padding: [0_u8; 1],
10398
}
10499
}
105100

@@ -132,7 +127,8 @@ impl FastMarketOrder {
132127
wormhole_svm_definitions::compute_keccak_digest(
133128
keccak::hashv(&[
134129
&self.vaa_timestamp.to_be_bytes(),
135-
&self.vaa_nonce.to_be_bytes(),
130+
// The nonce is 0
131+
&0_u32.to_be_bytes(),
136132
&self.vaa_emitter_chain.to_be_bytes(),
137133
&self.vaa_emitter_address,
138134
&self.vaa_sequence.to_be_bytes(),

0 commit comments

Comments
 (0)