|
| 1 | +import type { Program } from "@coral-xyz/anchor"; |
| 2 | +import type { Instruction, PDA } from "@orca-so/common-sdk"; |
| 3 | +import type { PublicKey } from "@solana/web3.js"; |
| 4 | +import type { LockTypeData } from ".."; |
| 5 | +import type { Whirlpool } from "../artifacts/whirlpool"; |
| 6 | +import { TOKEN_2022_PROGRAM_ID } from "@solana/spl-token"; |
| 7 | +import { SystemProgram } from "@solana/web3.js"; |
| 8 | + |
| 9 | +/** |
| 10 | + * Parameters to lock a position (TokenExtensions based position only). |
| 11 | + * |
| 12 | + * @category Instruction Types |
| 13 | + * @param lockType - The type of lock to apply to the position. |
| 14 | + * @param funder - The account that would fund the creation of LockConfig account |
| 15 | + * @param positionAuthority - authority that owns the token corresponding to this desired position. |
| 16 | + * @param position - PublicKey for the position which will be locked. |
| 17 | + * @param positionMint - PublicKey for the mint token for the Position token. |
| 18 | + * @param positionTokenAccount - The associated token address for the position token in the owners wallet. |
| 19 | + * @param lockConfigPda - PDA for the LockConfig account that will be created to manage lock state. |
| 20 | + * @param whirlpool - PublicKey for the whirlpool that the position belongs to. |
| 21 | + */ |
| 22 | +export type LockPositionParams = { |
| 23 | + lockType: LockTypeData; |
| 24 | + funder: PublicKey; |
| 25 | + positionAuthority: PublicKey; |
| 26 | + position: PublicKey; |
| 27 | + positionMint: PublicKey; |
| 28 | + positionTokenAccount: PublicKey; |
| 29 | + lockConfigPda: PDA; |
| 30 | + whirlpool: PublicKey; |
| 31 | +}; |
| 32 | + |
| 33 | +/** |
| 34 | + * Lock the position to prevent any liquidity changes. |
| 35 | + * |
| 36 | + * #### Special Errors |
| 37 | + * `PositionAlreadyLocked` - The provided position is already locked. |
| 38 | + * `PositionNotLockable` - The provided position is not lockable (e.g. An empty position). |
| 39 | + * |
| 40 | + * @category Instructions |
| 41 | + * @param program - program object containing services required to generate the instruction |
| 42 | + * @param params - LockPositionParams object. |
| 43 | + * @returns - Instruction to perform the action. |
| 44 | + */ |
| 45 | +export function lockPositionIx( |
| 46 | + program: Program<Whirlpool>, |
| 47 | + params: LockPositionParams, |
| 48 | +): Instruction { |
| 49 | + const ix = program.instruction.lockPosition(params.lockType, { |
| 50 | + accounts: { |
| 51 | + funder: params.funder, |
| 52 | + positionAuthority: params.positionAuthority, |
| 53 | + position: params.position, |
| 54 | + positionMint: params.positionMint, |
| 55 | + positionTokenAccount: params.positionTokenAccount, |
| 56 | + lockConfig: params.lockConfigPda.publicKey, |
| 57 | + whirlpool: params.whirlpool, |
| 58 | + token2022Program: TOKEN_2022_PROGRAM_ID, |
| 59 | + systemProgram: SystemProgram.programId, |
| 60 | + }, |
| 61 | + }); |
| 62 | + |
| 63 | + return { |
| 64 | + instructions: [ix], |
| 65 | + cleanupInstructions: [], |
| 66 | + signers: [], |
| 67 | + }; |
| 68 | +} |
0 commit comments