Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: plugin Solana web3.js V2 & automated LPing on Orca #2136

Merged
merged 29 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2f6b7c6
Build web3.js v2 plugin
calintje Jan 6, 2025
1c013ba
Finish plugin V2 base
calintje Jan 7, 2025
b461852
Try solve deps
calintje Jan 8, 2025
280730e
Resolved deps
calintje Jan 8, 2025
58f3f3e
Clean up
calintje Jan 8, 2025
b29c70e
Enable TEE mode
calintje Jan 8, 2025
c20bcbd
Close position action
calintje Jan 9, 2025
9b523e4
Close position action
calintje Jan 9, 2025
2428482
Add all components. Fixes needed
calintje Jan 10, 2025
f0c56b2
Add README
calintje Jan 10, 2025
88307c9
Merge branch 'main' into calintje/solana-v2
calintje Jan 10, 2025
ddc4d8a
Fix lock
calintje Jan 10, 2025
7cd47df
Fix Provider. Fix first Action. WIP Evaluator.
calintje Jan 14, 2025
9a5a46e
Working demo set-up. Additional work needed
calintje Jan 14, 2025
03383f3
Finish building and testing. New docs needed.
Jan 19, 2025
8ab1674
Add character. Fix bug
Jan 19, 2025
d73edad
Update docs and rpc url reference
Jan 22, 2025
0f7f36b
Merge branch 'develop' into calintje/solana-v2
calintje Jan 22, 2025
cd66ec4
Cleanup
calintje Jan 22, 2025
2830545
Update lockfile
calintje Jan 22, 2025
af721e6
Final nits
calintje Jan 22, 2025
4ccb847
Fix typo
calintje Jan 22, 2025
65eda71
Restore agents/sr/index.ts
calintje Jan 22, 2025
f2e8c53
Merge branch 'develop' into calintje/solana-v2
calintje Jan 25, 2025
66b9033
Fix lockfile
calintje Jan 25, 2025
3d34400
Merge branch 'develop' into calintje/solana-v2
odilitime Jan 25, 2025
ca53205
Merge branch 'develop' into calintje/solana-v2
calintje Jan 25, 2025
7821214
Fix lockfile
calintje Jan 25, 2025
6179aa8
Merge branch 'calintje/solana-v2' of https://github.com/calintje/eliz…
calintje Jan 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@elizaos/plugin-nft-generation": "workspace:*",
"@elizaos/plugin-node": "workspace:*",
"@elizaos/plugin-solana": "workspace:*",
"@elizaos/plugin-solana-v2": "workspace:*",
"@elizaos/plugin-injective": "workspace:*",
"@elizaos/plugin-solana-agent-kit": "workspace:*",
"@elizaos/plugin-squid-router": "workspace:*",
Expand Down Expand Up @@ -125,4 +126,4 @@
"ts-node": "10.9.2",
"tsup": "8.3.5"
}
}
}
5 changes: 3 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
import { quaiPlugin } from "@elizaos/plugin-quai";
import { sgxPlugin } from "@elizaos/plugin-sgx";
import { solanaPlugin } from "@elizaos/plugin-solana";
import { solanaPluginV2 } from "@elizaos/plugin-solana-v2";
import { solanaAgentkitPlugin } from "@elizaos/plugin-solana-agent-kit";
import { squidRouterPlugin } from "@elizaos/plugin-squid-router";
import { stargazePlugin } from "@elizaos/plugin-stargaze";
Expand Down Expand Up @@ -921,7 +922,7 @@ export async function createAgent(
getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? solanaPlugin
? [solanaPlugin, solanaPluginV2]
: null,
getSecret(character, "SOLANA_PRIVATE_KEY")
? solanaAgentkitPlugin
Expand Down Expand Up @@ -1109,7 +1110,7 @@ export async function createAgent(
? nvidiaNimPlugin
: null,
getSecret(character, "INITIA_PRIVATE_KEY") && getSecret(character, "INITIA_NODE_URL") ? initiaPlugin : null
].filter(Boolean),
].flat().filter(Boolean),
providers: [],
actions: [],
services: [],
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"pnpm": {
"overrides": {
"onnxruntime-node": "1.20.1",
"@solana/web3.js@1.95.5": "npm:@solana/web3.js@1.95.5",
"@solana/web3.js@1.95.8": "npm:@solana/web3.js@1.95.8",
"@solana/web3.js@2": "npm:@solana/web3.js@2.0.0",
"viem": "2.21.58"
}
},
Expand All @@ -71,4 +74,4 @@
"workspaces": [
"packages/*"
]
}
}
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@rollup/plugin-replace": "5.0.7",
"@rollup/plugin-terser": "0.1.0",
"@rollup/plugin-typescript": "11.1.6",
"@solana/web3.js": "1.95.8",
"@solana/web3.js": "npm:@solana/web3.js@1.95.8",
"@types/fluent-ffmpeg": "2.1.27",
"@types/jest": "29.5.14",
"@types/mocha": "10.0.10",
Expand Down Expand Up @@ -93,4 +93,4 @@
"uuid": "11.0.3",
"zod": "3.23.8"
}
}
}
4 changes: 2 additions & 2 deletions packages/plugin-nft-generation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
"@openzeppelin/contracts": "^5.1.0",
"@solana-developers/helpers": "^2.5.6",
"@solana/web3.js": "1.95.8",
"@solana/web3.js": "npm:@solana/web3.js@1.95.5",
"axios": "^1.7.9",
"bs58": "6.0.0",
"express": "4.21.1",
Expand All @@ -44,4 +44,4 @@
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
}
4 changes: 2 additions & 2 deletions packages/plugin-solana-agent-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@elizaos/plugin-tee": "workspace:*",
"@elizaos/plugin-trustdb": "workspace:*",
"@solana/spl-token": "0.4.9",
"@solana/web3.js": "1.95.8",
"@solana/web3.js": "npm:@solana/web3.js@1.95.8",
"bignumber": "1.1.0",
"bignumber.js": "9.1.2",
"bs58": "6.0.0",
Expand All @@ -30,4 +30,4 @@
"form-data": "4.0.1",
"whatwg-url": "7.1.0"
}
}
}
122 changes: 122 additions & 0 deletions packages/plugin-solana-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Solana Plugin V2 for Eliza 🌟

