Skip to content

Commit 324fa88

Browse files
author
Bengt Lofgren
committed
improved place initial offer shim
1 parent b506928 commit 324fa88

File tree

8 files changed

+40
-50
lines changed

8 files changed

+40
-50
lines changed

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,11 @@ use crate::error::MatchingEngineError;
2222
#[repr(C)]
2323
pub struct PlaceInitialOfferCctpShimData {
2424
pub offer_price: u64,
25-
pub sequence: u64,
26-
pub vaa_time: u32,
27-
pub consistency_level: u8,
28-
_padding: [u8; 3],
2925
}
3026

3127
impl PlaceInitialOfferCctpShimData {
32-
pub fn new(offer_price: u64, sequence: u64, vaa_time: u32, consistency_level: u8) -> Self {
33-
Self {
34-
offer_price,
35-
sequence,
36-
vaa_time,
37-
consistency_level,
38-
_padding: [0_u8; 3],
39-
}
28+
pub fn new(offer_price: u64) -> Self {
29+
Self { offer_price }
4030
}
4131

4232
pub fn from_bytes(data: &[u8]) -> Option<&Self> {
@@ -193,13 +183,7 @@ pub fn place_initial_offer_cctp_shim(
193183
check_account_length(accounts, 11)?;
194184
// Extract data fields
195185
// TODO: Remove sequence, vaa_time because they are in the fast market order state
196-
let PlaceInitialOfferCctpShimData {
197-
offer_price,
198-
sequence,
199-
vaa_time,
200-
consistency_level,
201-
_padding,
202-
} = *data;
186+
let PlaceInitialOfferCctpShimData { offer_price } = *data;
203187

204188
let signer = &accounts[0];
205189
let transfer_authority = &accounts[1];
@@ -217,6 +201,10 @@ pub fn place_initial_offer_cctp_shim(
217201
let fast_market_order_zero_copy =
218202
FastMarketOrderState::try_deserialize(&mut &fast_market_order_account.data.borrow()[..])?;
219203

204+
let vaa_time = fast_market_order_zero_copy.vaa_timestamp;
205+
let sequence = fast_market_order_zero_copy.vaa_sequence;
206+
let consistency_level = fast_market_order_zero_copy.vaa_consistency_level;
207+
220208
// Check pda of the transfer authority is valid
221209
let transfer_authority_seeds = [
222210
TRANSFER_AUTHORITY_SEED_PREFIX,

solana/programs/matching-engine/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#![allow(clippy::result_large_err)]
33

44
mod composite;
5-
// use composite::*;
5+
use composite::*;
66

7-
pub mod error;
7+
mod error;
88

99
mod events;
1010

@@ -480,9 +480,9 @@ pub mod matching_engine {
480480
}
481481

482482
/// UNUSED. This instruction does not exist and has never existed. It just reverts and exist to expose an account lol.
483-
// pub fn get_cctp_mint_recipient(_ctx: Context<CctpMintRecipientMut>) -> Result<()> {
484-
// err!(ErrorCode::InstructionMissing)
485-
// }
483+
pub fn get_cctp_mint_recipient(_ctx: Context<CctpMintRecipientMut>) -> Result<()> {
484+
err!(ErrorCode::InstructionMissing)
485+
}
486486

487487
/// Non anchor function for placing an initial offer using the VAA shim.
488488
pub fn fallback_process_instruction(

solana/programs/matching-engine/tests/shimful/shims_make_offer.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@ pub async fn place_initial_offer_fallback(
8282

8383
let solver_usdc_balance_before = solver.get_balance(test_ctx).await;
8484

85-
let place_initial_offer_ix_data = PlaceInitialOfferCctpShimFallbackData::new(
86-
offer_price,
87-
vaa_data.sequence,
88-
vaa_data.vaa_time,
89-
vaa_data.consistency_level,
90-
);
85+
let place_initial_offer_ix_data = PlaceInitialOfferCctpShimFallbackData::new(offer_price);
9186

9287
let place_initial_offer_ix_accounts = PlaceInitialOfferCctpShimFallbackAccounts {
9388
signer: &payer_signer.pubkey(),

solana/programs/matching-engine/tests/testing_engine/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ pub struct InitializeInstructionConfig {
2626

2727
pub struct CreateCctpRouterEndpointsInstructionConfig {
2828
pub chains: HashSet<Chain>,
29+
pub admin_owner_or_assistant: Option<Rc<Keypair>>,
2930
pub expected_error: Option<ExpectedError>,
3031
}
3132

3233
impl Default for CreateCctpRouterEndpointsInstructionConfig {
3334
fn default() -> Self {
3435
Self {
3536
chains: HashSet::from([Chain::Ethereum, Chain::Arbitrum, Chain::Solana]),
37+
admin_owner_or_assistant: None,
3638
expected_error: None,
3739
}
3840
}

solana/programs/matching-engine/tests/testing_engine/engine.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::utils::{
1717
setup::TestingContext,
1818
};
1919
use anchor_lang::prelude::*;
20+
use solana_sdk::signature::Signer;
2021

2122
#[allow(dead_code)]
2223
pub enum InstructionTrigger {
@@ -209,11 +210,15 @@ impl TestingEngine {
209210
.expect("Testing state is not initialized");
210211
let custodian_address = initialized_state.custodian_address;
211212
let testing_actors = &self.testing_context.testing_actors;
213+
let admin_owner_or_assistant = config
214+
.admin_owner_or_assistant
215+
.clone()
216+
.unwrap_or_else(|| testing_actors.owner.keypair());
212217
let result = create_all_router_endpoints_test(
213218
&self.testing_context,
214-
testing_actors.owner.pubkey(),
219+
admin_owner_or_assistant.pubkey(),
215220
custodian_address,
216-
testing_actors.owner.keypair(),
221+
admin_owner_or_assistant,
217222
config.chains.clone(),
218223
)
219224
.await;

solana/programs/matching-engine/tests/utils/constants.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,6 @@ pub fn get_player_one_keypair() -> Keypair {
115115

116116
pub const ETHEREUM_USDC_ADDRESS: &str = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
117117

118-
// Chain to cctp domain mapping
119-
pub const CHAIN_TO_DOMAIN: &[(Chain, u32)] = &[
120-
(Chain::Ethereum, 0),
121-
(Chain::Avalanche, 1),
122-
(Chain::Optimism, 2),
123-
(Chain::Arbitrum, 3),
124-
(Chain::Solana, 5),
125-
(Chain::Base, 6),
126-
(Chain::Polygon, 7),
127-
];
128-
129118
// Enum for Chain types
130119
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
131120
pub enum Chain {
@@ -150,6 +139,18 @@ impl Chain {
150139
Chain::Polygon => 6,
151140
}
152141
}
142+
143+
pub fn as_cctp_domain(&self) -> u32 {
144+
match self {
145+
Chain::Ethereum => 0,
146+
Chain::Avalanche => 1,
147+
Chain::Optimism => 2,
148+
Chain::Arbitrum => 3,
149+
Chain::Solana => 5,
150+
Chain::Base => 6,
151+
Chain::Polygon => 7,
152+
}
153+
}
153154
}
154155

155156
// Registered Token Routers

solana/programs/matching-engine/tests/utils/router.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub async fn add_cctp_router_endpoint_ix(
189189
let ix_data = AddCctpRouterEndpoint {
190190
args: AddCctpRouterEndpointArgs {
191191
chain: chain.as_chain_id(),
192-
cctp_domain: CHAIN_TO_DOMAIN[chain.as_index()].1,
192+
cctp_domain: chain.as_cctp_domain(),
193193
address: registered_token_router_address,
194194
mint_recipient: None,
195195
},
@@ -237,7 +237,7 @@ pub async fn add_cctp_router_endpoint_ix(
237237
&Pubkey::new_from_array(registered_token_router_address),
238238
None,
239239
matching_engine::state::MessageProtocol::Cctp {
240-
domain: CHAIN_TO_DOMAIN[chain.as_index()].1,
240+
domain: chain.as_cctp_domain(),
241241
},
242242
);
243243
test_router_endpoint
@@ -334,7 +334,7 @@ pub async fn create_cctp_router_endpoint(
334334
) -> TestRouterEndpoint {
335335
let fixture_accounts = testing_context.get_fixture_accounts().unwrap();
336336
let program_id = testing_context.get_matching_engine_program_id();
337-
let token_messenger = match chain {
337+
let remote_token_messenger = match chain {
338338
Chain::Arbitrum => fixture_accounts.arbitrum_remote_token_messenger,
339339
Chain::Ethereum => fixture_accounts.ethereum_remote_token_messenger,
340340
_ => {
@@ -348,7 +348,7 @@ pub async fn create_cctp_router_endpoint(
348348
custodian_address,
349349
admin_keypair.as_ref(),
350350
program_id,
351-
token_messenger,
351+
remote_token_messenger,
352352
chain,
353353
)
354354
.await

solana/programs/matching-engine/tests/utils/vaa.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use wormhole_svm_definitions::GUARDIAN_SIGNATURE_LENGTH;
77

88
use super::constants::Chain;
99
use super::setup::TestingContext;
10-
use super::CHAIN_TO_DOMAIN;
1110

1211
use super::constants::CORE_BRIDGE_PID;
1312
use borsh::{BorshDeserialize, BorshSerialize};
@@ -409,8 +408,8 @@ pub fn create_deposit_message(
409408
let deposit = Deposit {
410409
token_address: token_mint.to_bytes(),
411410
amount: ruint::aliases::U256::from(amount),
412-
source_cctp_domain: CHAIN_TO_DOMAIN[source_address.chain.as_index()].1,
413-
destination_cctp_domain: CHAIN_TO_DOMAIN[Chain::Solana.as_index()].1, // Hardcode solana as destination domain
411+
source_cctp_domain: source_address.chain.as_cctp_domain(),
412+
destination_cctp_domain: Chain::Solana.as_cctp_domain(), // Hardcode solana as destination domain
414413
cctp_nonce,
415414
burn_source: source_address.address.to_bytes(), // Token router address
416415
mint_recipient: cctp_mint_recipient.to_bytes(), // Mint recipient program id

0 commit comments

Comments
 (0)