-
Notifications
You must be signed in to change notification settings - Fork 293
Implements transfer_locked_position instruction in ts-sdk #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
boosik-sol
wants to merge
15
commits into
main
Choose a base branch
from
boosik/impl_transfer_locked_position_ts_sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7dc88e1
Implements instruction for transffering locked position in kit-sdk
boosik-sol 8cdccc7
Add unit test for transfer_locked_position instruction in ts-sdk
boosik-sol 8833adb
Add comments to each parameter in TransferLockedPositionParams
boosik-sol 82718eb
Implements lockPosition test code
boosik-sol 87a4560
fix: lint
boosik-sol e44b072
fix: rollback mint-authority in test case
boosik-sol 733e095
fix: getting address in setupAta owner
boosik-sol ac692b3
fix: lint
boosik-sol b7c3aac
fix: derive addresses from position
boosik-sol 6019170
fix: add comments
boosik-sol 0c5d73e
feat: add testcase that should fail when not TE
boosik-sol dcb7c4d
feat: test case that failed when signer and owner is different
boosik-sol 9f09682
feat: add more tc
boosik-sol 1266a6d
fix: format
boosik-sol c59ceda
tc: add verification that failed to send locked position to myself
boosik-sol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@orca-so/whirlpools": patch | ||
| --- | ||
|
|
||
| Implements transfer_locked_position_instruction in ts-sdk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { | ||
| fetchMaybeLockConfig, | ||
| fetchPosition, | ||
| getPositionAddress, | ||
| getTransferLockedPositionInstruction, | ||
| WHIRLPOOL_PROGRAM_ADDRESS, | ||
| } from "@orca-so/whirlpools-client"; | ||
| import { | ||
| fetchMaybeMint, | ||
| TOKEN_2022_PROGRAM_ADDRESS, | ||
| } from "@solana-program/token-2022"; | ||
| import { | ||
| type Address, | ||
| type GetAccountInfoApi, | ||
| type IInstruction, | ||
| type Rpc, | ||
| type TransactionSigner, | ||
| getProgramDerivedAddress, | ||
| getAddressCodec, | ||
| } from "@solana/kit"; | ||
| import { FUNDER } from "./config"; | ||
| import { wrapFunctionWithExecution } from "./actionHelpers"; | ||
| import assert from "assert"; | ||
| import { findAssociatedTokenPda } from "@solana-program/token"; | ||
|
|
||
| /** | ||
| * Instructions for transferring a locked position. | ||
| */ | ||
| export type TransferLockedPositionInstructions = { | ||
| /** The instructions for transferring a locked position. */ | ||
| instructions: IInstruction[]; | ||
| }; | ||
|
|
||
| /** | ||
| * Generates instructions to transfer a locked position. | ||
| * | ||
| * @param {SolanaRpc} rpc - The Solana RPC client. | ||
| * @param {Address} positionMintAddress - The address of the position mint. | ||
| * @param {Address} receiver - The address of the receiver. | ||
| * @param {TransactionSigner} [authority=FUNDER] - The authority for the transfer. | ||
| * @returns {Promise<TransferLockedPositionInstructions>} - A promise that resolves to an object containing instructions. | ||
| * | ||
| * @example | ||
| * import { transferLockedPositionInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools'; | ||
| * import { createSolanaRpc, devnet, address } from '@solana/kit'; | ||
| * import { loadWallet } from './utils'; | ||
| * | ||
| * await setWhirlpoolsConfig('solanaDevnet'); | ||
| * const wallet = await loadWallet(); | ||
| * const positionMint = address("HqoV7Qv27REUtmd9UKSJGGmCRNx3531t33bDG1BUfo9K"); | ||
| * | ||
| * const { instructions } = await transferLockedPositionInstructions( | ||
| * devnetRpc, | ||
| * positionMint, | ||
| * receiverAddress, | ||
| * wallet | ||
| * ); | ||
| * | ||
| * console.log(`Instructions: ${instructions}`); | ||
| */ | ||
| export async function transferLockedPositionInstructions( | ||
| rpc: Rpc<GetAccountInfoApi>, | ||
| positionMintAddress: Address, | ||
| receiver: Address, | ||
| authority: TransactionSigner = FUNDER, | ||
| ): Promise<TransferLockedPositionInstructions> { | ||
| const instructions: IInstruction[] = []; | ||
|
|
||
| const positionAddress = await getPositionAddress(positionMintAddress); | ||
| const position = await fetchPosition(rpc, positionAddress[0]); | ||
| const positionMint = await fetchMaybeMint(rpc, position.data.positionMint); | ||
|
|
||
| assert(positionMint.exists, "Position mint not found"); | ||
|
|
||
| const positionMintTokenAccount = await findAssociatedTokenPda({ | ||
| owner: authority.address, | ||
| mint: positionMintAddress, | ||
| tokenProgram: positionMint.programAddress, | ||
| }); | ||
|
|
||
| const destinationTokenAccount = await findAssociatedTokenPda({ | ||
| owner: receiver, | ||
| mint: positionMintAddress, | ||
| tokenProgram: positionMint.programAddress, | ||
| }); | ||
|
|
||
| const lockConfigPda = await getProgramDerivedAddress({ | ||
| seeds: [ | ||
| Buffer.from("lock_config"), | ||
| getAddressCodec().encode(positionAddress[0]), | ||
| ], | ||
| programAddress: WHIRLPOOL_PROGRAM_ADDRESS, | ||
| }); | ||
|
|
||
| const lockConfig = await fetchMaybeLockConfig(rpc, lockConfigPda[0]); | ||
| assert(lockConfig.exists, "Lock config not found"); | ||
|
|
||
| instructions.push( | ||
| getTransferLockedPositionInstruction({ | ||
| positionAuthority: authority, | ||
| receiver: receiver, | ||
| position: position.address, | ||
| positionTokenAccount: positionMintTokenAccount[0], | ||
| positionMint: positionMintAddress, | ||
| destinationTokenAccount: destinationTokenAccount[0], | ||
| lockConfig: lockConfig.address, | ||
| token2022Program: TOKEN_2022_PROGRAM_ADDRESS, | ||
| }), | ||
| ); | ||
|
|
||
| return { | ||
| instructions, | ||
| }; | ||
| } | ||
|
|
||
| // -------- ACTIONS -------- | ||
|
|
||
| export const transferLockedPosition = wrapFunctionWithExecution( | ||
| transferLockedPositionInstructions, | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wjthieme Could we use this with @orca-so/whirlpool-client? I think it is not exported. Or, I will move this to
utils.tswhen I fixlockPosition.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if the function is not yet in
@orca-so/whirlpool-client(or not exported) feel free to add/change it there!