Skip to content

Commit 4a35de0

Browse files
committed
Implements instruction for transffering locked position in kit-sdk
1 parent 5ba1a95 commit 4a35de0

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

.changeset/slimy-ears-type.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { getTransferLockedPositionInstruction } from "@orca-so/whirlpools-client";
2+
import { TOKEN_2022_PROGRAM_ADDRESS } from "@solana-program/token-2022";
3+
import type {
4+
Address,
5+
GetMultipleAccountsApi,
6+
GetAccountInfoApi,
7+
IInstruction,
8+
Rpc,
9+
GetMinimumBalanceForRentExemptionApi,
10+
GetEpochInfoApi,
11+
TransactionSigner,
12+
} from "@solana/kit";
13+
import { FUNDER } from "./config";
14+
15+
/**
16+
* Parameters for transferring a locked position.
17+
*/
18+
export type TransferLockedPositionParam = {
19+
position: Address;
20+
positionMint: Address;
21+
positionTokenAccount: Address;
22+
detinationTokenAccount: Address;
23+
lockConfig: Address;
24+
positionAuthority: Address;
25+
receiver: Address;
26+
};
27+
28+
/**
29+
* Instructions for transferring a locked position.
30+
*/
31+
export type TransferLockedPositionInstructions = {
32+
instructions: IInstruction[];
33+
};
34+
35+
/**
36+
* Generates instructions to transfer a locked position.
37+
*
38+
* @param {SolanaRpc} rpc - The Solana RPC client.
39+
* @param {TransferLockedPositionParam} param - The parameters for transferring a locked position.
40+
* @param {TransactionSigner} [authority=FUNDER] - The authority for the transfer.
41+
* @returns {Promise<TransferLockedPositionInstructions>} - A promise that resolves to an object containing instructions.
42+
*
43+
* @example
44+
* import { transferLockedPositionInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
45+
* import { createSolanaRpc, devnet, address } from '@solana/kit';
46+
* import { loadWallet } from './utils';
47+
*
48+
* await setWhirlpoolsConfig('solanaDevnet');
49+
* const wallet = await loadWallet();
50+
* const positionMint = address("HqoV7Qv27REUtmd9UKSJGGmCRNx3531t33bDG1BUfo9K");
51+
* const param = {
52+
* position: positionMint,
53+
* positionMint: positionMint,
54+
* positionTokenAccount: positionMint,
55+
* detinationTokenAccount: positionMint,
56+
* lockConfig: positionMint,
57+
* positionAuthority: positionMint,
58+
* receiver: positionMint,
59+
* };
60+
* const { instructions } = await transferLockedPositionInstructions(
61+
* devnetRpc,
62+
* param,
63+
* wallet
64+
* );
65+
*
66+
* console.log(`Instructions: ${instructions}`);
67+
*/
68+
export async function transferLockedPositionInstructions(
69+
rpc: Rpc<
70+
GetAccountInfoApi &
71+
GetMultipleAccountsApi &
72+
GetMinimumBalanceForRentExemptionApi &
73+
GetEpochInfoApi
74+
>,
75+
param: TransferLockedPositionParam,
76+
authority: TransactionSigner = FUNDER,
77+
): Promise<TransferLockedPositionInstructions> {
78+
const instructions: IInstruction[] = [];
79+
80+
instructions.push(
81+
getTransferLockedPositionInstruction({
82+
positionAuthority: authority,
83+
receiver: param.receiver,
84+
position: param.position,
85+
positionTokenAccount: param.positionTokenAccount,
86+
positionMint: param.positionMint,
87+
destinationTokenAccount: param.detinationTokenAccount,
88+
lockConfig: param.lockConfig,
89+
token2022Program: TOKEN_2022_PROGRAM_ADDRESS,
90+
}),
91+
);
92+
93+
return {
94+
instructions,
95+
};
96+
}

0 commit comments

Comments
 (0)