The **Solana Plugin V2** leverages the latest features of `@solana/web3.js` v2 to provide a modern, efficient, and composable solution for Solana integrations within the Eliza AI agent framework.

---

## Key Features 🚀

### Modern JavaScript and Functional Architecture
- **@solana/web3.js v2** introduces:
- Tree-shakability
- Composable internals
- Zero-dependency design
- Functional programming approach

### Compatibility with existing solana V1 plugins
- This plugin can be used by the agent alongside existing plugins that use `@solana/web3.js` v1.

### Common Utilities
The `Utils` class provides shared functionality across the plugin, offering flexibility and ease of integration.

#### `sendTransaction`
- Accepts the RPC instance, transaction instructions, and a wallet.
- Utilizes Solana's Compute Budget Program for optimized CU usage and priority fees.
- Implements client-side retry logic to enhance transaction landing success.
- More details on optimizing transactions can be found [here](https://orca-so.github.io/whirlpools/Whirlpools%20SDKs/Whirlpools/Send%20Transaction).

#### Trusted Execution Environment (TEE)
- For Trusted Execution Environment (TEE) functionality, this plugin transitions from `Keypair` (used in v1) to `CryptoKeyPair` from the Web Crypto API. This change aligns with `@solana/web3.js` v2's zero-dependency, modern JavaScript architecture.
- A modified implementation for TEE integration is included in `src/utils/`, following the same patterns used in `plugin-tee`.

---

## Current Functionality 🎯

### Liquidity Position Management
- **Reposition Liquidity**:
- Automatically repositions Orca liquidity positions if the center price of the position deviates from the current pool price by more than a user-specified threshold (`repositionThresholdBps`).
- Maintains the original width of the position during repositioning.
- Repositions at a user defined time interval.
- Uses a slippage tolerance set by the user.

### How to run the Orca LP Management tool
#### 1. Set up your environment variables
- In the root of the repositorty, copy `.env.example` to `.env`
- Fill in the following parameters:
- `SOLANA_PRIVATE_KEY`
- `SOLANA_PUBLIC_KEY`
- `SOLANA_RPC_URL`
- `OPENAI_API_KEY`

#### 2. RPC requirements
Most often, free-tier RPC URLs are not sufficient for this plugin.
- Eliza needs to fetch all your token-accounts in order to find the position NFTs that represent Orca positions. Such calls are done through the `getProgramAccounts` method of the RPC client, which can be expensive.
- To ensure transaction landing, the plugin makes use of a client-side retry logic (read more [here](https://www.helius.dev/blog/how-to-land-transactions-on-solana#how-do-i-land-transactions)), which also puts a heavier load on the RPC.
- The amount of positions you own and the update interval you set can also contribute to RPC limits.

#### 3. Update the agent
In `agent/src/index.ts`, search for the function `createAgent`, and add `solana_plugin_v2` to the `AgentRuntime` like so:
```typescript
export async function createAgent(
character: Character,
db: IDatabaseAdapter,
cache: ICacheManager,
token: string
): Promise<AgentRuntime> {
// Rest of the code ...

return new AgentRuntime({
// Other parameters
plugins: [
// Other plutins
getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? solanaPluginV2
: null,
// Rest of the code
```

#### 4. Use LP Manager character
Copy `packages/plugin-solana-v2/src/character/orca/lpmanager.character.json` to `characters/lpmanager.character.json`.

#### 5. Install and build the repo
Follow the general installation and build steps from the README in the root of the repo

#### 5. Run the agent
Start the the agent with the following command:
```sh
pnpm start --characters="characters/lpmanager.character.json"
```

Start the client (chat terminal) with:
```sh
pnpm start:client
```

#### 6. Start prompting
Ask the agent what it can do for you. Provide the appropriate parameters and let the agent reposition your positions automatically.

#### 7. Other configurations
In `packages/plugin-solana-v2/src/utils/sendTransaction.ts`, you can set the priority fees. They are by default set to use the dynamic fees, but you can adjust this as you like.

## Future Functionality 🔮

### Position Management Enhancements
- **Opening and Closing Positions**:
- Expose opening and closing positions as separate actions.
- Allow agents to leverage data streams and other plugins for decision-making and yield optimization.

### Token Launches
- **Token Creation and Liquidity Setup**:
- Create tokens with metadata using the Token 2022 Program.
- Launch tokens on Orca with single-sided liquidity.
- Configure start and maximum prices for initial liquidity.

---

## Contributing 🤝
Contributions are welcome! If you wish to extend `plugin-solana-v2` with your tools, ensure compatibility with `@solana/web3.js` v2.

---
30 changes: 30 additions & 0 deletions packages/plugin-solana-v2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@elizaos/plugin-solana-v2",
"version": "0.1.7-alpha.2",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@elizaos/plugin-tee": "workspace:*",
"@orca-so/whirlpools": "^1.0.2",
"@orca-so/whirlpools-core": "^1.0.2",
"@orca-so/whirlpools-client": "1.0.2",
"@solana-program/compute-budget": "^0.6.1",
"@solana-program/system": "^0.6.2",
"@solana-program/token-2022": "^0.3.1",
"@solana/codecs": "^2.0.0",
"@solana/web3.js": "^2.0.0",
"@types/bs58": "^4.0.4",
"bs58": "^6.0.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch"
},
"devDependencies": {
"@types/node": "^22.8.7",
"tsup": "8.3.5",
"vitest": "2.1.4"
}
}
Loading
Loading