Adding priority rates to a clmm closure position in Solana using Raydium’s SDK V2
Raydium, a popular decentralized switching platform (DEX), provided its SDK V2 for the development of personalized trading applications. A common scenario where users may need to implement priority rates is when closing positions that require liquidity or above market price. This article will guide it by adding priority rates to a CLMM (Feching Market Maker) closure position in Solana using Raydium’s SDK V2.
Prerequisites
- Familiarity with Raydium’s SDK and Sol Programming Language
- Basic understanding of negotiation logic and priority rates
Step 1: Create a new script
Create a new file for your custom script, for example, clmm_close_position.py
. This file will contain the logic to close positions using Raydium’s SDK V2.
`Solana Program
import {sdk} of ‘raydium-sdk’;
/**
* Clmm closing position script.
*
* @param {sdk} sdk – raydium sdk instance.
*/
Export Closeposition of the asynchronous function (position) {
// Get the current market manufacturer (cm) and the closing price.
Consta cm = position.cm;
Consta ClosingPrice = pusion.price;
// Make sure the CM has activated priority rates.
if (cm.hasprionityfeesenabled ()) {
// Calculate the rate for the transaction based on the market manufacturer’s offer/question.
CONST TAW = (CLSINGPRICE – CM.BID) / CM.ASK * 0.0001; // 100 sun
// Close the position using Raydium’s SDK V2.
awaits sdk.closeposição (cm, closingprice, {
Value: 1, // Close a unit of the position
rate,
});
} other {
// If the priority rates are not activated, close the position as usual.
awaits sdk.closeposição (cm, closurePrice);
}
}
`
Step 2: Record the script with Raydium
To use the script, you need to register it on Raydium. This involves creating a new instance script 'and record of its personalized function.
Solana Program
import {script} of ‘raydium-sdk’;
// Create a new instance of script.
Constant ClmMCLOSEPOSITION = new script ();
// Register the script with Raydium.
ClmMClosEposition.register (‘Closeposição’, Closeposição);
`
Step 3: Call the script in its commercial logic
To use the Clmm closed position script, you can call it from your commercial logic in Solana. Here is an example:
`Solana Program
import {sdk} of ‘raydium-sdk’;
// Get the current market manufacturer (cm) and the closing price.
CONST CM = Wait SDK.getMarketmaker ();
CONST CLOSINGPRICE = Wait SDK.GETCLOSEPRICE (CM);
// Call the Clmm closing position script to close the position.
awaits clmmcloseposição.closeposição (closingprice);
`
With these steps, you can now use Raydium’s SDK V2 and Solana programming language to add priority rates to a CLMM closure position to your custom trading app.