0

I need to create a Program with a function swap_on_dex(...) which will accept an input token with an amount, a target wallet address and execute a swap for SOL (optionally, for other token) on any popular DEX: Orca, Raydium, Serum, Jupiter.

I haven't found any info about the topic. I've looked into Raydium which is the most popular DEX, yet to no avail.

There're, however, examples of how to execute this on the client side, that is, off-chain. But I need it within a Program - on-chain, in Rust.

How to do it? Any simple example?

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Feb 27 at 8:42

1 Answer 1

1

Calling another contract from within an on-chain contract on Solana is referred to as CPI (cross program invocations). You can read more about it here.

Here are the rust bindings for Raydium's contracts https://github.com/raydium-io/raydium-contract-instructions/tree/master. Orca CPI crate: https://github.com/orca-so/whirlpool-cpi.

1
  • Thansk. How to approach this? Is there any simple example?
    – ursula
    Commented Mar 4 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.