Solana: Add priority fees to a CLMM close position script

Add priority fees to CLMM to close Solana using Raydium SDK V2

Raydium, the popular decentralized Exchange (Dex) platform, provided SDK V2 for customized trading applications. One of the widespread scenarios in which users may need to introduce priority fees is to complete positions that require liquidity at market prices or higher. This article helps to add a priority fee, the CLMM (closing market maker) closure script, Solana, with the Raydium SDK V2.

Prerequisites

  • Knows Raydium SDK and SOL programming language

  • Basic knowledge of commercial logic and priority fees

Step 1: Create a new script

Create a new file for a customized script, such as clmm_close_position.py. This file logic will be to close positions using Raydium SDK V2.

`Solana program

Import {sdk} from ‘Raydium -SDK’;

/**

* CLMM Final Position Script.

*

* @param {sdk} SDK – Raydium SDK copy.

*/

Export async Function Closeposition (position) {

// Get the current market maker (cm) and the closing price.

Const cm = position.cm;

Const closure process = positer.price;

// Check that CM is enabled.

IF (cm.haspriorityfeesAbled ()) {

// Calculate the transaction fee based on the distribution of market maker/ASK.

CONST FACE = (Closure Rour – CMMBID) / cm.ak * 0.0001; // 100 SOL

// Close the position with Raydium SDK V2.

Wait sdk.closeposition (cm, closure, {

Amount: 1, // Close a position unit

fee,

});

} Else {

// If the priority fee is not enabled, close the position as usual.

Waiting for sdk.closeposition (cm, closure price);

}

}

`

Step 2: Register Scripet with Raydium

To use the script, it must be secured with a Raydium. This includes creating a new “script” instance and customized function.

`Solana program

Import {script} from ‘Raydium -SDK’;

// Create a new script.

CONST CLMMCLOSEPOSITION = New Script ();

// Register the script with the Raydium.

ClmmCloseposition.register (‘Closposition’, Closposition);

`

Step 3: Call the script in the logic of commerce

You can call the CLMM closing script called Trading Logic Solana. Here’s an example:

`Solana program

Import {sdk} from ‘Raydium -SDK’;

// Get the current market maker (cm) and the closing price.

Const cm = wait for sdk.getmarketmaker ();

Const closure = wait for sdk.getcloseprice (cm);

// Call CLMM closing position script to close the position.

CLMMCLOSEPOSITION.CLOSEPOSITION is expected;

`

With these steps, you can now use the Raydium SDK V2 and Solana programming language to give a priority fee to the Clmm closing position in customized trading.

METAMASK CONNECT METAMASK PROVIDER

Artigos relacionados

Deixe o primeiro comentário