-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue on conversion between camel and snake (pos_2022 >> pos2022 >> pos2022) and generate wrong instruction disc code (instruction not found)
- Loading branch information
1 parent
1b8d35c
commit 1f803ec
Showing
12 changed files
with
939 additions
and
83 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
legacy-sdk/whirlpool/src/instructions/close-position-with-token-extensions-ix.ts
This file contains 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,62 @@ | ||
import type { Program } from "@coral-xyz/anchor"; | ||
import type { Instruction } from "@orca-so/common-sdk"; | ||
import { TOKEN_2022_PROGRAM_ID } from "@solana/spl-token"; | ||
import type { PublicKey } from "@solana/web3.js"; | ||
import type { Whirlpool } from "../artifacts/whirlpool"; | ||
|
||
/** | ||
* Parameters to close a position (based on Token-2022) 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 ClosePositionWithTokenExtensionsParams = { | ||
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. | ||
* Mint and TokenAccount are based on Token-2022. And Mint accout will be also closed. | ||
* | ||
* @category Instructions | ||
* @param context - Context object containing services required to generate the instruction | ||
* @param params - ClosePositionWithTokenExtensionsParams object | ||
* @returns - Instruction to perform the action. | ||
*/ | ||
export function closePositionWithTokenExtensionsIx( | ||
program: Program<Whirlpool>, | ||
params: ClosePositionWithTokenExtensionsParams, | ||
): Instruction { | ||
const { | ||
positionAuthority, | ||
receiver: receiver, | ||
position: position, | ||
positionMint, | ||
positionTokenAccount, | ||
} = params; | ||
|
||
const ix = program.instruction.closePositionWithTokenExtensions({ | ||
accounts: { | ||
positionAuthority, | ||
receiver, | ||
position, | ||
positionMint, | ||
positionTokenAccount, | ||
token2022Program: TOKEN_2022_PROGRAM_ID, | ||
}, | ||
}); | ||
|
||
return { | ||
instructions: [ix], | ||
cleanupInstructions: [], | ||
signers: [], | ||
}; | ||
} |
This file contains 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
72 changes: 72 additions & 0 deletions
72
legacy-sdk/whirlpool/src/instructions/open-position-with-token-extensions-ix.ts
This file contains 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,72 @@ | ||
import type { Program } from "@coral-xyz/anchor"; | ||
import type { Instruction, PDA } from "@orca-so/common-sdk"; | ||
import type { PublicKey } from "@solana/web3.js"; | ||
import { WHIRLPOOL_NFT_UPDATE_AUTH } from ".."; | ||
import type { Whirlpool } from "../artifacts/whirlpool"; | ||
import { openPositionWithTokenExtensionsAccounts } from "../utils/instructions-util"; | ||
|
||
/** | ||
* Parameters to open a position (based on Token-2022) in a Whirlpool. | ||
* | ||
* @category Instruction Types | ||
* @param whirlpool - PublicKey for the whirlpool that the position will be opened for. | ||
* @param ownerKey - PublicKey for the wallet that will host the minted position token. | ||
* @param positionPda - PDA for the derived position address. | ||
* @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 funder - The account that would fund the creation of this account | ||
* @param tickLowerIndex - The tick specifying the lower end of the position range. | ||
* @param tickUpperIndex - The tick specifying the upper end of the position range. | ||
* @param withTokenMetadataExtension - If true, the position token will have a TokenMetadata extension. | ||
*/ | ||
export type OpenPositionWithTokenExtensionsParams = { | ||
whirlpool: PublicKey; | ||
owner: PublicKey; | ||
positionPda: PDA; | ||
positionMint: PublicKey; | ||
positionTokenAccount: PublicKey; | ||
funder: PublicKey; | ||
tickLowerIndex: number; | ||
tickUpperIndex: number; | ||
withTokenMetadataExtension: boolean; | ||
}; | ||
|
||
/** | ||
* Open a position in a Whirlpool. A unique token will be minted to represent the position | ||
* in the users wallet. Additional TokenMetadata extension is initialized to identify the token if requested. | ||
* Mint and Token account are based on Token-2022. | ||
* The position will start off with 0 liquidity. | ||
* | ||
* #### Special Errors | ||
* `InvalidTickIndex` - If a provided tick is out of bounds, out of order or not a multiple of the tick-spacing in this pool. | ||
* | ||
* @category Instructions | ||
* @param context - Context object containing services required to generate the instruction | ||
* @param params - OpenPositionWithTokenExtensionsParams object and a derived PDA that hosts the position's metadata. | ||
* @returns - Instruction to perform the action. | ||
*/ | ||
export function openPositionWithTokenExtensionsIx( | ||
program: Program<Whirlpool>, | ||
params: OpenPositionWithTokenExtensionsParams, | ||
): Instruction { | ||
const { tickLowerIndex, tickUpperIndex, withTokenMetadataExtension } = params; | ||
|
||
const ix = program.instruction.openPositionWithTokenExtensions( | ||
tickLowerIndex, | ||
tickUpperIndex, | ||
withTokenMetadataExtension, | ||
{ | ||
accounts: { | ||
...openPositionWithTokenExtensionsAccounts(params), | ||
metadataUpdateAuth: WHIRLPOOL_NFT_UPDATE_AUTH, | ||
}, | ||
}, | ||
); | ||
|
||
// TODO: Require Keypair and auto sign this ix | ||
return { | ||
instructions: [ix], | ||
cleanupInstructions: [], | ||
signers: [], | ||
}; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.