precious-void / raydium-swap

Swap example using the Raydium SDK
120 stars 39 forks source link

Revert Swap #11

Closed shillinboi closed 1 day ago

shillinboi commented 4 months ago

Sorry for asking this question but I am confuse on how to sell instead of buy. I manage to get the code to work but when I want to sell I assume we need to change 'in' to 'out' and u swap base and quote address? but then how can we add the code so we can specify how much we want to sell?

DeepBorys commented 4 months ago

You have to swap the base and quote mint in the poolKeys. Below a hardcoded example for Maneki.

const targetPoolInfo = yield (0, formatAmmKeysById_1.formatAmmKeysById)(pool_x);

// Swap the base and quote mints. targetPoolInfo["baseMint"] = "So11111111111111111111111111111111111111112"; targetPoolInfo["quoteMint"] = "25hAyBQfoDhfWx9ay6rarbgvWGwDdNqcHsXS3jQ3mTDJ"

const poolKeys = (0, raydium_sdk_1.jsonInfo2PoolKeys)(targetPoolInfo);

precious-void commented 4 months ago

Or you can simply "swap" the first parameter passed to the getSwapInstructions function. Note to update token accounts and amount passed to this function respectively.