@@ -2,10 +2,12 @@ use anchor_lang::prelude::*;
22use anchor_spl:: token:: { Token } ;
33use anchor_spl:: token_interface:: { Token2022 , TokenAccount , Mint } ;
44use spl_memo;
5+
56use raydium_clmm_cpi:: {
67 program:: RaydiumClmm ,
78 states:: { AmmConfig , ObservationState , PoolState } ,
89} ;
10+
911use oapp:: endpoint_cpi:: { get_accounts_for_clear_compose, LzAccount } ;
1012use 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
5346impl 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}
0 commit comments