-
Notifications
You must be signed in to change notification settings - Fork 145
/
close-position-ix.ts
61 lines (57 loc) · 1.75 KB
/
close-position-ix.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { Instruction } from "@orca-so/common-sdk";
import { PublicKey } from "@solana/web3.js";
import { Program } from "@project-serum/anchor";
import { Whirlpool } from "../artifacts/whirlpool";
/**
* Parameters to close a position in a Whirlpool.
*
* @category Instruction Types
* @param receiver - PublicKey for the wallet that will receive the rented lamports.
* @param position - PublicKey for the position.
* @param positionMint - PublicKey for the mint token for the Position token.
* @param positionTokenAccount - The associated token address for the position token in the owners wallet.
* @param positionAuthority - Authority that owns the position token.
*/
export type ClosePositionParams = {
receiver: PublicKey;
position: PublicKey;
positionMint: PublicKey;
positionTokenAccount: PublicKey;
positionAuthority: PublicKey;
};
/**
* Close a position in a Whirlpool. Burns the position token in the owner's wallet.
*
* @category Instructions
* @param context - Context object containing services required to generate the instruction
* @param params - ClosePositionParams object
* @returns - Instruction to perform the action.
*/
export function closePositionIx(
program: Program<Whirlpool>,
params: ClosePositionParams
): Instruction {
const {
positionAuthority,
receiver: receiver,
position: position,
positionMint: positionMint,
positionTokenAccount,
} = params;
const ix = program.instruction.closePosition({
accounts: {
positionAuthority,
receiver,
position,
positionMint,
positionTokenAccount,
tokenProgram: TOKEN_PROGRAM_ID,
},
});
return {
instructions: [ix],
cleanupInstructions: [],
signers: [],
};
}