From e859a2112bac0cc4e196730f56a6a908e6440ba1 Mon Sep 17 00:00:00 2001 From: FuzzyYeti Date: Fri, 10 Nov 2023 00:10:01 -0700 Subject: [PATCH 1/3] add optional position mint params --- sdk/src/impl/whirlpool-impl.ts | 15 +++++++++------ sdk/src/whirlpool-client.ts | 10 +++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/sdk/src/impl/whirlpool-impl.ts b/sdk/src/impl/whirlpool-impl.ts index 02e449891..a4747685c 100644 --- a/sdk/src/impl/whirlpool-impl.ts +++ b/sdk/src/impl/whirlpool-impl.ts @@ -94,7 +94,8 @@ export class WhirlpoolImpl implements Whirlpool { tickUpper: number, liquidityInput: IncreaseLiquidityInput, wallet?: Address, - funder?: Address + funder?: Address, + positionMint?: Keypair ) { await this.refresh(); return this.getOpenPositionWithOptMetadataTx( @@ -111,8 +112,8 @@ export class WhirlpoolImpl implements Whirlpool { tickUpper: number, liquidityInput: IncreaseLiquidityInput, sourceWallet?: Address, - positionWallet?: Address, - funder?: Address + funder?: Address, + positionMint?: Keypair ) { await this.refresh(); return this.getOpenPositionWithOptMetadataTx( @@ -121,7 +122,8 @@ export class WhirlpoolImpl implements Whirlpool { liquidityInput, !!sourceWallet ? AddressUtil.toPubKey(sourceWallet) : this.ctx.wallet.publicKey, !!funder ? AddressUtil.toPubKey(funder) : this.ctx.wallet.publicKey, - true + true, + positionMint ); } @@ -253,7 +255,8 @@ export class WhirlpoolImpl implements Whirlpool { liquidityInput: IncreaseLiquidityInput, wallet: PublicKey, funder: PublicKey, - withMetadata: boolean = false + withMetadata: boolean = false, + positionMint?: Keypair ): Promise<{ positionMint: PublicKey; tx: TransactionBuilder }> { invariant(TickUtil.checkTickInBounds(tickLower), "tickLower is out of bounds."); invariant(TickUtil.checkTickInBounds(tickUpper), "tickUpper is out of bounds."); @@ -276,7 +279,7 @@ export class WhirlpoolImpl implements Whirlpool { `upper tick ${tickUpper} is not an initializable tick for tick-spacing ${whirlpool.tickSpacing}` ); - const positionMintKeypair = Keypair.generate(); + const positionMintKeypair = positionMint ?? Keypair.generate(); const positionPda = PDAUtil.getPosition( this.ctx.program.programId, positionMintKeypair.publicKey diff --git a/sdk/src/whirlpool-client.ts b/sdk/src/whirlpool-client.ts index 1d5b69716..59fa68dc9 100644 --- a/sdk/src/whirlpool-client.ts +++ b/sdk/src/whirlpool-client.ts @@ -1,6 +1,6 @@ import { Address } from "@coral-xyz/anchor"; import { Percentage, TransactionBuilder } from "@orca-so/common-sdk"; -import { PublicKey } from "@solana/web3.js"; +import {Keypair, PublicKey } from "@solana/web3.js"; import { WhirlpoolContext } from "./context"; import { WhirlpoolClientImpl } from "./impl/whirlpool-client-impl"; import { DevFeeSwapInput, SwapInput } from "./instructions"; @@ -211,6 +211,7 @@ export interface Whirlpool { * @param liquidityInput - an InputLiquidityInput type to define the desired liquidity amount to deposit * @param wallet - the wallet to withdraw tokens to deposit into the position and house the position token. If null, the WhirlpoolContext wallet is used. * @param funder - the wallet that will fund the cost needed to initialize the position. If null, the WhirlpoolContext wallet is used. + * @param positionMint - the mint address of the position token to be created. If null, a new mint address will be created. * @return `positionMint` - the position to be created. `tx` - The transaction containing the instructions to perform the operation on chain. */ openPosition: ( @@ -218,7 +219,8 @@ export interface Whirlpool { tickUpper: number, liquidityInput: IncreaseLiquidityInput, wallet?: Address, - funder?: Address + funder?: Address, + positionMint?: Keypair ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>; /** @@ -233,6 +235,7 @@ export interface Whirlpool { * @param liquidityInput - input that defines the desired liquidity amount and maximum tokens willing to be to deposited. * @param wallet - the wallet to withdraw tokens to deposit into the position and house the position token. If null, the WhirlpoolContext wallet is used. * @param funder - the wallet that will fund the cost needed to initialize the position. If null, the WhirlpoolContext wallet is used. + * @param positionMint - the mint address of the position token to be created. If null, a new mint address will be created. * @return `positionMint` - the position to be created. `tx` - The transaction containing the instructions to perform the operation on chain. */ openPositionWithMetadata: ( @@ -240,7 +243,8 @@ export interface Whirlpool { tickUpper: number, liquidityInput: IncreaseLiquidityInput, wallet?: Address, - funder?: Address + funder?: Address, + positionMint?: Keypair ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>; /** From 15d373d0fc45b6f9ead261e05fff5d44b0df0d2b Mon Sep 17 00:00:00 2001 From: FuzzyYeti Date: Fri, 10 Nov 2023 21:56:23 -0700 Subject: [PATCH 2/3] switch from keypair to pubkey --- sdk/src/impl/whirlpool-impl.ts | 28 +++++++++++++++++----------- sdk/src/whirlpool-client.ts | 4 ++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/sdk/src/impl/whirlpool-impl.ts b/sdk/src/impl/whirlpool-impl.ts index a4747685c..516d62a9a 100644 --- a/sdk/src/impl/whirlpool-impl.ts +++ b/sdk/src/impl/whirlpool-impl.ts @@ -95,7 +95,7 @@ export class WhirlpoolImpl implements Whirlpool { liquidityInput: IncreaseLiquidityInput, wallet?: Address, funder?: Address, - positionMint?: Keypair + positionMint?: PublicKey ) { await this.refresh(); return this.getOpenPositionWithOptMetadataTx( @@ -103,7 +103,9 @@ export class WhirlpoolImpl implements Whirlpool { tickUpper, liquidityInput, !!wallet ? AddressUtil.toPubKey(wallet) : this.ctx.wallet.publicKey, - !!funder ? AddressUtil.toPubKey(funder) : this.ctx.wallet.publicKey + !!funder ? AddressUtil.toPubKey(funder) : this.ctx.wallet.publicKey, + false, + positionMint ); } @@ -113,7 +115,7 @@ export class WhirlpoolImpl implements Whirlpool { liquidityInput: IncreaseLiquidityInput, sourceWallet?: Address, funder?: Address, - positionMint?: Keypair + positionMint?: PublicKey ) { await this.refresh(); return this.getOpenPositionWithOptMetadataTx( @@ -256,7 +258,7 @@ export class WhirlpoolImpl implements Whirlpool { wallet: PublicKey, funder: PublicKey, withMetadata: boolean = false, - positionMint?: Keypair + positionMint?: PublicKey ): Promise<{ positionMint: PublicKey; tx: TransactionBuilder }> { invariant(TickUtil.checkTickInBounds(tickLower), "tickLower is out of bounds."); invariant(TickUtil.checkTickInBounds(tickUpper), "tickUpper is out of bounds."); @@ -279,14 +281,15 @@ export class WhirlpoolImpl implements Whirlpool { `upper tick ${tickUpper} is not an initializable tick for tick-spacing ${whirlpool.tickSpacing}` ); - const positionMintKeypair = positionMint ?? Keypair.generate(); + const positionMintKeypair = Keypair.generate(); + const positionMintPubkey = positionMint ?? positionMintKeypair.publicKey; const positionPda = PDAUtil.getPosition( this.ctx.program.programId, - positionMintKeypair.publicKey + positionMintPubkey ); - const metadataPda = PDAUtil.getPositionMetadata(positionMintKeypair.publicKey); + const metadataPda = PDAUtil.getPositionMetadata(positionMintPubkey); const positionTokenAccountAddress = getAssociatedTokenAddressSync( - positionMintKeypair.publicKey, + positionMintPubkey, wallet, this.ctx.accountResolverOpts.allowPDAOwnerAddress ); @@ -304,14 +307,17 @@ export class WhirlpoolImpl implements Whirlpool { owner: wallet, positionPda, metadataPda, - positionMintAddress: positionMintKeypair.publicKey, + positionMintAddress: positionMintPubkey, positionTokenAccount: positionTokenAccountAddress, whirlpool: this.address, tickLowerIndex: tickLower, tickUpperIndex: tickUpper, } ); - txBuilder.addInstruction(positionIx).addSigner(positionMintKeypair); + txBuilder.addInstruction(positionIx); + if(positionMint === undefined) { + txBuilder.addSigner(positionMintKeypair); + } const [ataA, ataB] = await resolveOrCreateATAs( this.ctx.connection, @@ -363,7 +369,7 @@ export class WhirlpoolImpl implements Whirlpool { txBuilder.addInstruction(liquidityIx); return { - positionMint: positionMintKeypair.publicKey, + positionMint: positionMintPubkey, tx: txBuilder, }; } diff --git a/sdk/src/whirlpool-client.ts b/sdk/src/whirlpool-client.ts index 59fa68dc9..3d81efa03 100644 --- a/sdk/src/whirlpool-client.ts +++ b/sdk/src/whirlpool-client.ts @@ -220,7 +220,7 @@ export interface Whirlpool { liquidityInput: IncreaseLiquidityInput, wallet?: Address, funder?: Address, - positionMint?: Keypair + positionMint?: PublicKey ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>; /** @@ -244,7 +244,7 @@ export interface Whirlpool { liquidityInput: IncreaseLiquidityInput, wallet?: Address, funder?: Address, - positionMint?: Keypair + positionMint?: PublicKey ) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>; /** From d6f22e550916e06e2b7978378516ab16e51a28ee Mon Sep 17 00:00:00 2001 From: FuzzyYeti Date: Sun, 12 Nov 2023 20:29:29 -0700 Subject: [PATCH 3/3] PR fixes --- sdk/src/impl/whirlpool-impl.ts | 2 +- sdk/src/whirlpool-client.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/src/impl/whirlpool-impl.ts b/sdk/src/impl/whirlpool-impl.ts index 516d62a9a..55374a856 100644 --- a/sdk/src/impl/whirlpool-impl.ts +++ b/sdk/src/impl/whirlpool-impl.ts @@ -281,7 +281,7 @@ export class WhirlpoolImpl implements Whirlpool { `upper tick ${tickUpper} is not an initializable tick for tick-spacing ${whirlpool.tickSpacing}` ); - const positionMintKeypair = Keypair.generate(); + const positionMintKeypair = Keypair.generate(); const positionMintPubkey = positionMint ?? positionMintKeypair.publicKey; const positionPda = PDAUtil.getPosition( this.ctx.program.programId, diff --git a/sdk/src/whirlpool-client.ts b/sdk/src/whirlpool-client.ts index 3d81efa03..d24b11a4c 100644 --- a/sdk/src/whirlpool-client.ts +++ b/sdk/src/whirlpool-client.ts @@ -1,6 +1,6 @@ import { Address } from "@coral-xyz/anchor"; import { Percentage, TransactionBuilder } from "@orca-so/common-sdk"; -import {Keypair, PublicKey } from "@solana/web3.js"; +import { PublicKey } from "@solana/web3.js"; import { WhirlpoolContext } from "./context"; import { WhirlpoolClientImpl } from "./impl/whirlpool-client-impl"; import { DevFeeSwapInput, SwapInput } from "./instructions";