-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/mayan-swap-sdk
* main: fix: convert position mint to pub key chore: orca actions added
- Loading branch information
Showing
6 changed files
with
394 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.