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: adrena-perp-trading #2261

Closed
wants to merge 9 commits into from
Closed

Conversation

pann0x
Copy link

@pann0x pann0x commented Jan 13, 2025

Relates to

N/A

Risks

Low

Background

What does this PR do?

Adds feature to open perpetual trading using adrena protocol through solana-agent-kit.

What kind of change is this?

features (non-breaking, only adding functionality)
expect added features including closing a position, shorting, and reducing parameters required such as contract address and price. (feel free to include missing features)

Enables sized positions on-chain through user input.

Documentation changes needed?

No changes required.

image
image
image

Testing

Where should a reviewer start?

go to plugin-solana-agentkit

Detailed testing steps

mention all parameters required. change are expected.

@wtfsayo
Copy link
Member

wtfsayo commented Jan 14, 2025

recommend creating separate plugin!

@wtfsayo wtfsayo closed this Jan 14, 2025
@pann0x
Copy link
Author

pann0x commented Jan 14, 2025

Won't be able to use a separate plugin; it uses the same kit from solana-agent-kit: here

@wtfsayo wtfsayo reopened this Jan 14, 2025
@wtfsayo
Copy link
Member

wtfsayo commented Jan 15, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the Solana AgentKit plugin, expanding its capabilities with new actions and constants. The changes include adding support for perpetual trades on the Adrena protocol, introducing token-related constants, and extending the plugin's action set. The modifications prepare the infrastructure for more complex trading and token creation operations within the Solana ecosystem.

Changes

File Change Summary
packages/plugin-solana-agentkit/src/actions/createToken.ts Added commented-out parameters suggesting future interface expansion for token creation
packages/plugin-solana-agentkit/src/actions/openPerpTrade.ts New module for handling leveraged perpetual trades, including interface, validation function, and trade execution handler
packages/plugin-solana-agentkit/src/constants.ts Introduced constants for token addresses, default trading options, and API configurations
packages/plugin-solana-agentkit/src/index.ts Added openPerpTrade action to the plugin's action array
packages/plugin-solana-agentkit/src/types.ts Added new flashTradeContent interface for trade-related type definitions

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
packages/plugin-solana-agentkit/src/actions/openPerpTrade.ts (1)

181-187: Enhance success feedback to the user

Provide more details upon successful trade execution, such as a link to the transaction on a block explorer.

packages/plugin-solana-agentkit/src/types.ts (1)

3-8: Standardize interface naming

Consider using FlashTradeContent instead of flashTradeContent to follow PascalCase convention for interface names.

Rename the interface:

-export interface flashTradeContent extends Content {
+export interface FlashTradeContent extends Content {
    token: string;
    side: "long" | "short";
    collateralUsd: number;
    leverage: number;
}
packages/plugin-solana-agentkit/src/constants.ts (1)

33-35: Consider environment-based API URL configuration.

The hardcoded API URL might make it difficult to switch between environments (e.g., testnet). Also, the empty referral address needs attention.

Consider using environment variables:

export const JUP_API = process.env.JUP_API_URL || "https://quote-api.jup.ag/v6";
export const JUP_REFERRAL_ADDRESS = process.env.JUP_REFERRAL_ADDRESS || "";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89b6a19 and b75eb31.

📒 Files selected for processing (5)
  • packages/plugin-solana-agentkit/src/actions/createToken.ts (1 hunks)
  • packages/plugin-solana-agentkit/src/actions/openPerpTrade.ts (1 hunks)
  • packages/plugin-solana-agentkit/src/constants.ts (1 hunks)
  • packages/plugin-solana-agentkit/src/index.ts (1 hunks)
  • packages/plugin-solana-agentkit/src/types.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/plugin-solana-agentkit/src/actions/createToken.ts
🔇 Additional comments (4)
packages/plugin-solana-agentkit/src/actions/openPerpTrade.ts (1)

169-176: Add input validation before executing trade

Ensure all inputs are valid before calling openPerpTradeLong to prevent runtime errors.

Add checks for content.price, content.collateralAmount, and other required fields.

packages/plugin-solana-agentkit/src/index.ts (2)

3-3: ⚠️ Potential issue

Fix typo in variable name

Variable solanaAgentkitPlguin is misspelled.

Correct the variable name:

-export const solanaAgentkitPlguin: Plugin = {
+export const solanaAgentkitPlugin: Plugin = {

Update all references accordingly.

Likely invalid or redundant comment.


10-10: Ensure new action is properly integrated

Verify that openPerpTrade is correctly imported and added to the actions array.

Confirm import statement:

-import openPerpTrade from "./actions/openPerpTrade.ts";
+import openPerpTrade from "./actions/openPerpTrade";

Ensure consistency in import paths.

✅ Verification successful

Import and integration are correct, extension is stylistic

The openPerpTrade action is properly imported and added to the actions array. The .ts extension in the import path is valid, though removing it would maintain consistency with common TypeScript practices.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Find openPerpTrade file
fd openPerpTrade packages/plugin-solana-agentkit/src/actions

# Check import statement and actions array usage
ast-grep --pattern 'import openPerpTrade from "./actions/openPerpTrade"'
ast-grep --pattern 'import openPerpTrade from "./actions/openPerpTrade.ts"'

# Get the content of index.ts to see the actions array
cat packages/plugin-solana-agentkit/src/index.ts

Length of output: 856

packages/plugin-solana-agentkit/src/constants.ts (1)

1-15: Verify token addresses on Solana mainnet.

The token addresses look valid, and the implementation is type-safe.

Let's verify these addresses:

✅ Verification successful

All token addresses verified on Solana mainnet

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify token addresses exist on Solana mainnet
# Note: Using curl to query Solana RPC endpoint

for token in EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA So11111111111111111111111111111111111111112 J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1 mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263; do
  curl -s -X POST https://api.mainnet-beta.solana.com -H "Content-Type: application/json" -d "{
    \"jsonrpc\": \"2.0\",
    \"id\": 1,
    \"method\": \"getAccountInfo\",
    \"params\": [\"$token\"]
  }" | jq '.result.value != null'
done

Length of output: 5083

@wtfsayo
Copy link
Member

wtfsayo commented Jan 15, 2025

can you resolve the flagged issues above @pann0x

pann0x and others added 2 commits January 14, 2025 22:50
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@pann0x
Copy link
Author

pann0x commented Jan 15, 2025

can you resolve the flagged issues above @pann0x

Resolved, await commits.

modelClass: ModelClass.LARGE,
});

//todo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for these?

/**
* Common token addresses used across the toolkit
*/
export const TOKENS = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to get these from jup api?

@@ -0,0 +1,8 @@
import { Content } from "@elizaos/core";

export interface flashTradeContent extends Content {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this interface used?

@wtfsayo
Copy link
Member

wtfsayo commented Jan 15, 2025

please reopen when feedback implemented

@wtfsayo wtfsayo closed this Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants