11import {
2+ fetchMaybeLockConfig ,
23 fetchPosition ,
34 getPositionAddress ,
45 getTransferLockedPositionInstruction ,
6+ WHIRLPOOL_PROGRAM_ADDRESS ,
57} from "@orca-so/whirlpools-client" ;
68import {
79 fetchMaybeMint ,
810 TOKEN_2022_PROGRAM_ADDRESS ,
911} from "@solana-program/token-2022" ;
10- import type {
11- Address ,
12- GetMultipleAccountsApi ,
13- GetAccountInfoApi ,
14- IInstruction ,
15- Rpc ,
16- GetMinimumBalanceForRentExemptionApi ,
17- GetEpochInfoApi ,
18- TransactionSigner ,
12+ import {
13+ type Address ,
14+ type GetAccountInfoApi ,
15+ type IInstruction ,
16+ type Rpc ,
17+ type TransactionSigner ,
18+ getProgramDerivedAddress ,
19+ getAddressCodec ,
1920} from "@solana/kit" ;
2021import { FUNDER } from "./config" ;
2122import { wrapFunctionWithExecution } from "./actionHelpers" ;
2223import assert from "assert" ;
2324import { findAssociatedTokenPda } from "@solana-program/token" ;
2425
25- /**
26- * Parameters for transferring a locked position.
27- */
28- export type TransferLockedPositionParam = {
29- /** The address of the position mint. */
30- positionMintAddress : Address ;
31-
32- /** The address of the destination token account. */
33- detinationTokenAccount : Address ;
34-
35- /** The address of the lock config. */
36- lockConfig : Address ;
37-
38- /** The address of the receiver. */
39- receiver : Address ;
40- } ;
41-
4226/**
4327 * Instructions for transferring a locked position.
4428 */
@@ -63,56 +47,62 @@ export type TransferLockedPositionInstructions = {
6347 * await setWhirlpoolsConfig('solanaDevnet');
6448 * const wallet = await loadWallet();
6549 * const positionMint = address("HqoV7Qv27REUtmd9UKSJGGmCRNx3531t33bDG1BUfo9K");
66- * const param = {
67- * position: positionMint,
68- * positionMint: positionMint,
69- * positionTokenAccount: positionMint,
70- * detinationTokenAccount: positionMint,
71- * lockConfig: positionMint,
72- * positionAuthority: positionMint,
73- * receiver: positionMint,
74- * };
50+ *
7551 * const { instructions } = await transferLockedPositionInstructions(
7652 * devnetRpc,
77- * param,
53+ * positionMint,
54+ * receiverAddress,
7855 * wallet
7956 * );
8057 *
8158 * console.log(`Instructions: ${instructions}`);
8259 */
8360export async function transferLockedPositionInstructions (
84- rpc : Rpc <
85- GetAccountInfoApi &
86- GetMultipleAccountsApi &
87- GetMinimumBalanceForRentExemptionApi &
88- GetEpochInfoApi
89- > ,
90- param : TransferLockedPositionParam ,
61+ rpc : Rpc < GetAccountInfoApi > ,
62+ positionMintAddress : Address ,
63+ receiver : Address ,
9164 authority : TransactionSigner = FUNDER ,
9265) : Promise < TransferLockedPositionInstructions > {
9366 const instructions : IInstruction [ ] = [ ] ;
9467
95- const positionAddress = await getPositionAddress ( param . positionMintAddress ) ;
68+ const positionAddress = await getPositionAddress ( positionMintAddress ) ;
9669 const position = await fetchPosition ( rpc , positionAddress [ 0 ] ) ;
9770 const positionMint = await fetchMaybeMint ( rpc , position . data . positionMint ) ;
9871
9972 assert ( positionMint . exists , "Position mint not found" ) ;
10073
10174 const positionMintTokenAccount = await findAssociatedTokenPda ( {
10275 owner : authority . address ,
103- mint : param . positionMintAddress ,
76+ mint : positionMintAddress ,
77+ tokenProgram : positionMint . programAddress ,
78+ } ) ;
79+
80+ const destinationTokenAccount = await findAssociatedTokenPda ( {
81+ owner : receiver ,
82+ mint : positionMintAddress ,
10483 tokenProgram : positionMint . programAddress ,
10584 } ) ;
10685
86+ const lockConfigPda = await getProgramDerivedAddress ( {
87+ seeds : [
88+ Buffer . from ( "lock_config" ) ,
89+ getAddressCodec ( ) . encode ( positionAddress [ 0 ] ) ,
90+ ] ,
91+ programAddress : WHIRLPOOL_PROGRAM_ADDRESS ,
92+ } ) ;
93+
94+ const lockConfig = await fetchMaybeLockConfig ( rpc , lockConfigPda [ 0 ] ) ;
95+ assert ( lockConfig . exists , "Lock config not found" ) ;
96+
10797 instructions . push (
10898 getTransferLockedPositionInstruction ( {
10999 positionAuthority : authority ,
110- receiver : param . receiver ,
100+ receiver : receiver ,
111101 position : position . address ,
112102 positionTokenAccount : positionMintTokenAccount [ 0 ] ,
113- positionMint : param . positionMintAddress ,
114- destinationTokenAccount : param . detinationTokenAccount ,
115- lockConfig : param . lockConfig ,
103+ positionMint : positionMintAddress ,
104+ destinationTokenAccount : destinationTokenAccount [ 0 ] ,
105+ lockConfig : lockConfig . address ,
116106 token2022Program : TOKEN_2022_PROGRAM_ADDRESS ,
117107 } ) ,
118108 ) ;
0 commit comments