# Processor Swap Raydium

This Processor enables token swaps from a Raydium pool. The swap is executed via [Raydium AMM Routing](https://solscan.io/account/routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS) contract—the same contract used when you swap tokens through the [Raydium](https://raydium.io/swap) interface.

Libraries used in the swap Processor code:

| Library name                                                                           | Version      |
| -------------------------------------------------------------------------------------- | ------------ |
| [@raydium-io/raydium-sdk-v2](https://www.npmjs.com/package/@raydium-io/raydium-sdk-v2) | 0.1.94-alpha |
| [@solana/web3.js](https://www.npmjs.com/package/@solana/web3.js)                       | 1.95.0       |
| [@solana/spl-token](https://www.npmjs.com/package/@solana/spl-token)                   | 0.4.6        |

{% hint style="info" %}
Note: This Processor only swaps within a single pool and does not use an aggregator to swap across multiple pools. Therefore, you must configure the pool address for the swap.
{% endhint %}

<figure><img src="https://content.gitbook.com/content/56Mr5hKBuQpU8OOb4JWG/blobs/tCHNY1GfNCu7S0PCskjd/swap_raydium_config.png" alt="" width="375"><figcaption><p>Example: Swapping FARTCOIN tokens to SOL</p></figcaption></figure>

In the example above, the configuration swaps FARTCOIN tokens to SOL using the [FARTCOIN/SOL](https://dexscreener.com/solana/bzc9nzfmqkxr6fz1dbph7bdf9broyef6pnzesp7v5iiw) pool on the Solana network.

Configuration meanings:

<table><thead><tr><th width="233.84375">Field name</th><th width="117.5546875"> Required?</th><th>Ý nghĩa</th></tr></thead><tbody><tr><td>Variable name for storing result</td><td>Yes</td><td>This Processor will output the transaction hash of the swap. You can choose a variable name to store the transaction hash. For example: <code>TX_HASH_SWAP_TOKEN_RAYDIUM</code></td></tr><tr><td>Private key</td><td>Yes</td><td>This is the private key of the wallet performing the transaction. Each Profile has a default variable for storing the private key, so you can use the default variable <code>WALLET_PRIVATE_KEY</code></td></tr><tr><td>Node endpoint group</td><td>Yes</td><td>Select the node provider to interact with the blockchain</td></tr><tr><td>Pool address</td><td>Yes</td><td>The address of the pool you want to swap</td></tr><tr><td>Input token address</td><td>Yes</td><td>A pool contains two tokens. Here, you enter the address of the token you want to swap from. For example, if you want to swap FARTCOIN for SOL (sell FARTCOIN), input the address of the FARTCOIN token in this field</td></tr><tr><td>Output token address</td><td>Yes</td><td>Enter the address of the token you want to receive after the swap. For example, if you are swapping FARTCOIN for SOL (selling FARTCOIN), input the address of the SOL token here</td></tr><tr><td>Amount of input token</td><td>Yes</td><td>Enter the amount of tokens you want to sell. For example, if you want to sell 1,000 FARTCOIN for SOL, enter <code>1000</code></td></tr><tr><td>Slippage tolerance (%)</td><td>Yes</td><td>Maximum slippage for swaps. For pools with low price volatility, you should set this value low (e.g., 0.3%, 0.5%). For pools with high price volatility over short periods, set a higher value to increase the likelihood of a successful swap</td></tr><tr><td>Max price impact (%)</td><td>Yes</td><td>Maximum price impact for swaps. For pools with high liquidity, you should set this value low (e.g., 0.3%, 0.5%). For pools with low liquidity, you may choose a higher value</td></tr><tr><td>Priority fee (Micro lamport)</td><td>No</td><td>Priority fee for executing transactions. If you leave this field blank, the system will use the current average priority fee of the chain. For best results, it is recommended to specify a priority fee to increase the likelihood of a successful swap transaction</td></tr><tr><td>Total number of transaction</td><td>Yes</td><td>The minimum value is 1. If you enter a value greater than 1, such as <code>10</code>, this Processor will broadcast 10 swap transactions simultaneously to increase the chances of multiple transactions being mined in the same block</td></tr><tr><td>Wait for the transaction to be confirmed?</td><td>No</td><td>If you enable this option, the Processor will wait for the swap transaction to be confirmed before proceeding to the next Processor. If you leave it unchecked, the Processor will broadcast the swap transaction without waiting for confirmation and immediately move on to the next Processor</td></tr></tbody></table>

#### How to select the Priority fee for the Processor <a href="#cach-chon-gas-limit-gas-price" id="cach-chon-gas-limit-gas-price"></a>

If you want your transaction to be mined faster by competing on gas, you can manually set the `Priority fee (in micro lamports)` for the Processor.

For example, if you want to swap tokens in the [FARTCOIN/SOL](https://dexscreener.com/solana/bzc9nzfmqkxr6fz1dbph7bdf9broyef6pnzesp7v5iiw) pool, review several recent transactions to see their Priority fee. This will help you select an appropriate value for the Processor.

Using the following transaction as a reference: <https://solscan.io/tx/dYyK6KWMEzeigoCWBhzebgBjK1LDqPwxJyv16abW1vjEDhfEEoGV6Q2V2PUEXWBzbyyRp6GWQDDGGYqesZE4Eq6>, navigate to the **Instruction Detail** > **SetComputeUnitLimit** section to view the Priority fee. Based on this, you can set the `Priority fee (Micro lamports)` to `250000`.

<figure><img src="https://content.gitbook.com/content/56Mr5hKBuQpU8OOb4JWG/blobs/S7UGfv8R1U5Dm5VMzQWf/sol_priority_fee.png" alt=""><figcaption><p>Example of how to determine the Priority fee</p></figcaption></figure>
