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 15 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
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@elizaos/plugin-nft-generation": "workspace:*",
"@elizaos/plugin-node": "workspace:*",
"@elizaos/plugin-solana": "workspace:*",
"@elizaos/plugin-solana-v2": "workspace:*",
"@elizaos/plugin-starknet": "workspace:*",
"@elizaos/plugin-ton": "workspace:*",
"@elizaos/plugin-sui": "workspace:*",
Expand Down
6 changes: 4 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { nearPlugin } from "@elizaos/plugin-near";
import { nftGenerationPlugin } from "@elizaos/plugin-nft-generation";
import { createNodePlugin } from "@elizaos/plugin-node";
import { solanaPlugin } from "@elizaos/plugin-solana";
import { solanaPluginV2 } from "@elizaos/plugin-solana-v2";
import { suiPlugin } from "@elizaos/plugin-sui";
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
import { tonPlugin } from "@elizaos/plugin-ton";
Expand Down Expand Up @@ -533,7 +534,7 @@ export async function createAgent(
getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? solanaPlugin
? [solanaPluginV2]
: null,
(getSecret(character, "NEAR_ADDRESS") ||
getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
Expand Down Expand Up @@ -605,11 +606,12 @@ export async function createAgent(
getSecret(character, "AVALANCHE_PRIVATE_KEY")
? avalanchePlugin
: null,

getSecret(character, "ECHOCHAMBERS_API_URL") &&
getSecret(character, "ECHOCHAMBERS_API_KEY")
? echoChamberPlugin
: 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 @@ -47,7 +47,10 @@
},
"pnpm": {
"overrides": {
"onnxruntime-node": "1.20.1"
"onnxruntime-node": "1.20.1",
"@solana/[email protected]": "npm:@solana/[email protected]",
"@solana/[email protected]": "npm:@solana/[email protected]",
"@solana/web3.js@2": "npm:@solana/[email protected]"
}
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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",
"@tavily/core": "^0.0.2",
"@types/fluent-ffmpeg": "2.1.27",
"@types/jest": "29.5.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-nft-generation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@metaplex-foundation/umi": "^0.9.2",
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
"@solana-developers/helpers": "^2.5.6",
"@solana/web3.js": "1.95.5",
"@solana/web3.js": "npm:@solana/web3.js@1.95.5",
"bs58": "6.0.0",
"express": "4.21.1",
"node-cache": "5.1.2",
Expand Down
95 changes: 95 additions & 0 deletions packages/plugin-solana-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# 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.

## Orca DEX integration
This plugin is designed for advanced position management and introduces foundational tools for building DeFi strategies on Orca.

---

## Key Features 🚀

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

### Backward Compatibility
- This plugin can be used 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 isntance, transaction instructions, and a wallet.
calintje marked this conversation as resolved.
Show resolved Hide resolved
- 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`.
calintje marked this conversation as resolved.
Show resolved Hide resolved
---

## Current Functionality 🎯

### Liquidity Position Management
- **Reposition Liquidity**:
- Automatically repositions 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.
- Example: To ensure the center price is within 3% of the current price, set `repositionThresholdBps` to 300.

### Built-in Utilities
- **`Utils` Class**:
- `loadWallet`: Integrates wallet loading with TEE functionality.
- `sendTransaction`: Smart transaction handling with CU optimization.

---

## 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.

---

## Usage 🛠️

### Plugin Configuration For Automated Repositioning
```typescript
export const solanaPluginV2: Plugin = {
name: "solanaV2",
description: "Solana Plugin V2 for Eliza",
actions: [managePositions, repositionPosition],
evaluators: [repositionEvaluator],
providers: [positionProvider],
};
```

### Example Integration
In your `.env` variable, set the following parameters:
```bash
SOLANA_PRIVATE_KEY=
SOLANA_PUBLIC_KEY=
RPC_URL=
calintje marked this conversation as resolved.
Show resolved Hide resolved
```

---

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

---

## Notes 📝
- Refer to the [Orca Whirlpools SDK](https://orca-so.github.io/whirlpools/) for additional resources and context.
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"
}
}
calintje marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading