Adding priority fees to the CLMM closing position in Solanu using SDK V2 Raydium using SDK V2 **
Raydium, a popular decentralized replacement platform (DEX), was provided by SDK V2 for the development of custom trading applications. One of the common scenarios in which users may need to implement priority fees is to close the positions requiring liquidity at market price or above. In this article, you will lead you to add priority fees to the CLMM script (closing the market) in Solan with SDK V2 in Raydium.
preliminary requirements
- Knowledge of the raydium programming language and SOL programming
- Basic understanding of trade logic and priority fees
Step 1: Create a new script
Create a new file for a custom script, e.g. clmm_close_poscion.py
. This file will contain logic to close the position using SDK V2 Raydium.
`Solana-program
Import {SDK} with "Raydium-SDK";
/**
* CLMM script close to position.
*
* @param {SDK} SDK - instance of Raydium SDK.
*/
Export the asynchronization function Closeposis (position) {
// get the current market manufacturer (cm) and closing price.
Const cm = position.cm;
Const closingprice = position.
// Check if CM has priority fees enabled.
if (cm.haspriorityfeesenabled ()) {
// Calculate the transaction fee based on the market bidding/queries of the market manufacturer.
Const Fee = (Closingprice - cm.bid) / cm. Aask * 0.0001; // 100 SOL
// Close the position with the SDK V2 Raydium.
Wait for SDK.ClosePosition (CM, Calmingprice, {
Amount: 1, // close one unit of items
fee,
});
} otherwise {
// If the priority fees are not enabled, close the position as usual.
They are waiting for SDK.
}
}
Step 2: Register the script in Raydium
To use the script, you must register it in Raydium. This includes the creation of a new “script” and registration of a custom function.
`Solana-program
Import {Script} with "Raydium-SDK";
// Create a new script instance.
Const ClmmClosePOSition = New Script ();
// Register the script in Raydium.
CLMMMCLOSEPOSITION.REGIST ("CLOSEPOSITION", Closeposis);
Step 3: Call the script in your trade logic
To use the CLMM CLOSE position, you can call it with trade logic in Solan. Here is an example:
`Solana-program
Import {SDK} with "Raydium-SDK";
// get the current market manufacturer (cm) and closing price.
Const cm = waiting for sdk.Getmarketmaker ();
Const ClosingPrice = expect sdk.getcloseprice (cm);
// Call the CLMM Close Position to close your position.
Expect clmmClosepetion.closeeposis (ClosingPrice);
Thanks to these steps, you can now use the SDK V2 and Solana programming language in Raydium to add fees for the priority position of CLMM close to the custom trading application.