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: Solana plugin improvement for flawless transfers #2340

Merged
merged 28 commits into from
Jan 18, 2025

Conversation

sunsakis
Copy link
Contributor

Risks

Low risks, the only risk is that someone hooks up this plugin with their Solana wallet and because it is so easy to use spends more tokens than they wanted.

Background

Previous Solana plug-in simply did not work for transfering tokens - the transfer action was never triggered.

Improved Solana plug-in and added a new character who handles all Solana based transactions: SBF.

The transfer action in solana-plugin was split into two separate actions: SEND_SOL and SEND_TOKEN.

This way the agent can handle different transactions better than having both actions in one.

Also added more detailed logging and transaction state monitoring.

WARNING: as of this fresh release, there are yet no confirmations before sending out SOL or SPL tokens, so use for experimentation only.

SBF handles Solana transactions

As plugins and characters in Eliza agentic world go hand-in-hand, SBF is a character made for leveraging Solana plugin.

Setup the client

cp .env.example .env

Input your ANTHROPIC_API_KEY, SOLANA_PRIVATE_KEY and SOLANA_PUBLIC_KEY in .env.

I recommend using Anthropic's Claude, because the success rate of calling transfer actions is highly correlated with the intelligence of the AI used, but instead of ANTHROPIC_API_KEY, you can use any other model, so long as you specify it in the character.json file.

run pnpm install --no-frozen-lockfile and pnpm build to install dependencies and build the project.

run pnpm start --character="characters/sbf.character.json" to start SBF agent up.

run pnpm start:client to start the client and chat with SBF using the client.

NOTE: If something does not work, make the appropriate changes, delete the agent/data/db.sqlite file and pnpm build again to make sure your changes are reflected.

Using the Solana plug-in

If you want the agent to send you SOL or SPL tokens, you need to simply tell the agent to do so.

For example type "send 1.5 SOL to Ae8GkmtaJmr3MS3oKStkZyPHuQf3hawn53XD4bQjVQiu".

This will send 1.5 SOL to the address Ae8GkmtaJmr3MS3oKStkZyPHuQf3hawn53XD4bQjVQiu.

For sending SPL native tokens, apart from the destination address and amount, the token contract address is also needed.

example:

"send 69 GODS (CA: GEVqugYZESSzZaYU6SKdpW6znCCEtH7aoSTzPHbqpump) to Ae8GkmtaJmr3MS3oKStkZyPHuQf3hawn53XD4bQjVQiu"

That's it. Upon success, you will be sent a transaction hash.

extra feats in client-twitter

I needed to run this plugin on Twitter so had to make sure it works with Twitter.

client-twitter was modified to a more sophisticated self-tweet handling - it will still process self-tweets if they're from target users.

Features:

  1. More sophisticated handling of self-tweets and target users
  2. Enhanced debugging capabilities
  3. More robust state handling and action processing
  4. Better formatting of character examples and actions

What kind of change is this?

Bug fixes (non-breaking change which fixes an issue)
Improvements (misc. changes to existing features)
Features (non-breaking change which adds functionality)
Updates (new versions of included code)

Documentation changes needed?

Testing

run pnpm install --no-frozen-lockfile and pnpm build to install dependencies and build the project.

run pnpm start --character="characters/sbf.character.json" to start SBF agent up.

run pnpm start:client to start the client and chat with SBF using the client.

Discord username: sunsakis

This change has been discussed and blessed in ElizaOS Development server #pull-requests

@odilitime odilitime changed the title Solana plugin improvement for flawless transfers feat: Solana plugin improvement for flawless transfers Jan 16, 2025
odilitime
odilitime previously approved these changes Jan 17, 2025
@odilitime odilitime enabled auto-merge (squash) January 17, 2025 17:38
auto-merge was automatically disabled January 17, 2025 18:07

Head branch was pushed to by a user without write access

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

📝 Walkthrough

Walkthrough

This pull request introduces significant updates to the Solana plugin, focusing on token and SOL transfer capabilities. A new character named SBF has been added, representing a crypto-savvy assistant specializing in Solana transfers. The changes involve updating action names, adding new transfer methods, and refining interaction logic across multiple files. The modifications enhance the plugin's functionality while maintaining its core structure.

Changes

File Change Summary
.gitignore Removed characters/ and packages/core/src/providers/cache from ignore list
README.md Cosmetic file content refresh without substantive changes
characters/sbf.character.json New character definition for SBF, a Solana transfer specialist
packages/client-twitter/src/interactions.ts Updated tweet handling logic and context composition
packages/plugin-solana/README.MD Renamed TRANSFER_TOKEN to SEND_TOKEN, added SEND_SOL action
packages/plugin-solana/src/actions/transfer.ts Refined token transfer template, validation, and error handling
packages/plugin-solana/src/actions/transfer_sol.ts New module for SOL transfer functionality
packages/plugin-solana/src/index.ts Updated imports and actions array with new transfer methods

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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: 7

🧹 Nitpick comments (2)
packages/plugin-solana/src/actions/transfer_sol.ts (1)

121-122: Wait for Transaction Confirmation

Immediately after sending the transaction, wait for confirmation to ensure it was processed successfully.

