add optional position mint params (#121)
* add optional position mint params * switch from keypair to pubkey * PR fixes
This commit is contained in:
parent
728586cc70
commit
2dfb9f7ecf
|
@ -94,7 +94,8 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
tickUpper: number,
|
||||
liquidityInput: IncreaseLiquidityInput,
|
||||
wallet?: Address,
|
||||
funder?: Address
|
||||
funder?: Address,
|
||||
positionMint?: PublicKey
|
||||
) {
|
||||
await this.refresh();
|
||||
return this.getOpenPositionWithOptMetadataTx(
|
||||
|
@ -102,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
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -111,8 +114,8 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
tickUpper: number,
|
||||
liquidityInput: IncreaseLiquidityInput,
|
||||
sourceWallet?: Address,
|
||||
positionWallet?: Address,
|
||||
funder?: Address
|
||||
funder?: Address,
|
||||
positionMint?: PublicKey
|
||||
) {
|
||||
await this.refresh();
|
||||
return this.getOpenPositionWithOptMetadataTx(
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -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,
|
||||
|
@ -360,7 +369,7 @@ export class WhirlpoolImpl implements Whirlpool {
|
|||
txBuilder.addInstruction(liquidityIx);
|
||||
|
||||
return {
|
||||
positionMint: positionMintKeypair.publicKey,
|
||||
positionMint: positionMintPubkey,
|
||||
tx: txBuilder,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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?: PublicKey
|
||||
) => 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?: PublicKey
|
||||
) => Promise<{ positionMint: PublicKey; tx: TransactionBuilder }>;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue