Skip to content

Commit d7a4f1c

Browse files
committed
chore: orca actions added
1 parent 328201b commit d7a4f1c

File tree

6 files changed

+393
-0
lines changed

6 files changed

+393
-0
lines changed

src/actions/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ import getInfoAction from "./agent/get_info";
7979
import getPriceInferenceAction from "./allora/getPriceInference";
8080
import getAllTopicsAction from "./allora/getAllTopics";
8181
import getInferenceByTopicIdAction from "./allora/getInferenceByTopicId";
82+
import closeOrcaPositionAction from "./orca/closeOrcaPosition";
83+
import createOrcaCLMMAction from "./orca/createOrcaCLMM";
84+
import fetchOrcaPositionsAction from "./orca/fetchOrcaPositions";
85+
import openOrcaCenteredPositionWithLiquidityAction from "./orca/openOrcaCenteredPositionWithLiquidity";
86+
import openOrcaSingleSidedPositionAction from "./orca/openOrcaSingleSidedPosition";
8287
export const ACTIONS = {
8388
GET_INFO_ACTION: getInfoAction,
8489
WALLET_ADDRESS_ACTION: getWalletAddressAction,
@@ -114,6 +119,12 @@ export const ACTIONS = {
114119
RAYDIUM_CREATE_AMM_V4_ACTION: raydiumCreateAmmV4Action,
115120
CREATE_ORCA_SINGLE_SIDED_WHIRLPOOL_ACTION:
116121
createOrcaSingleSidedWhirlpoolAction,
122+
CLOSE_ORCA_POSITION_ACTION: closeOrcaPositionAction,
123+
CREATE_ORCA_CLMM_ACTION: createOrcaCLMMAction,
124+
FETCH_ORCA_POSITIONS_ACTION: fetchOrcaPositionsAction,
125+
OPEN_ORCA_CENTERED_POSITION_WITH_LIQUIDITY_ACTION:
126+
openOrcaCenteredPositionWithLiquidityAction,
127+
OPEN_ORCA_SINGLE_SIDED_POSITION_ACTION: openOrcaSingleSidedPositionAction,
117128
LAUNCH_PUMPFUN_TOKEN_ACTION: launchPumpfunTokenAction,
118129
FLASH_OPEN_TRADE_ACTION: flashOpenTradeAction,
119130
FLASH_CLOSE_TRADE_ACTION: flashCloseTradeAction,

src/actions/orca/closeOrcaPosition.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { z } from "zod";
2+
import type { Action } from "../../types";
3+
import { orcaClosePosition } from "../../tools";
4+
5+
const closeOrcaPositionAction: Action = {
6+
name: "CLOSE_ORCA_POSITION_ACTION",
7+
similes: [
8+
"close orca liquidity position",
9+
"close orca whirlpool position",
10+
"close orca liquidity pool",
11+
"close my orca liquidity position",
12+
],
13+
description:
14+
"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",
15+
examples: [
16+
[
17+
{
18+
input: {
19+
positionMintAddress: "EPjasdf...",
20+
},
21+
output: {
22+
status: "success",
23+
signature: "12Erx...",
24+
message: "Successfully closed Orca whirlpool position",
25+
},
26+
explanation: "Close a USDC/SOL whirlpool position",
27+
},
28+
],
29+
],
30+
schema: z.object({
31+
positionMintAddress: z
32+
.string()
33+
.describe("The mint address of the liquidity position to close"),
34+
}),
35+
handler: async (agent, input) => {
36+
try {
37+
const signature = await orcaClosePosition(
38+
agent,
39+
input.positionMintAddress,
40+
);
41+
42+
return {
43+
status: "success",
44+
signature,
45+
message: "Successfully closed Orca whirlpool position",
46+
};
47+
} catch (e) {
48+
return {
49+
status: "error",
50+
// @ts-expect-error - TS doesn't know that `e` has a `message` property
51+
message: `Failed to close Orca whirlpool position: ${e.message}`,
52+
};
53+
}
54+
},
55+
};
56+
57+
export default closeOrcaPositionAction;

src/actions/orca/createOrcaCLMM.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { z } from "zod";
2+
import type { Action } from "../../types";
3+
import { PublicKey } from "@solana/web3.js";
4+
import { orcaCreateCLMM } from "../../tools";
5+
import Decimal from "decimal.js";
6+
7+
const createOrcaCLMMAction: Action = {
8+
name: "CREATE_ORCA_CLMM_ACTION",
9+
description:
10+
"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.",
11+
similes: [
12+
"create orca clmm",
13+
"create orca concentrated pool",
14+
"create orca clmm pool",
15+
"create orca concentrated liquidity",
16+
],
17+
examples: [
18+
[
19+
{
20+
input: {
21+
mintDeploy: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
22+
mintPair: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
23+
initialPrice: 1.1,
24+
feeTier: 1,
25+
},
26+
output: {
27+
status: "success",
28+
message:
29+
"CLMM pool created successfully. Note: No liquidity was added.",
30+
},
31+
explanation: "Create a CLMM pool with USDC and JUP",
32+
},
33+
],
34+
],
35+
schema: z.object({
36+
mintDeploy: z
37+
.string()
38+
.describe("The mint address of the token you want to deploy"),
39+
mintPair: z
40+
.string()
41+
.describe(
42+
"The mint address of the token you want to pair the deployed mint with",
43+
),
44+
initialPrice: z
45+
.number()
46+
.positive()
47+
.describe("Initial price of mintDeploy in terms of mintPair"),
48+
feeTier: z
49+
.number()
50+
.positive()
51+
.min(1)
52+
.describe(
53+
"The fee tier in bps. Options: 1, 2, 4, 5, 16, 30, 65, 100, 200",
54+
),
55+
}),
56+
handler: async (agent, input) => {
57+
try {
58+
const [mintDeploy, mintPair, initialPrice, feeTier] = [
59+
new PublicKey(input.mintDeploy),
60+
new PublicKey(input.mintPair),
61+
new Decimal(input.initialPrice),
62+
input.feeTier,
63+
];
64+
65+
const signature = await orcaCreateCLMM(
66+
agent,
67+
mintDeploy,
68+
mintPair,
69+
initialPrice,
70+
feeTier,
71+
);
72+
73+
return {
74+
status: "success",
75+
message:
76+
"CLMM pool created successfully. Note: No liquidity was added.",
77+
signature,
78+
};
79+
} catch (e) {
80+
return {
81+
status: "error",
82+
// @ts-expect-error - TS doesn't know that `e` has a `message` property
83+
message: `Failed to create Orca CLMM pool: ${e.message}`,
84+
};
85+
}
86+
},
87+
};
88+
89+
export default createOrcaCLMMAction;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { z } from "zod";
2+
import type { Action } from "../../types";
3+
import { orcaFetchPositions } from "../../tools";
4+
5+
const fetchOrcaPositionsAction: Action = {
6+
name: "FETCH_ORCA_POSITIONS_ACTION",
7+
description:
8+
"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.",
9+
similes: [
10+
"fetch orca liquidity positions",
11+
"fetch orca whirlpool positions",
12+
"fetch orca liquidity pools",
13+
"fetch my orca liquidity positions",
14+
],
15+
examples: [
16+
[
17+
{
18+
input: {},
19+
output: {
20+
status: "success",
21+
message: "Liquidity positions fetched.",
22+
positions: {
23+
positionMintAddress1: {
24+
whirlpoolAddress: "whirlpoolAddress1",
25+
positionInRange: true,
26+
distanceFromCenterBps: 250,
27+
},
28+
},
29+
},
30+
explanation: "Fetch all Orca whirlpool positions",
31+
},
32+
],
33+
],
34+
schema: z.object({}),
35+
handler: async (agent) => {
36+
try {
37+
const positions = JSON.parse(await orcaFetchPositions(agent));
38+
39+
return {
40+
status: "success",
41+
message: "Liquidity positions fetched.",
42+
positions,
43+
};
44+
} catch (e) {
45+
return {
46+
status: "error",
47+
// @ts-expect-error - TS doesn't know that `e` has a `message` property
48+
message: `Failed to fetch Orca whirlpool positions: ${e.message}`,
49+
};
50+
}
51+
},
52+
};
53+
54+
export default fetchOrcaPositionsAction;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { z } from "zod";
2+
import type { Action } from "../../types";
3+
import { PublicKey } from "@solana/web3.js";
4+
import { orcaOpenCenteredPositionWithLiquidity } from "../../tools";
5+
import Decimal from "decimal.js";
6+
7+
const openOrcaCenteredPositionWithLiquidityAction: Action = {
8+
name: "OPEN_ORCA_CENTERED_POSITION_WITH_LIQUIDITY_ACTION",
9+
description:
10+
"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.",
11+
similes: [
12+
"open orca liquidity position",
13+
"open orca whirlpool position",
14+
"open orca liquidity pool",
15+
"open new orca liquidity position",
16+
"open centered orca liquidity position",
17+
],
18+
examples: [
19+
[
20+
{
21+
input: {
22+
whirlpoolAddress: "EPjasdf...",
23+
priceOffsetBps: 500,
24+
inputTokenMint: "EPjasdf...",
25+
inputAmount: 100.0,
26+
},
27+
output: {
28+
status: "success",
29+
signature: "12Erx...",
30+
message: "Centered liquidity position opened successfully",
31+
},
32+
explanation: "Open a USDC/SOL whirlpool position",
33+
},
34+
],
35+
],
36+
schema: z.object({
37+
whirlpoolAddress: z
38+
.string()
39+
.describe("The address of the Orca whirlpool to open a position in"),
40+
priceOffsetBps: z
41+
.number()
42+
.positive()
43+
.min(100)
44+
.describe("The price offset in basis points for the new position"),
45+
inputTokenMint: z
46+
.string()
47+
.describe("The mint address of the token to deposit"),
48+
inputAmount: z
49+
.number()
50+
.positive()
51+
.describe("The amount of the token to deposit"),
52+
}),
53+
handler: async (agent, input) => {
54+
try {
55+
const [whirlpoolAddress, inputTokenMint, priceOffsetBps, inputAmount] = [
56+
new PublicKey(input.whirlpoolAddress),
57+
new PublicKey(input.inputTokenMint),
58+
input.priceOffsetBps,
59+
new Decimal(input.inputAmount),
60+
];
61+
62+
const signature = await orcaOpenCenteredPositionWithLiquidity(
63+
agent,
64+
whirlpoolAddress,
65+
priceOffsetBps,
66+
inputTokenMint,
67+
inputAmount,
68+
);
69+
70+
return {
71+
status: "success",
72+
signature,
73+
message: "Centered liquidity position opened successfully",
74+
};
75+
} catch (e) {
76+
return {
77+
status: "error",
78+
// @ts-expect-error - TS doesn't know that `e` has a `message` property
79+
message: `Failed to open centered Orca whirlpool position: ${e.message}`,
80+
};
81+
}
82+
},
83+
};
84+
85+
export default openOrcaCenteredPositionWithLiquidityAction;

0 commit comments

Comments
 (0)