Skip to content
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

add optional position mint params #121

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions sdk/src/impl/whirlpool-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,18 @@ export class WhirlpoolImpl implements Whirlpool {
tickUpper: number,
liquidityInput: IncreaseLiquidityInput,
wallet?: Address,
funder?: Address
funder?: Address,
positionMint?: PublicKey
) {
await this.refresh();
return this.getOpenPositionWithOptMetadataTx(
tickLower,
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
);
}

Expand All @@ -111,8 +114,8 @@ export class WhirlpoolImpl implements Whirlpool {
tickUpper: number,
liquidityInput: IncreaseLiquidityInput,
sourceWallet?: Address,
positionWallet?: Address,
yugure-orca marked this conversation as resolved.
Show resolved Hide resolved
funder?: Address
funder?: Address,
positionMint?: PublicKey
) {
await this.refresh();
return this.getOpenPositionWithOptMetadataTx(
Expand All @@ -121,7 +124,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
);
}

Expand Down Expand Up @@ -253,7 +257,8 @@ export class WhirlpoolImpl implements Whirlpool {
liquidityInput: IncreaseLiquidityInput,
wallet: PublicKey,
funder: PublicKey,
withMetadata: boolean = false
withMetadata: boolean = false,
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.");
Expand All @@ -277,13 +282,14 @@ export class WhirlpoolImpl implements Whirlpool {
);

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
);
Expand All @@ -301,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,
Expand Down Expand Up @@ -360,7 +369,7 @@ export class WhirlpoolImpl implements Whirlpool {
txBuilder.addInstruction(liquidityIx);

return {
positionMint: positionMintKeypair.publicKey,
positionMint: positionMintPubkey,
tx: txBuilder,
};
}
Expand Down
8 changes: 6 additions & 2 deletions sdk/src/whirlpool-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,16 @@ 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: (
tickLower: number,
tickUpper: number,
liquidityInput: IncreaseLiquidityInput,
wallet?: Address,
funder?: Address
funder?: Address,
positionMint?: PublicKey
) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>;

/**
Expand All @@ -233,14 +235,16 @@ 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: (
tickLower: number,
tickUpper: number,
liquidityInput: IncreaseLiquidityInput,
wallet?: Address,
funder?: Address
funder?: Address,
positionMint?: PublicKey
) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>;

/**
Expand Down