mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-31 15:11:24 +00:00
chore: lint
This commit is contained in:
@@ -16,7 +16,7 @@ export * from "./get_token_data";
|
||||
export * from "./stake_with_jup";
|
||||
export * from "./fetch_price";
|
||||
export * from "./send_compressed_airdrop";
|
||||
export * from "./orca_close_position"
|
||||
export * from "./orca_close_position";
|
||||
export * from "./orca_create_clmm";
|
||||
export * from "./orca_create_single_sided_liquidity_pool";
|
||||
export * from "./orca_fetch_positions";
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
TransactionMessage,
|
||||
VersionedTransaction
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "@coral-xyz/anchor";
|
||||
@@ -32,7 +32,7 @@ import { Percentage } from "@orca-so/common-sdk";
|
||||
* - The function uses Orca’s SDK to interact with the specified Whirlpool and close the liquidity position.
|
||||
* - A maximum slippage of 1% is assumed for liquidity provision during the position closing.
|
||||
* - The function automatically fetches the associated Whirlpool address and position details using the provided mint address.
|
||||
*
|
||||
*
|
||||
* ## Throws
|
||||
* An error will be thrown if:
|
||||
* - The specified position mint address is invalid or inaccessible.
|
||||
@@ -54,25 +54,29 @@ export async function orcaClosePosition(
|
||||
wallet,
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
);
|
||||
const client = buildWhirlpoolClient(ctx)
|
||||
const client = buildWhirlpoolClient(ctx);
|
||||
|
||||
const positionAddress = PDAUtil.getPosition(ORCA_WHIRLPOOL_PROGRAM_ID, positionMintAddress);
|
||||
const positionAddress = PDAUtil.getPosition(
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
positionMintAddress,
|
||||
);
|
||||
const position = await client.getPosition(positionAddress.publicKey);
|
||||
const whirlpoolAddress = position.getData().whirlpool;
|
||||
const whirlpool = await client.getPool(whirlpoolAddress);
|
||||
const txBuilder = await whirlpool.closePosition(positionAddress.publicKey, Percentage.fromFraction(1, 100));
|
||||
const txBuilder = await whirlpool.closePosition(
|
||||
positionAddress.publicKey,
|
||||
Percentage.fromFraction(1, 100),
|
||||
);
|
||||
const txPayload = await txBuilder[0].build();
|
||||
const txPayloadDecompiled = TransactionMessage.decompile((txPayload.transaction as VersionedTransaction).message);
|
||||
const txPayloadDecompiled = TransactionMessage.decompile(
|
||||
(txPayload.transaction as VersionedTransaction).message,
|
||||
);
|
||||
const instructions = txPayloadDecompiled.instructions;
|
||||
const signers = txPayload.signers as Keypair[];
|
||||
|
||||
const txId = await sendTx(
|
||||
agent,
|
||||
instructions,
|
||||
signers
|
||||
);
|
||||
return txId
|
||||
const txId = await sendTx(agent, instructions, signers);
|
||||
return txId;
|
||||
} catch (error) {
|
||||
throw new Error(`${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
TransactionMessage,
|
||||
VersionedTransaction
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "@coral-xyz/anchor";
|
||||
@@ -45,7 +45,7 @@ import { FEE_TIERS } from "./orca_create_single_sided_liquidity_pool";
|
||||
*
|
||||
* @remarks
|
||||
* This function only initializes the CLMM pool and does not add liquidity. For adding liquidity, you can use
|
||||
* a separate function after the pool is successfully created.
|
||||
* a separate function after the pool is successfully created.
|
||||
* ```
|
||||
*/
|
||||
export async function orcaCreateCLMM(
|
||||
@@ -57,12 +57,16 @@ export async function orcaCreateCLMM(
|
||||
): Promise<string> {
|
||||
try {
|
||||
let whirlpoolsConfigAddress: PublicKey;
|
||||
if (agent.connection.rpcEndpoint.includes('mainnet')) {
|
||||
whirlpoolsConfigAddress = new PublicKey('2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ');
|
||||
} else if (agent.connection.rpcEndpoint.includes('devnet')) {
|
||||
whirlpoolsConfigAddress = new PublicKey('FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR');
|
||||
if (agent.connection.rpcEndpoint.includes("mainnet")) {
|
||||
whirlpoolsConfigAddress = new PublicKey(
|
||||
"2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ",
|
||||
);
|
||||
} else if (agent.connection.rpcEndpoint.includes("devnet")) {
|
||||
whirlpoolsConfigAddress = new PublicKey(
|
||||
"FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR",
|
||||
);
|
||||
} else {
|
||||
throw new Error('Unsupported network');
|
||||
throw new Error("Unsupported network");
|
||||
}
|
||||
const wallet = new Wallet(agent.wallet);
|
||||
const ctx = WhirlpoolContext.from(
|
||||
@@ -71,14 +75,12 @@ export async function orcaCreateCLMM(
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
);
|
||||
const fetcher = ctx.fetcher;
|
||||
const client = buildWhirlpoolClient(ctx)
|
||||
const client = buildWhirlpoolClient(ctx);
|
||||
|
||||
const correctTokenOrder = PoolUtil.orderMints(
|
||||
mintDeploy,
|
||||
mintPair,
|
||||
).map((addr) => addr.toString());
|
||||
const isCorrectMintOrder =
|
||||
correctTokenOrder[0] === mintDeploy.toString();
|
||||
const correctTokenOrder = PoolUtil.orderMints(mintDeploy, mintPair).map(
|
||||
(addr) => addr.toString(),
|
||||
);
|
||||
const isCorrectMintOrder = correctTokenOrder[0] === mintDeploy.toString();
|
||||
let mintA;
|
||||
let mintB;
|
||||
if (!isCorrectMintOrder) {
|
||||
@@ -94,7 +96,12 @@ export async function orcaCreateCLMM(
|
||||
}
|
||||
|
||||
const tickSpacing = FEE_TIERS[feeTier];
|
||||
const initialTick = PriceMath.priceToInitializableTickIndex(initialPrice, mintAAccount.decimals, mintBAccount.decimals, tickSpacing)
|
||||
const initialTick = PriceMath.priceToInitializableTickIndex(
|
||||
initialPrice,
|
||||
mintAAccount.decimals,
|
||||
mintBAccount.decimals,
|
||||
tickSpacing,
|
||||
);
|
||||
const { poolKey, tx: txBuilder } = await client.createPool(
|
||||
whirlpoolsConfigAddress,
|
||||
mintA,
|
||||
@@ -102,16 +109,18 @@ export async function orcaCreateCLMM(
|
||||
tickSpacing,
|
||||
initialTick,
|
||||
wallet.publicKey,
|
||||
)
|
||||
);
|
||||
|
||||
const txPayload = await txBuilder.build();
|
||||
const txPayloadDecompiled = TransactionMessage.decompile((txPayload.transaction as VersionedTransaction).message);
|
||||
const txPayloadDecompiled = TransactionMessage.decompile(
|
||||
(txPayload.transaction as VersionedTransaction).message,
|
||||
);
|
||||
const instructions = txPayloadDecompiled.instructions;
|
||||
|
||||
const txId = await sendTx(
|
||||
agent,
|
||||
instructions,
|
||||
txPayload.signers as Keypair[]
|
||||
txPayload.signers as Keypair[],
|
||||
);
|
||||
return JSON.stringify({
|
||||
transactionId: txId,
|
||||
@@ -120,4 +129,4 @@ export async function orcaCreateCLMM(
|
||||
} catch (error) {
|
||||
throw new Error(`${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
TransactionMessage,
|
||||
VersionedTransaction
|
||||
import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { BN, Wallet } from "@coral-xyz/anchor";
|
||||
@@ -112,12 +112,16 @@ export async function orcaCreateSingleSidedLiquidityPool(
|
||||
): Promise<string> {
|
||||
try {
|
||||
let whirlpoolsConfigAddress: PublicKey;
|
||||
if (agent.connection.rpcEndpoint.includes('mainnet')) {
|
||||
whirlpoolsConfigAddress = new PublicKey('2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ');
|
||||
} else if (agent.connection.rpcEndpoint.includes('devnet')) {
|
||||
whirlpoolsConfigAddress = new PublicKey('FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR');
|
||||
if (agent.connection.rpcEndpoint.includes("mainnet")) {
|
||||
whirlpoolsConfigAddress = new PublicKey(
|
||||
"2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ",
|
||||
);
|
||||
} else if (agent.connection.rpcEndpoint.includes("devnet")) {
|
||||
whirlpoolsConfigAddress = new PublicKey(
|
||||
"FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR",
|
||||
);
|
||||
} else {
|
||||
throw new Error('Unsupported network');
|
||||
throw new Error("Unsupported network");
|
||||
}
|
||||
const wallet = new Wallet(agent.wallet);
|
||||
const ctx = WhirlpoolContext.from(
|
||||
@@ -263,7 +267,7 @@ export async function orcaCreateSingleSidedLiquidityPool(
|
||||
) {
|
||||
throw Error("Prices out of bounds");
|
||||
}
|
||||
depositTokenAmount = isCorrectMintOrder
|
||||
depositTokenAmount = isCorrectMintOrder
|
||||
? depositTokenAmount * Math.pow(10, mintAAccount.decimals)
|
||||
: depositTokenAmount * Math.pow(10, mintBAccount.decimals);
|
||||
const increasLiquidityQuoteParam: IncreaseLiquidityQuoteParam = {
|
||||
@@ -388,7 +392,9 @@ export async function orcaCreateSingleSidedLiquidityPool(
|
||||
tickArrayUpper: tickArrayUpperPda.publicKey,
|
||||
};
|
||||
|
||||
const liquidityIx = !TokenExtensionUtil.isV2IxRequiredPool(tokenExtensionCtx)
|
||||
const liquidityIx = !TokenExtensionUtil.isV2IxRequiredPool(
|
||||
tokenExtensionCtx,
|
||||
)
|
||||
? increaseLiquidityIx(ctx.program, baseParamsLiquidity)
|
||||
: increaseLiquidityV2Ix(ctx.program, {
|
||||
...baseParamsLiquidity,
|
||||
@@ -404,14 +410,13 @@ export async function orcaCreateSingleSidedLiquidityPool(
|
||||
(txPayload.transaction as VersionedTransaction).message,
|
||||
).instructions;
|
||||
|
||||
|
||||
const txId = await sendTx(
|
||||
agent,
|
||||
instructions,
|
||||
[positionMintKeypair, tokenVaultAKeypair, tokenVaultBKeypair],
|
||||
);
|
||||
const txId = await sendTx(agent, instructions, [
|
||||
positionMintKeypair,
|
||||
tokenVaultAKeypair,
|
||||
tokenVaultBKeypair,
|
||||
]);
|
||||
return txId;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to send transaction: ${JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,18 +58,18 @@ export async function orcaFetchPositions(
|
||||
wallet,
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
);
|
||||
const client = buildWhirlpoolClient(ctx)
|
||||
const client = buildWhirlpoolClient(ctx);
|
||||
|
||||
const positions = await getAllPositionAccountsByOwner({
|
||||
ctx,
|
||||
owner: agent.wallet.publicKey
|
||||
})
|
||||
ctx,
|
||||
owner: agent.wallet.publicKey,
|
||||
});
|
||||
const positionDatas = [
|
||||
...positions.positions.entries(),
|
||||
...positions.positionsWithTokenExtensions.entries()
|
||||
...positions.positionsWithTokenExtensions.entries(),
|
||||
];
|
||||
const result: PositionDataMap = {};
|
||||
for (const [_, positionData] of positionDatas) {
|
||||
for (const [, positionData] of positionDatas) {
|
||||
const positionMintAddress = positionData.positionMint;
|
||||
const whirlpoolAddress = positionData.whirlpool;
|
||||
const whirlpool = await client.getPool(whirlpoolAddress);
|
||||
@@ -78,16 +78,34 @@ export async function orcaFetchPositions(
|
||||
const currentTick = whirlpoolData.tickCurrentIndex;
|
||||
const mintA = whirlpool.getTokenAInfo();
|
||||
const mintB = whirlpool.getTokenBInfo();
|
||||
const currentPrice = PriceMath.sqrtPriceX64ToPrice(sqrtPrice, mintA.decimals, mintB.decimals);
|
||||
const lowerTick = positionData.tickLowerIndex
|
||||
const upperTick = positionData.tickUpperIndex
|
||||
const lowerPrice = PriceMath.tickIndexToPrice(lowerTick, mintA.decimals, mintB.decimals);
|
||||
const upperPrice = PriceMath.tickIndexToPrice(upperTick, mintA.decimals, mintB.decimals);
|
||||
const centerPosition = (lowerPrice.add(upperPrice)).div(2);
|
||||
const currentPrice = PriceMath.sqrtPriceX64ToPrice(
|
||||
sqrtPrice,
|
||||
mintA.decimals,
|
||||
mintB.decimals,
|
||||
);
|
||||
const lowerTick = positionData.tickLowerIndex;
|
||||
const upperTick = positionData.tickUpperIndex;
|
||||
const lowerPrice = PriceMath.tickIndexToPrice(
|
||||
lowerTick,
|
||||
mintA.decimals,
|
||||
mintB.decimals,
|
||||
);
|
||||
const upperPrice = PriceMath.tickIndexToPrice(
|
||||
upperTick,
|
||||
mintA.decimals,
|
||||
mintB.decimals,
|
||||
);
|
||||
const centerPosition = lowerPrice.add(upperPrice).div(2);
|
||||
|
||||
const positionInRange = (currentTick > lowerTick && currentTick < upperTick) ? true : false;
|
||||
const positionInRange =
|
||||
currentTick > lowerTick && currentTick < upperTick ? true : false;
|
||||
const distanceFromCenterBps = Math.ceil(
|
||||
currentPrice.sub(centerPosition).abs().div(centerPosition).mul(10000).toNumber()
|
||||
currentPrice
|
||||
.sub(centerPosition)
|
||||
.abs()
|
||||
.div(centerPosition)
|
||||
.mul(10000)
|
||||
.toNumber(),
|
||||
);
|
||||
|
||||
result[positionMintAddress.toString()] = {
|
||||
@@ -100,4 +118,4 @@ export async function orcaFetchPositions(
|
||||
} catch (error) {
|
||||
throw new Error(`${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { Keypair, PublicKey, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
|
||||
import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
TransactionInstruction,
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "@coral-xyz/anchor";
|
||||
import { Decimal } from "decimal.js";
|
||||
@@ -20,7 +26,7 @@ import { TOKEN_2022_PROGRAM_ID } from "@solana/spl-token";
|
||||
* # Opens a Centered Liquidity Position in an Orca Whirlpool
|
||||
*
|
||||
* This function opens a centered liquidity position in a specified Orca Whirlpool. The user defines
|
||||
* a basis point (bps) offset from the cuurent price of the pool to set the lower and upper bounds of the position.
|
||||
* a basis point (bps) offset from the cuurent price of the pool to set the lower and upper bounds of the position.
|
||||
* The user also specifies the token mint and the amount to deposit. The required amount of the other token
|
||||
* is calculated automatically.
|
||||
*
|
||||
@@ -69,29 +75,44 @@ export async function orcaOpenCenteredPositionWithLiquidity(
|
||||
wallet,
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
);
|
||||
const client = buildWhirlpoolClient(ctx)
|
||||
const client = buildWhirlpoolClient(ctx);
|
||||
|
||||
const whirlpool = await client.getPool(whirlpoolAddress);
|
||||
const whirlpoolData = whirlpool.getData();
|
||||
const mintInfoA = whirlpool.getTokenAInfo()
|
||||
const mintInfoB = whirlpool.getTokenBInfo()
|
||||
const mintInfoA = whirlpool.getTokenAInfo();
|
||||
const mintInfoB = whirlpool.getTokenBInfo();
|
||||
const price = PriceMath.sqrtPriceX64ToPrice(
|
||||
whirlpoolData.sqrtPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals
|
||||
)
|
||||
mintInfoB.decimals,
|
||||
);
|
||||
|
||||
const lowerPrice = price.mul(1 - priceOffsetBps / 10000)
|
||||
const upperPrice = price.mul(1 + priceOffsetBps / 10000)
|
||||
const lowerTick = PriceMath.priceToInitializableTickIndex(lowerPrice, mintInfoA.decimals, mintInfoB.decimals, whirlpoolData.tickSpacing)
|
||||
const upperTick = PriceMath.priceToInitializableTickIndex(upperPrice, mintInfoA.decimals, mintInfoB.decimals, whirlpoolData.tickSpacing)
|
||||
const lowerPrice = price.mul(1 - priceOffsetBps / 10000);
|
||||
const upperPrice = price.mul(1 + priceOffsetBps / 10000);
|
||||
const lowerTick = PriceMath.priceToInitializableTickIndex(
|
||||
lowerPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals,
|
||||
whirlpoolData.tickSpacing,
|
||||
);
|
||||
const upperTick = PriceMath.priceToInitializableTickIndex(
|
||||
upperPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals,
|
||||
whirlpoolData.tickSpacing,
|
||||
);
|
||||
|
||||
const txBuilderTickArrays = await whirlpool.initTickArrayForTicks([lowerTick, upperTick])
|
||||
let instructions: TransactionInstruction[] = []
|
||||
let signers: Keypair[] = []
|
||||
const txBuilderTickArrays = await whirlpool.initTickArrayForTicks([
|
||||
lowerTick,
|
||||
upperTick,
|
||||
]);
|
||||
let instructions: TransactionInstruction[] = [];
|
||||
let signers: Keypair[] = [];
|
||||
if (txBuilderTickArrays !== null) {
|
||||
const txPayloadTickArrays = await txBuilderTickArrays.build();
|
||||
const txPayloadTickArraysDecompiled = TransactionMessage.decompile((txPayloadTickArrays.transaction as VersionedTransaction).message);
|
||||
const txPayloadTickArraysDecompiled = TransactionMessage.decompile(
|
||||
(txPayloadTickArrays.transaction as VersionedTransaction).message,
|
||||
);
|
||||
const instructionsTickArrays = txPayloadTickArraysDecompiled.instructions;
|
||||
instructions = instructions.concat(instructionsTickArrays);
|
||||
signers = signers.concat(txPayloadTickArrays.signers as Keypair[]);
|
||||
@@ -109,33 +130,32 @@ export async function orcaOpenCenteredPositionWithLiquidity(
|
||||
upperTick,
|
||||
Percentage.fromFraction(1, 100),
|
||||
whirlpool,
|
||||
tokenExtensionCtx
|
||||
)
|
||||
const { positionMint, tx: txBuilder } = await whirlpool.openPositionWithMetadata(
|
||||
lowerTick,
|
||||
upperTick,
|
||||
increaseLiquiditQuote,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
TOKEN_2022_PROGRAM_ID
|
||||
)
|
||||
tokenExtensionCtx,
|
||||
);
|
||||
const { positionMint, tx: txBuilder } =
|
||||
await whirlpool.openPositionWithMetadata(
|
||||
lowerTick,
|
||||
upperTick,
|
||||
increaseLiquiditQuote,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
TOKEN_2022_PROGRAM_ID,
|
||||
);
|
||||
|
||||
const txPayload = await txBuilder.build();
|
||||
const txPayloadDecompiled = TransactionMessage.decompile((txPayload.transaction as VersionedTransaction).message);
|
||||
const txPayloadDecompiled = TransactionMessage.decompile(
|
||||
(txPayload.transaction as VersionedTransaction).message,
|
||||
);
|
||||
instructions = instructions.concat(txPayloadDecompiled.instructions);
|
||||
signers = signers.concat(txPayload.signers as Keypair[]);
|
||||
|
||||
const txId = await sendTx(
|
||||
agent,
|
||||
instructions,
|
||||
signers
|
||||
);
|
||||
const txId = await sendTx(agent, instructions, signers);
|
||||
return JSON.stringify({
|
||||
transactionId: txId,
|
||||
positionMint: positionMint.toString(),
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error(`${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Keypair, PublicKey, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
|
||||
import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
TransactionMessage,
|
||||
VersionedTransaction,
|
||||
} from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { Wallet } from "@coral-xyz/anchor";
|
||||
import { Decimal } from "decimal.js";
|
||||
@@ -52,7 +57,7 @@ export async function orcaOpenSingleSidedPosition(
|
||||
distanceFromCurrentPriceBps: number,
|
||||
widthBps: number,
|
||||
inputTokenMint: PublicKey,
|
||||
inputAmount: Decimal
|
||||
inputAmount: Decimal,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const wallet = new Wallet(agent.wallet);
|
||||
@@ -70,7 +75,7 @@ export async function orcaOpenSingleSidedPosition(
|
||||
const price = PriceMath.sqrtPriceX64ToPrice(
|
||||
whirlpoolData.sqrtPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals
|
||||
mintInfoB.decimals,
|
||||
);
|
||||
|
||||
const isTokenA = inputTokenMint.equals(mintInfoA.mint);
|
||||
@@ -85,13 +90,13 @@ export async function orcaOpenSingleSidedPosition(
|
||||
upperBoundPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals,
|
||||
whirlpoolData.tickSpacing
|
||||
whirlpoolData.tickSpacing,
|
||||
);
|
||||
lowerTick = PriceMath.priceToInitializableTickIndex(
|
||||
lowerBoundPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals,
|
||||
whirlpoolData.tickSpacing
|
||||
whirlpoolData.tickSpacing,
|
||||
);
|
||||
} else {
|
||||
lowerBoundPrice = price.mul(1 - distanceFromCurrentPriceBps / 10000);
|
||||
@@ -100,26 +105,31 @@ export async function orcaOpenSingleSidedPosition(
|
||||
upperBoundPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals,
|
||||
whirlpoolData.tickSpacing
|
||||
whirlpoolData.tickSpacing,
|
||||
);
|
||||
upperTick = PriceMath.priceToInitializableTickIndex(
|
||||
lowerBoundPrice,
|
||||
mintInfoA.decimals,
|
||||
mintInfoB.decimals,
|
||||
whirlpoolData.tickSpacing
|
||||
whirlpoolData.tickSpacing,
|
||||
);
|
||||
}
|
||||
|
||||
const txBuilderTickArrays = await whirlpool.initTickArrayForTicks([lowerTick, upperTick]);
|
||||
let txIds: string = '';
|
||||
const txBuilderTickArrays = await whirlpool.initTickArrayForTicks([
|
||||
lowerTick,
|
||||
upperTick,
|
||||
]);
|
||||
let txIds: string = "";
|
||||
if (txBuilderTickArrays !== null) {
|
||||
const txPayloadTickArrays = await txBuilderTickArrays.build();
|
||||
const txPayloadTickArraysDecompiled = TransactionMessage.decompile((txPayloadTickArrays.transaction as VersionedTransaction).message);
|
||||
const txPayloadTickArraysDecompiled = TransactionMessage.decompile(
|
||||
(txPayloadTickArrays.transaction as VersionedTransaction).message,
|
||||
);
|
||||
const instructions = txPayloadTickArraysDecompiled.instructions;
|
||||
const signers = txPayloadTickArrays.signers as Keypair[];
|
||||
|
||||
const tickArrayTxId = await sendTx(agent, instructions, signers);
|
||||
txIds += tickArrayTxId + ',';
|
||||
txIds += tickArrayTxId + ",";
|
||||
}
|
||||
|
||||
const tokenExtensionCtx: TokenExtensionContextForPool = {
|
||||
@@ -134,25 +144,28 @@ export async function orcaOpenSingleSidedPosition(
|
||||
upperTick,
|
||||
Percentage.fromFraction(1, 100),
|
||||
whirlpool,
|
||||
tokenExtensionCtx
|
||||
);
|
||||
const { positionMint, tx: txBuilder } = await whirlpool.openPositionWithMetadata(
|
||||
lowerTick,
|
||||
upperTick,
|
||||
increaseLiquiditQuote,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
TOKEN_2022_PROGRAM_ID
|
||||
tokenExtensionCtx,
|
||||
);
|
||||
const { positionMint, tx: txBuilder } =
|
||||
await whirlpool.openPositionWithMetadata(
|
||||
lowerTick,
|
||||
upperTick,
|
||||
increaseLiquiditQuote,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
TOKEN_2022_PROGRAM_ID,
|
||||
);
|
||||
|
||||
const txPayload = await txBuilder.build();
|
||||
const txPayloadDecompiled = TransactionMessage.decompile((txPayload.transaction as VersionedTransaction).message);
|
||||
const txPayloadDecompiled = TransactionMessage.decompile(
|
||||
(txPayload.transaction as VersionedTransaction).message,
|
||||
);
|
||||
const instructions = txPayloadDecompiled.instructions;
|
||||
const signers = txPayload.signers as Keypair[];
|
||||
|
||||
const positionTxId = await sendTx(agent, instructions, signers);
|
||||
txIds += positionTxId;
|
||||
txIds += positionTxId;
|
||||
|
||||
return JSON.stringify({
|
||||
transactionIds: txIds,
|
||||
|
||||
Reference in New Issue
Block a user