eliza icon indicating copy to clipboard operation
eliza copied to clipboard

feat: Replaces the current plugin with Solana Agent Kit

Open thearyanag opened this issue 1 year ago • 9 comments

Relates to:

https://github.com/elizaOS/eliza/issues/1619

Risks

Low

Background

What does this PR do?

Replace the solana plugin with solana agent kit

  • wrapper around the runtime for the kit
  • replace the trade function with trade action from the kit
  • replace the transfer function with transfer action from the kit
  • replace the swap dao function with trade action from the kit

What kind of change is this?

This PR improves the existing plugin by replacing with the Solana Agent Kit In following days, will add more actions from the agent kit.

Testing

Where should a reviewer start?

packages/plugin-solana

Reference docs https://sendaifun.github.io/solana-agent-kit/

Detailed testing steps

None, automated tests are fine.

Discord username

0xaryan

thearyanag avatar Jan 01 '25 09:01 thearyanag

Why is using the agent kit better than what we had?

odilitime avatar Jan 01 '25 10:01 odilitime

@odilitime , this PR just sets the base for adding further actions from the agent kit.

The kit can perform the following actions, we'll then integrate every action present in the kit.

Token Operations

Deploy SPL tokens by Metaplex Transfer assets Balance checks Stake SOL Zk compressed Airdrop by Light Protocol and Helius

NFT Management via Metaplex

Collection deployment NFT minting Metadata management Royalty configuration

DeFi Integration

Jupiter Exchange swaps Launch on Pump via PumpPortal Raydium pool creation (CPMM, CLMM, AMMv4) Orca Whirlpool integration Manifest market creation, and limit orders Meteora Dynamic AMM, DLMM Pool, and Alpha Vault Openbook market creation Register and Resolve SNS Jito Bundles Pyth Price feeds for fetching Asset Prices Register/resolve Alldomains

Solana Blinks

Lending by Lulo (Best APR for USDC) Send Arcade Games JupSOL staking

Non-Financial Actions

Gib Work for registering bounties

thearyanag avatar Jan 01 '25 10:01 thearyanag

it would be better to make a new plugin, allow users choice regarding which instances they wish to implement

cipher-rc5 avatar Jan 01 '25 14:01 cipher-rc5

@cipher-rc5 currently, it's just drop in replacement for the existing plugin so there wont' be any issues for backward compatibility, it's a w-w given we'll be adding all the supported action from the agent kit

thearyanag avatar Jan 01 '25 15:01 thearyanag

it would be better to make a new plugin, allow users choice regarding which instances they wish to implement

I'd be fine with actions we didn't already have, being served by the agent kit. But I don't think we should replace the existing actions that are explicit and transparent.

odilitime avatar Jan 02 '25 00:01 odilitime

Hey @odilitime - the main reason behind replacing the current actions, is to follow the best practices being followed in the industry.

For example, the transaction sending logic in the current codebase, does not implement the priority fee handling and does not even has the retry logic

The current transaction sending logic in swap

            const txid = await connection.sendTransaction(transaction, {
                skipPreflight: false,
                maxRetries: 3,
                preflightCommitment: "confirmed",
            });

The current transaction sending logic in transfer

            // Send transaction
            const signature = await connection.sendTransaction(transaction);

The send transaction logic in the kit is contributed by orca team, who know the best way to land transaction

The one with which it would get replaced by using the kit

  while (Date.now() - startTime < timeoutMs) {
    const transactionStartTime = Date.now();

    const signature = await agent.connection.sendTransaction(transaction, {
      maxRetries: 0,
      skipPreflight: false,
    });

    const statuses = await agent.connection.getSignatureStatuses([signature]);
    if (statuses.value[0]) {
      if (!statuses.value[0].err) {
        return signature;
      } else {
        throw new Error(
          `Transaction failed: ${statuses.value[0].err.toString()}`,
        );
      }
    }

    const elapsedTime = Date.now() - transactionStartTime;
    const remainingTime = Math.max(0, 1000 - elapsedTime);
    if (remainingTime > 0) {
      await new Promise((resolve) => setTimeout(resolve, remainingTime));
    }
  }

We are also adding the option to chose between the default priority fees and Jito bundles in next update, so the solana plugin would automatically get adopted to the best practices.

As all the protocol specific PR's are raised by the respective teams, so Eliza would get the best of solana world.

thearyanag avatar Jan 04 '25 17:01 thearyanag

I agree with @thearyanag here - solana-agent-kit is being actively updated with all major interactions/dapps on solana, it is maintained by the solana community and widely used in the ecosystem, adding the agent kit to Eliza would make all solana interactions to be plug and play while they are being actively maintained by the community.

cc: @odilitime @cipher-rc5

UjjwalGupta49 avatar Jan 07 '25 09:01 UjjwalGupta49

I'll throw in here as well and say I'd absolutely love to see this integration as the Solana Agent Kit has a pretty large userbase already and growing quickly. Would love to see every solana action standardized with with the kit.

pwkraken avatar Jan 07 '25 21:01 pwkraken

hey @odilitime - a friendly bump

thearyanag avatar Jan 12 '25 21:01 thearyanag

@coderabbitai review

wtfsayo avatar Jan 14 '25 12:01 wtfsayo

📝 Walkthrough

Walkthrough

The pull request introduces significant enhancements to the Solana plugin, adding new actions for token operations like lending, token information retrieval, staking, and GibWork task creation. The changes streamline transaction handling by leveraging the solana-agent-kit, simplifying wallet interactions and reducing complex transaction management. Dependencies have been updated, and new utility functions like getSAK have been implemented to improve wallet key management and integration.

Changes

File Change Summary
packages/plugin-solana/package.json - Added @coral-xyz/anchor dependency
- Added solana-agent-kit dependency
- Managed @elizaos/plugin-trustdb dependency
packages/plugin-solana/src/actions/... - New actions added: getTokenInfo.ts, gibwork.ts, lend.ts, stake.ts
- Updated swap.ts, swapDao.ts, transfer.ts to use solana-agent-kit
- Added pumpfun.ts import for SolanaAgentKit
packages/plugin-solana/src/index.ts - Imported and added new actions to solanaPlugin
packages/plugin-solana/src/utils.ts - Added getSAK utility function for wallet key management

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.

coderabbitai[bot] avatar Jan 14 '25 12:01 coderabbitai[bot]

@thearyanag can you allow us to edit the PR/branch?

wtfsayo avatar Jan 14 '25 12:01 wtfsayo

closing in favor of #2288

wtfsayo avatar Jan 14 '25 13:01 wtfsayo