You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Builds on Solana CLI v1.18.x (and above) will hit a “stack offset exceeded” error due to changes in codegen.
In this PR:
Implements a Raydium Composer for OFT’s on Solana that calls the swap_v2 method from Raydium AMM V3 via the CPI helper.
Utilizes the raydium-cpi and raydium-cpi-example repositories (both targeting Anchor 0.29.0) to integrate CLMM swap functionality. The implementation shows how to trigger the swap through the lzCompose method.
Integrates with LayerZero messaging so that after the swap CPI is executed, the corresponding LayerZero compose state is cleared.
Testing & Validation:
Verified that the minimal context for the swap CPI meets the Raydium AMM V3 requirements.
Ensured proper integration with LayerZero messaging—after executing the swap, the compose message is cleared as expected.
Reviewed the generated code (using tools like cargo expand) to confirm that only the necessary accounts and fields are compiled.
Currently testing framework using the solana-local-validator and cloning the necessary programs:
attkrak ~/…/composer-library [feat/oft-solana-composer-example] $ anchor build
Error: Function … Stack offset of 4608 exceeded max offset of 4096 by 512 bytes, please minimize large stack variables
Finished release [optimized] target(s) in 0.26s
Finished test [unoptimized + debuginfo] target(s) in 0.48s
…
The offchain executor first retrieves the data from the lz_compose_types_accounts PDA to identify which accounts are needed for the lz_compose_types instruction
The executor then calls the lz_compose_types instruction with these accounts, which returns the complete list of accounts needed for lz_compose call
The executor assembles all these accounts and calls lz_compose
Inside lz_compose, this composer program should:
Validate the message is from the expected OFT (stored in composer pda)
Perform the Raydium swap via CPI call
Clear the compose message state via the clear_compose CPI call
Emit events
After a thorough review, I have some comments.
For the init_composer instruction:
I recommend implementing two clearly defined PDA in this instruction:
a) The composer PDA:
- Can be derived using a seed pattern such as [COMPOSER_SEED, oft_pda.key()]
- Should store critical data like:
• The OFT PDA address for validation during compose operations
• Any configuration
- This account acts as the main program state and authority
b) The lz_compose_types_accounts PDA:
- Must be derived specifically with [LZ_COMPOSE_TYPES_SEED, composer.key()]
- Try to keep only necessary account addresses, which cannot be deterministically derived at runtime through PDA
This mode ensures that the offchain executor can correctly discover all required accounts
For the lz_compose_types instruction:
This instruction functions as a view function and should not modify any state
All account annotations should reflect this by removing #[account(mut)] macro
The implementation should ensure that accounts appear in the correct order for both the swap operation and subsequent clearing of the compose state:
First retrieve the base accounts needed for swap operations
Then append the accounts required by get_accounts_for_clear_compose
Return a complete, ordered list of accounts that the executor will provide to lz_compose
@St0rmBr3w@ziming-zung
When do you expect this PR could be merged?
I am looking forward to an example like this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR:
swap_v2method from Raydium AMM V3 via the CPI helper.lzComposemethod.Testing & Validation:
cargo expand) to confirm that only the necessary accounts and fields are compiled.Build Errors (when using Solana CLI ≥ 1.18.x)