Skip to content

Commit 63e8df6

Browse files
committed
chore: anchor build successful with solana-cli v1.17.31
1 parent fd5baa6 commit 63e8df6

File tree

5 files changed

+70
-22
lines changed

5 files changed

+70
-22
lines changed

examples/oft-solana-composer-library/programs/composer/src/instructions/init_composer.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ pub struct InitComposer<'info> {
99
init,
1010
payer = payer,
1111
space = Composer::SIZE,
12-
seeds = [LZ_COMPOSE_TYPES_SEED, payer.key().as_ref(), &[params.id]],
12+
seeds = [COMPOSER_SEED, params.oft.as_ref()],
1313
bump
1414
)]
1515
pub composer: Account<'info, Composer>,
1616

17+
/// The LzComposeTypesAccounts account, storing extra addresses required for lz_compose_types.
18+
#[account(
19+
init,
20+
payer = payer,
21+
space = LzComposeTypesAccounts::SIZE,
22+
seeds = [LZ_COMPOSE_TYPES_SEED, composer.key().as_ref()],
23+
bump
24+
)]
25+
pub lz_compose_types_accounts: Account<'info, LzComposeTypesAccounts>,
26+
1727
#[account(mut)]
1828
pub payer: Signer<'info>,
1929

@@ -33,6 +43,12 @@ impl InitComposer<'_> {
3343
let composer = &mut ctx.accounts.composer;
3444
composer.oft = params.oft;
3545
composer.endpoint_program = params.endpoint_program;
46+
composer.bump = ctx.bumps.composer;
47+
48+
// Initialize lz_compose_types_accounts with the composer address.
49+
let lz_accounts = &mut ctx.accounts.lz_compose_types_accounts;
50+
lz_accounts.composer = composer.key();
51+
// Other fields in LzComposeTypesAccounts can be set as needed.
3652
Ok(())
3753
}
3854
}

examples/oft-solana-composer-library/programs/composer/src/instructions/lz_compose.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ use crate::*;
22
use anchor_lang::prelude::*;
33
use anchor_spl::token::{Token};
44
use anchor_spl::token_interface::{Token2022, TokenAccount, Mint};
5+
56
use raydium_clmm_cpi::cpi::accounts::SwapSingleV2;
67
use raydium_clmm_cpi::cpi::swap_v2;
78
use raydium_clmm_cpi::{
89
program::RaydiumClmm,
910
states::{AmmConfig, ObservationState, PoolState},
1011
};
12+
1113
use oapp::endpoint::{instructions::ClearComposeParams, ID as ENDPOINT_ID};
1214
use oapp::endpoint_cpi::clear_compose;
1315
use oapp::LzComposeParams;
16+
1417
use spl_memo;
1518

1619
#[derive(Accounts)]
@@ -88,6 +91,10 @@ pub struct LzCompose<'info> {
8891

