Skip to content

Commit

Permalink
Merge branch 'main' into feat/mayan-swap-sdk
Browse files Browse the repository at this point in the history
* main:
  fix: convert position mint to pub key
  chore: orca actions added
  • Loading branch information
zoli committed Jan 29, 2025
2 parents fc10666 + c5a48c3 commit a994554
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ import swapAction from "./mayan/swap";
import getPriceInferenceAction from "./allora/getPriceInference";
import getAllTopicsAction from "./allora/getAllTopics";
import getInferenceByTopicIdAction from "./allora/getInferenceByTopicId";
import closeOrcaPositionAction from "./orca/closeOrcaPosition";
import createOrcaCLMMAction from "./orca/createOrcaCLMM";
import fetchOrcaPositionsAction from "./orca/fetchOrcaPositions";
import openOrcaCenteredPositionWithLiquidityAction from "./orca/openOrcaCenteredPositionWithLiquidity";
import openOrcaSingleSidedPositionAction from "./orca/openOrcaSingleSidedPosition";

export const ACTIONS = {
GET_INFO_ACTION: getInfoAction,
Expand Down Expand Up @@ -116,6 +121,12 @@ export const ACTIONS = {
RAYDIUM_CREATE_AMM_V4_ACTION: raydiumCreateAmmV4Action,
CREATE_ORCA_SINGLE_SIDED_WHIRLPOOL_ACTION:
createOrcaSingleSidedWhirlpoolAction,
CLOSE_ORCA_POSITION_ACTION: closeOrcaPositionAction,
CREATE_ORCA_CLMM_ACTION: createOrcaCLMMAction,
FETCH_ORCA_POSITIONS_ACTION: fetchOrcaPositionsAction,
OPEN_ORCA_CENTERED_POSITION_WITH_LIQUIDITY_ACTION:
openOrcaCenteredPositionWithLiquidityAction,
OPEN_ORCA_SINGLE_SIDED_POSITION_ACTION: openOrcaSingleSidedPositionAction,
LAUNCH_PUMPFUN_TOKEN_ACTION: launchPumpfunTokenAction,
FLASH_OPEN_TRADE_ACTION: flashOpenTradeAction,
FLASH_CLOSE_TRADE_ACTION: flashCloseTradeAction,
Expand Down
58 changes: 58 additions & 0 deletions src/actions/orca/closeOrcaPosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { z } from "zod";
import type { Action } from "../../types";
import { orcaClosePosition } from "../../tools";
import { PublicKey } from "@solana/web3.js";

const closeOrcaPositionAction: Action = {
name: "CLOSE_ORCA_POSITION_ACTION",
similes: [
"close orca liquidity position",
"close orca whirlpool position",
"close orca liquidity pool",
"close my orca liquidity position",
],
description:
"Close an existing liquidity position in an Orca Whirlpool. This functions fetches the position details using the provided mint address and closes the position with a 1% slippage",
examples: [
[
{
input: {
positionMintAddress: "EPjasdf...",
},
output: {
status: "success",
signature: "12Erx...",
message: "Successfully closed Orca whirlpool position",
},
explanation: "Close a USDC/SOL whirlpool position",
},
],
],
schema: z.object({
positionMintAddress: z
.string()
.describe("The mint address of the liquidity position to close"),
}),
handler: async (agent, input) => {
try {
const signature = await orcaClosePosition(
agent,
new PublicKey(input.positionMintAddress),
);

return {
status: "success",
signature,
message: "Successfully closed Orca whirlpool position",
};
} catch (e) {
return {
status: "error",
// @ts-expect-error - TS doesn't know that `e` has a `message` property
message: `Failed to close Orca whirlpool position: ${e.message}`,
};
}
},
};

export default closeOrcaPositionAction;
89 changes: 89 additions & 0 deletions src/actions/orca/createOrcaCLMM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { z } from "zod";
import type { Action } from "../../types";
import { PublicKey } from "@solana/web3.js";
import { orcaCreateCLMM } from "../../tools";
import Decimal from "decimal.js";

const createOrcaCLMMAction: Action = {
name: "CREATE_ORCA_CLMM_ACTION",
description:
"Create a Concentrated Liquidity Market Maker (CLMM) pool on Orca, the most efficient and capital-optimized CLMM on Solana. This function initializes a CLMM pool but does not add liquidity. You can add liquidity later using a centered position or a single-sided position.",
similes: [
"create orca clmm",
"create orca concentrated pool",
"create orca clmm pool",
"create orca concentrated liquidity",
],
examples: [
[
{
input: {
mintDeploy: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
mintPair: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
initialPrice: 1.1,
feeTier: 1,
},
output: {
status: "success",
message:
"CLMM pool created successfully. Note: No liquidity was added.",
},
explanation: "Create a CLMM pool with USDC and JUP",
},
],
],
schema: z.object({
mintDeploy: z
.string()
.describe("The mint address of the token you want to deploy"),
mintPair: z
.string()
.describe(
"The mint address of the token you want to pair the deployed mint with",
),
initialPrice: z
.number()
.positive()
.describe("Initial price of mintDeploy in terms of mintPair"),
feeTier: z
.number()
.positive()
.min(1)
.describe(
"The fee tier in bps. Options: 1, 2, 4, 5, 16, 30, 65, 100, 200",
),
}),
handler: async (agent, input) => {
try {
const [mintDeploy, mintPair, initialPrice, feeTier] = [
new PublicKey(input.mintDeploy),
new PublicKey(input.mintPair),
new Decimal(input.initialPrice),
input.feeTier,
];

const signature = await orcaCreateCLMM(
agent,
mintDeploy,
mintPair,
initialPrice,
feeTier,
);

return {
status: "success",
message:
"CLMM pool created successfully. Note: No liquidity was added.",
signature,
};
} catch (e) {
return {
status: "error",
// @ts-expect-error - TS doesn't know that `e` has a `message` property
message: `Failed to create Orca CLMM pool: ${e.message}`,
};
}
},
};

export default createOrcaCLMMAction;
54 changes: 54 additions & 0 deletions src/actions/orca/fetchOrcaPositions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { z } from "zod";
import type { Action } from "../../types";
import { orcaFetchPositions } from "../../tools";

const fetchOrcaPositionsAction: Action = {
name: "FETCH_ORCA_POSITIONS_ACTION",
description:
"Fetch all the liquidity positions in an Orca Whirlpool by owner. Returns an object with position mint addresses as keys and position status details as values.",
similes: [
"fetch orca liquidity positions",
"fetch orca whirlpool positions",
"fetch orca liquidity pools",
"fetch my orca liquidity positions",
],
examples: [
[
{
input: {},
output: {
status: "success",
message: "Liquidity positions fetched.",
positions: {
positionMintAddress1: {
whirlpoolAddress: "whirlpoolAddress1",
positionInRange: true,
distanceFromCenterBps: 250,
},
},
},
explanation: "Fetch all Orca whirlpool positions",
},
],
],
schema: z.object({}),
handler: async (agent) => {
try {
const positions = JSON.parse(await orcaFetchPositions(agent));

return {
status: "success",
message: "Liquidity positions fetched.",
positions,
};
} catch (e) {
return {
status: "error",
// @ts-expect-error - TS doesn't know that `e` has a `message` property
message: `Failed to fetch Orca whirlpool positions: ${e.message}`,
};
}
},
};

export default fetchOrcaPositionsAction;
85 changes: 85 additions & 0 deletions src/actions/orca/openOrcaCenteredPositionWithLiquidity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { z } from "zod";
import type { Action } from "../../types";
import { PublicKey } from "@solana/web3.js";
import { orcaOpenCenteredPositionWithLiquidity } from "../../tools";
import Decimal from "decimal.js";

const openOrcaCenteredPositionWithLiquidityAction: Action = {
name: "OPEN_ORCA_CENTERED_POSITION_WITH_LIQUIDITY_ACTION",
description:
"Open a new Orca whirlpool position with liquidity centered around the current price. This function opens a new liquidity position in an Orca whirlpool with the provided liquidity amount centered around the current price.",
similes: [
"open orca liquidity position",
"open orca whirlpool position",
"open orca liquidity pool",
"open new orca liquidity position",
"open centered orca liquidity position",
],
examples: [
[
{
input: {
whirlpoolAddress: "EPjasdf...",
priceOffsetBps: 500,
inputTokenMint: "EPjasdf...",
inputAmount: 100.0,
},
output: {
status: "success",
signature: "12Erx...",
message: "Centered liquidity position opened successfully",
},
explanation: "Open a USDC/SOL whirlpool position",
},
],
],
schema: z.object({
whirlpoolAddress: z
.string()
.describe("The address of the Orca whirlpool to open a position in"),
priceOffsetBps: z
.number()
.positive()
.min(100)
.describe("The price offset in basis points for the new position"),
inputTokenMint: z
.string()
.describe("The mint address of the token to deposit"),
inputAmount: z
.number()
.positive()
.describe("The amount of the token to deposit"),
}),
handler: async (agent, input) => {
try {
const [whirlpoolAddress, inputTokenMint, priceOffsetBps, inputAmount] = [
new PublicKey(input.whirlpoolAddress),
new PublicKey(input.inputTokenMint),
input.priceOffsetBps,
new Decimal(input.inputAmount),
];

const signature = await orcaOpenCenteredPositionWithLiquidity(
agent,
whirlpoolAddress,
priceOffsetBps,
inputTokenMint,
inputAmount,
);

return {
status: "success",
signature,
message: "Centered liquidity position opened successfully",
};
} catch (e) {
return {
status: "error",
// @ts-expect-error - TS doesn't know that `e` has a `message` property
message: `Failed to open centered Orca whirlpool position: ${e.message}`,
};
}
},
};

export default openOrcaCenteredPositionWithLiquidityAction;
Loading

0 comments on commit a994554

Please sign in to comment.