Apply this diff:

 const signature = await connection.sendTransaction(transaction);
+await connection.confirmTransaction(signature, "confirmed");
README.md (1)

82-84: Fix markdown formatting issues.

  1. Add language specifiers to fenced code blocks
  2. Add alt text to contributor image
-```
+```bash
 cp .env.example .env

- +bash
pnpm install --include=optional sharp


-  <img src="https://contrib.rocks/image?repo=elizaos/eliza" />
+  <img src="https://contrib.rocks/image?repo=elizaos/eliza" alt="Project contributors" />

Also applies to: 143-145, 163-164

🧰 Tools
🪛 Markdownlint (0.37.0)

82-82: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 94ee57b and 2702ab6.

📒 Files selected for processing (8)
  • .gitignore (0 hunks)
  • README.md (1 hunks)
  • characters/sbf.character.json (1 hunks)
  • packages/client-twitter/src/interactions.ts (2 hunks)
  • packages/plugin-solana/README.MD (1 hunks)
  • packages/plugin-solana/src/actions/transfer.ts (5 hunks)
  • packages/plugin-solana/src/actions/transfer_sol.ts (1 hunks)
  • packages/plugin-solana/src/index.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • .gitignore
🧰 Additional context used
🪛 LanguageTool
README.md

[grammar] ~66-~66: This sentence should probably be started with a verb instead of the noun ‘Checkout’. If not, consider inserting a comma for better clarity.
Context: ...d if you know what you are doing) #### Checkout the latest release ```bash # Clone the...

(SENT_START_NN_DT)


[typographical] ~157-~157: Do not use a colon (:) before a series that is introduced by a preposition (‘for’). Remove the colon or add a noun or a noun phrase after the preposition.
Context: .../github.com/elizaos/eliza/issues). Best for: bugs you encounter using Eliza, and fea...

(RP_COLON)

🪛 Markdownlint (0.37.0)
README.md

82-82: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


143-143: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


163-163: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

🔇 Additional comments (5)
packages/plugin-solana/src/index.ts (1)

7-14: Verify Exported Modules Integration

Ensure that all imported modules (transferToken, transferSol, providers, and evaluators) are correctly exported and registered within solanaPlugin.

packages/plugin-solana/src/actions/transfer.ts (1)

68-68: Simile Consistency for Action Names

Consider adding similes like "GIVE_TOKEN" or "SEND_ASSET" to cover a broader range of user commands.

packages/client-twitter/src/interactions.ts (2)

315-317: LGTM! Enhanced self-tweet handling logic.

The modified condition now correctly processes self-tweets when directed at target users, improving the interaction capabilities.


433-451: LGTM! Improved state composition.

The changes enhance context generation by:

  1. Converting arrays to strings consistently
  2. Including character examples for better response generation
characters/sbf.character.json (1)

31-75: LGTM! Well-structured message examples.

The message examples effectively demonstrate both SOL and token transfer actions with clear user interactions.

characters/sbf.character.json Show resolved Hide resolved
packages/plugin-solana/README.MD Show resolved Hide resolved
wtfsayo
wtfsayo previously approved these changes Jan 18, 2025
@wtfsayo wtfsayo enabled auto-merge (squash) January 18, 2025 08:15
@wtfsayo wtfsayo self-requested a review January 18, 2025 08:19
.gitignore Outdated Show resolved Hide resolved
@wtfsayo
Copy link
Member

wtfsayo commented Jan 18, 2025

resolve conflicts/rebase and good to go

auto-merge was automatically disabled January 18, 2025 09:14

Head branch was pushed to by a user without write access

@sunsakis sunsakis requested review from wtfsayo and odilitime January 18, 2025 09:44
@wtfsayo wtfsayo enabled auto-merge (squash) January 18, 2025 12:04
@wtfsayo wtfsayo merged commit 2d7ea52 into elizaOS:develop Jan 18, 2025
4 of 5 checks passed
@sunsakis sunsakis deleted the solana-plugin branch January 18, 2025 14:31
mgunnin added a commit to mgunnin/kairos that referenced this pull request Jan 18, 2025
…o develop

* 'develop' of https://github.com/mgunnin/virtualDegen: (41 commits)
  Update README.md (elizaOS#2495)
  Update README_CN.md (elizaOS#2489)
  Update README_JA.md (elizaOS#2490)
  feat: introduce Dependency Injection to enhance developer experience (elizaOS#2115)
  chore: corrected the link to the banner (elizaOS#2491)
  chore: update createToken.ts (elizaOS#2493)
  feat: Solana plugin improvement for flawless transfers (elizaOS#2340)
  Update README_DE.md (elizaOS#2483)
  feat: Sui supports the secp256k1/secp256r1 algorithms (elizaOS#2476)
  chore: remove eslint, prettier, tslint and replace with biome (elizaOS#2439)
  chore: let -> const
  fix: lint command
  fix: unused import and type errors
  chore: console -> elizaLogger
  fix: error logging and remove unused import
  fix: remove unused error var
  chore: pnpm lock file
  add openai var
  Revert "Revert "refactor: dockerize smoke tests (elizaOS#2420)" (elizaOS#2459)"
  fix swaps evm plugin (elizaOS#2332)
  ...
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.

3 participants