8992
impl LzCompose<'_> {
9093
pub fn apply(ctx: &mut Context<LzCompose>, params: &LzComposeParams) -> Result<()> {
94+
// Validate that the message is coming from the expected OFT and addressed to this composer.
95+
require!(params.from == ctx.accounts.composer.oft, ComposerError::InvalidFrom);
96+
require!(params.to == ctx.accounts.composer.key(), ComposerError::InvalidTo);
97+
9198
let msg = &params.message;
9299
// Decode input amount from bytes 32..40.
93100
let amount_ld = u64::from_be_bytes(msg[32..40].try_into().unwrap());
@@ -131,7 +138,7 @@ impl LzCompose<'_> {
131138

132139
swap_v2(cpi_ctx, amount_ld, min_amount_out, 0u128, true)?;
133140

134-
// Use the stored "oft" field as the seed instead of a non-existent “id”.
141+
// Use the stored "oft" field as the seed.
135142
let seeds: &[&[u8]] = &[
136143
COMPOSER_SEED,
137144
&ctx.accounts.composer.oft.to_bytes(),

examples/oft-solana-composer-library/programs/composer/src/instructions/lz_compose_types.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ use anchor_lang::prelude::*;
22
use anchor_spl::token::{Token};
33
use anchor_spl::token_interface::{Token2022, TokenAccount, Mint};
44
use spl_memo;
5+
56
use raydium_clmm_cpi::{
67
program::RaydiumClmm,
78
states::{AmmConfig, ObservationState, PoolState},
89
};
10+
911
use oapp::endpoint_cpi::{get_accounts_for_clear_compose, LzAccount};
1012
use oapp::{endpoint::ID as ENDPOINT_ID, LzComposeParams};
1113

@@ -16,17 +18,12 @@ pub struct LzComposeTypes<'info> {
1618
pub payer: Signer<'info>,
1719
#[account(address = pool_state.load()?.amm_config)]
1820
pub amm_config: Box<Account<'info, AmmConfig>>,
19-
#[account(mut)]
2021
pub pool_state: AccountLoader<'info, PoolState>,
21-
#[account(mut)]
2222
pub input_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
23-
#[account(mut)]
2423
pub output_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
25-
#[account(mut)]
2624
pub input_vault: Box<InterfaceAccount<'info, TokenAccount>>,
27-
#[account(mut)]
2825
pub output_vault: Box<InterfaceAccount<'info, TokenAccount>>,
29-
#[account(mut, address = pool_state.load()?.observation_key)]
26+
#[account(address = pool_state.load()?.observation_key)]
3027
pub observation_state: AccountLoader<'info, ObservationState>,
3128
pub token_program: Program<'info, Token>,
3229
pub token_program_2022: Program<'info, Token2022>,
@@ -36,34 +33,25 @@ pub struct LzComposeTypes<'info> {
3633
pub input_vault_mint: Box<InterfaceAccount<'info, Mint>>,
3734
#[account(address = output_vault.mint)]
3835
pub output_vault_mint: Box<InterfaceAccount<'info, Mint>>,
39-
// Extra accounts required for the clear_compose call.
4036
/// The LayerZero endpoint program.
4137
pub lz_program: AccountInfo<'info>,
4238
/// The authority account for the swap.
4339
pub authority: AccountInfo<'info>,
4440
/// Tick array accounts for the swap range.
45-
#[account(mut)]
4641
pub tick_array_lower: AccountInfo<'info>,
47-
#[account(mut)]
4842
pub tick_array_current: AccountInfo<'info>,
49-
#[account(mut)]
5043
pub tick_array_upper: AccountInfo<'info>,
5144
}
5245

5346
impl LzComposeTypes<'_> {
54-
/// Generates the list of LzAccounts expected by the clear_compose call.
47+
/// Generates the ordered list of LzAccounts expected by the clear_compose call.
48+
/// Base accounts for the swap are listed first, followed by extra accounts.
5549
pub fn apply(
5650
ctx: &Context<LzComposeTypes>,
5751
params: &LzComposeParams,
5852
) -> Result<Vec<LzAccount>> {
59-
let mut accounts = get_accounts_for_clear_compose(
60-
ENDPOINT_ID,
61-
&params.from,
62-
&ctx.accounts.lz_program.key(),
63-
&params.guid,
64-
params.index,
65-
&params.message,
66-
);
53+
let mut accounts = Vec::new();
54+
// Base accounts for swap operations.
6755
accounts.push(LzAccount {
6856
pubkey: ctx.accounts.payer.key(),
6957
is_signer: true,
@@ -109,6 +97,33 @@ impl LzComposeTypes<'_> {
10997
is_signer: false,
11098
is_writable: true,
11199
});
100+
accounts.push(LzAccount {
101+
pubkey: ctx.accounts.tick_array_lower.key(),
102+
is_signer: false,
103+
is_writable: true,
104+
});
105+
accounts.push(LzAccount {
106+
pubkey: ctx.accounts.tick_array_current.key(),
107+
is_signer: false,
108+
is_writable: true,
109+
});
110+
accounts.push(LzAccount {
111+
pubkey: ctx.accounts.tick_array_upper.key(),
112+
is_signer: false,
113+
is_writable: true,
114+
});
115+
116+
// Append additional accounts required for clear_compose.
117+
let mut extra_accounts = get_accounts_for_clear_compose(
118+
ENDPOINT_ID,
119+
&params.from,
120+
&ctx.accounts.lz_program.key(),
121+
&params.guid,
122+
params.index,
123+
&params.message,
124+
);
125+
accounts.append(&mut extra_accounts);
126+
112127
Ok(accounts)
113128
}
114129
}

examples/oft-solana-composer-library/programs/composer/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ mod state;
33

44
use anchor_lang::prelude::*;
55
use instructions::*;
6+
67
use oapp::{endpoint_cpi::LzAccount, LzComposeParams};
8+
79
use state::*;
810

911
declare_id!("3NJ7AUBaj9N8kBsRqA7SYWJ1poEUsEW36gCG1EfLDkW2");

examples/oft-solana-composer-library/programs/composer/src/state/composer.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Composer {
1515
pub const SIZE: usize = 8 + 32 + 32 + 1;
1616
}
1717

18-
/// LzComposeTypesAccounts includes the pubkeys of all accounts used in the LzComposeTypes instruction.
18+
/// LzComposeTypesAccounts includes the pubkeys of all accounts used in the lz_compose_types instruction.
1919
/// (Adjust the fields as needed.)
2020
#[account]
2121
pub struct LzComposeTypesAccounts {
@@ -44,3 +44,11 @@ pub struct LzComposeTypesAccounts {
4444
impl LzComposeTypesAccounts {
4545
pub const SIZE: usize = 8 + std::mem::size_of::<Self>();
4646
}
47+
48+
#[error_code]
49+
pub enum ComposerError {
50+
#[msg("Invalid 'from' address. The message sender is not the expected OFT PDA.")]
51+
InvalidFrom,
52+
#[msg("Invalid 'to' address. The message recipient does not match the composer PDA.")]
53+
InvalidTo,
54+
}

0 commit comments

Comments
 (0)