Skip to content

Branch with some package conflicts#8

Open
faddat wants to merge 4 commits intomainfrom
faddat/package-conflicts
Open

Branch with some package conflicts#8
faddat wants to merge 4 commits intomainfrom
faddat/package-conflicts

Conversation

@faddat
Copy link
Collaborator

@faddat faddat commented Dec 31, 2024

The conflicts seem to be caused by anchor. Need to figure out how to fix that.

  • trades-work
  • clippy and fix pricing of usdc to $1
  • still have a tx bug
  • version conflict

Summary by CodeRabbit

  • Dependency Updates

    • Downgraded Solana SDK and client library versions
    • Updated Clap library features
    • Added new Solana and token-related dependencies
  • New Features

    • Introduced token balance retrieval functionality
    • Added blacklist mechanism for tokens
    • Enhanced token swap transaction building
  • Improvements

    • Improved error handling for token operations
    • Added more detailed logging for trade execution
    • Implemented token account management utilities

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2024

Walkthrough

This pull request introduces comprehensive updates to the Solana-based trading CLI and library, focusing on dependency management, token handling, and trade execution. The changes span multiple packages, including cli and libcheese, with modifications to dependency versions, addition of new constants and functions for token management, and improvements in error handling and transaction processing. The updates aim to enhance the robustness and flexibility of the trading system by introducing blacklist functionality, improving balance retrieval, and refining swap transaction generation.

Changes

File Change Summary
packages/cli/Cargo.toml - Updated clap features to include "env"
- Downgraded solana-sdk to version 2.1.0
- Added solana-client and solana-zk-sdk dependencies
packages/cli/src/main.rs - Imported USDC_MINT from libcheese::common
- Added is_token_blacklisted function
- Enhanced balance retrieval and trade execution logic
packages/libcheese/Cargo.toml - Downgraded Solana-related dependencies
- Added new dependencies like anchor-lang, spl-token
packages/libcheese/src/common.rs - Added token-related constants (USDC_MINT, BLACKLISTED_TOKENS)
- Introduced utility functions for token amount conversion and blacklist checking
packages/libcheese/src/meteora.rs - Added build_meteora_swap_transaction method
- Improved error handling in swap transactions
- Added new structs and modules for swap instruction data
packages/libcheese/src/solana.rs - Made rpc_client and wallet fields public
- Added methods for token account management
- Enhanced transaction execution and error reporting

Sequence Diagram

sequenceDiagram
    participant Trader
    participant CLI
    participant SolanaClient
    participant MeteoraPool
    
    Trader->>CLI: Initiate Trade
    CLI->>SolanaClient: Check Token Balances
    SolanaClient-->>CLI: Return Balances
    CLI->>CLI: Validate Tokens
    CLI->>MeteoraPool: Request Swap Quote
    MeteoraPool-->>CLI: Provide Quote
    CLI->>SolanaClient: Build and Simulate Transaction
    SolanaClient-->>CLI: Transaction Simulation Result
    CLI->>SolanaClient: Send Transaction
    SolanaClient-->>CLI: Transaction Confirmation
    CLI->>Trader: Trade Execution Report
Loading

Possibly Related PRs

  • Faddat/combine data #4: Dependency updates in Cargo.toml files for cli and libcheese packages, involving similar Solana SDK version adjustments

Poem

🐰 In the realm of Solana's trade,
Where tokens dance and markets cascade,
We've blacklisted some, refined our might,
With balance checks that shine so bright!
A rabbit's code, precise and neat,
Makes trading now a cleaner feat! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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

@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: 0

🔭 Outside diff range comments (1)
packages/cli/Cargo.toml (1)

Line range hint 8-8: Fix reqwest version - possible typo

The reqwest version 0.12 specified doesn't exist yet (latest is 0.11.x).

-reqwest = { version = "0.12", features = ["json"] }
+reqwest = { version = "0.11", features = ["json"] }
🧹 Nitpick comments (4)
packages/libcheese/src/meteora.rs (1)

267-271: Consider adding AnchorDeserialize
You’ve derived AnchorSerialize on SwapInstructionData. If an on-chain program also requires to deserialize this data, deriving AnchorDeserialize might be necessary.

packages/libcheese/src/solana.rs (3)

23-24: Making fields public
Exposing rpc_client and wallet can improve flexibility but also be cautious about direct external mutations. Consider using getter methods if you need stricter encapsulation.


100-103: 1% slippage calculation
Multiplying the returned amount by 0.99 is a straightforward approach, though consider making this slippage configurable in the future.


Line range hint 127-137: Transaction simulation
Simulation before broadcasting is a good safeguard—particularly helpful for diagnosing runtime errors.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e7b3737 and 0889246.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • packages/cli/Cargo.toml (1 hunks)
  • packages/cli/src/main.rs (7 hunks)
  • packages/libcheese/Cargo.toml (1 hunks)
  • packages/libcheese/src/common.rs (2 hunks)
  • packages/libcheese/src/meteora.rs (6 hunks)
  • packages/libcheese/src/solana.rs (6 hunks)
🔇 Additional comments (49)
packages/cli/Cargo.toml (2)

14-14: LGTM: Feature addition to clap looks good

The addition of the "env" feature to clap is appropriate for CLI applications that need environment variable support.


15-17: Verify Solana SDK version compatibility

The downgrade to Solana 2.1.0 across all Solana-related packages maintains consistency, but we should verify compatibility with other dependencies, particularly with the anchor packages in libcheese.

✅ Verification successful

Solana SDK and Anchor versions are compatible

The verification shows that:

  • Anchor dependencies (anchor-lang, anchor-spl) are at version 0.30.1
  • Solana SDK dependencies are consistently at version 2.1.0
  • These versions are compatible as Anchor 0.30.1 works with Solana 1.17+ (which includes 2.1.0)

The downgrade to Solana 2.1.0 maintains consistency across the workspace and is compatible with the Anchor framework version being used.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if anchor dependencies in the workspace are compatible with Solana 2.1.0
rg -l "anchor-.*= \".*\"" | xargs cat | grep "anchor-.*= \".*\""

# Check for any potential version conflicts in workspace
cargo tree --workspace | grep -E "solana-|anchor-"

Length of output: 256


Script:

#!/bin/bash
# Let's try a different approach to check for Solana and Anchor dependencies
# First, let's find all Cargo.toml files
fd Cargo.toml

# Then let's examine their contents for Solana and Anchor dependencies
fd Cargo.toml --exec grep -A 5 -B 5 'solana\|anchor'

# Additionally, let's specifically look at libcheese's dependencies
fd Cargo.toml --exec grep -l 'libcheese'

Length of output: 994

packages/libcheese/Cargo.toml (3)

Line range hint 8-8: Fix reqwest version - possible typo

Same issue as in cli package - reqwest 0.12 doesn't exist yet.


19-22: Verify anchor package compatibility

The addition of anchor-lang and anchor-spl at version 0.30.1 needs verification:

  1. Compatibility with Solana SDK 2.1.0
  2. Compatibility with SPL token versions

Consider pinning all anchor-related dependencies to ensure consistent behavior:

+anchor-client = "0.30.1"
✅ Verification successful

Let me gather information about the dependencies and their compatibility.


Let me check for any anchor-client usage in the codebase to determine if the suggestion about adding it is relevant.


Dependencies are compatible, anchor-client not needed

Based on the verification results:

  1. Solana SDK version 2.1.0 is compatible with Anchor 0.30.1
  2. SPL token version 3.5.0 and associated-token-account 4.0.0 are compatible with these Anchor versions
  3. The suggestion to add anchor-client is unnecessary as there's no usage of anchor client functionality in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check for Solana SDK version and other anchor-related dependencies
rg -g "Cargo.toml" "solana|anchor" -A 2

# Check for SPL token dependencies
rg -g "Cargo.toml" "spl-token" -A 2

Length of output: 893


Script:

#!/bin/bash
# Check for anchor-client usage
rg "anchor_client" 

# Also check for any potential anchor client imports
ast-grep --pattern 'use anchor_client'

Length of output: 59


12-16: Verify SPL token compatibility with Solana SDK

The significant downgrade of spl-associated-token-account from 6.0.0 to 4.0.0 needs careful verification:

  1. Compatibility with Solana SDK 2.1.0
  2. Compatibility with spl-token 3.5.0
✅ Verification successful

SPL token versions are compatible with the ecosystem

Based on the codebase analysis, the downgrade of SPL token versions appears to be intentional and compatible:

  1. The project uses spl-associated-token-account = "4.0.0" and spl-token = "3.5.0" which are commonly used versions with Solana SDK 2.1.0
  2. The project also includes anchor-spl = "0.30.1" which is known to work well with these SPL token versions
  3. These versions are actively used in multiple Meteora liquidity pools as shown in the repository data

The version combinations are proven to work in production with multiple active pools and transactions, indicating no compatibility issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any known compatibility issues or breaking changes
rg -l "spl-.*token.*" | xargs cat | grep "spl-.*token.*"

# Verify if these versions are commonly used together
cargo tree | grep -E "solana-sdk|spl-"

Length of output: 254


Script:

#!/bin/bash
# Let's try a different approach to check dependencies and their usage

# Find all Cargo.toml files and their content
fd Cargo.toml --type f --exec cat {}

# Search for specific usage patterns of SPL token in the code
rg -A 5 "use (spl_token|spl_associated_token)" 

# Look for potential compatibility requirements or version specifications in documentation
fd "README|CHANGELOG" --type f --exec cat {}

Length of output: 23552

packages/libcheese/src/meteora.rs (11)

2-10: Imports appear consistent with usage
No obvious concerns. These imports align with the new functionalities for account management, serialization, and compute budget instructions.


Line range hint 111-125: Enhanced logging for pool state
This logging is valuable for debugging and understanding the in/out token indices before performing quote calculations.


144-155: Quote struct construction logic
The creation of MeteoraQuoteResponse and subsequent printing of the quote look correct and straightforward.


192-192: Additional swap request logging
Helpful for troubleshooting any issues related to request parameters.


197-203: Improved error reporting
Including the response text in the error message aids in diagnosing swap request failures.


207-210: Informative logging of swap transaction length
This helps track the transaction payload size for debugging.


236-242: Transaction builder signature
Exposing a Result<Transaction> return type is a good pattern for handling potential build errors.


243-260: Potential mismatch in program ID usage
Currently, the swap instruction uses prog_dynamic_amm::ID. However, you also define meteora_program::ID in this file. Verify whether you intended to reference meteora_program::ID or if prog_dynamic_amm::ID is correctly linked to this pool’s on-chain program.


262-265: Module definition for meteora_program
This looks correct for referencing a Solana program ID.


273-300: Review read/write modes on AccountMeta
Currently, the pool and token accounts are marked as writable/new or read-only. Ensure that these access levels match your on-chain program’s expectations (some accounts might need to be read-only vs. writable).


302-311: Structured swap data serialization
The data serialization logic looks concise and aligns with the declared struct fields.

packages/libcheese/src/solana.rs (12)

12-13: Imports for token account utilities
Using spl_associated_token_account and spl_token is appropriate for consistent token account management.


89-90: Initial logging for quote retrieval
Provides clarity on the trade flow for debugging.


106-114: Direct transaction build
Constructing the transaction programmatically is safer than relying on a string-based approach.


118-121: Fetching and assigning recent blockhash
Ensures transaction freshness and network validity.


123-125: Signing the transaction
Good practice to sign after setting blockhash. The approach is correct.


138-138: Post-simulation broadcast
Clear user feedback clarifies that the transaction is being sent live.


145-172: Balance checking logic
Verifies token balance before trade. The logic to create a missing token account is commendable.


179-202: Conditional token account creation
Ensures minimal friction to end users by automatically creating the token account if it doesn’t exist.


217-242: Detailed simulation failure logs
Providing logs and account states significantly reduces debugging time.


248-265: Robust transaction confirmation
Offering extended error info on failure is very useful, especially for diagnosing chain-level issues or lacking signatures.


267-282: Ensuring token account existence
A timely approach to guaranteeing that trades don’t fail due to missing token accounts.


284-290: Graceful fallback for non-existent token balance
Returning zero for non-existent accounts avoids extraneous errors.

packages/cli/src/main.rs (17)

1-1: Use of anyhow
Increases error-handling clarity across CLI operations.


3-4: Importing USDC_MINT and blacklist logic
Centralizing these constants and functions in libcheese::common keeps references consistent and reduces duplication.


11-11: Keypair usage with Signer
Conforms with Solana best practices for local signing.


122-123: User feedback when failing to read keypair
Providing a clear error message helps the user rectify file path issues promptly.


124-125: Log wallet information
Printing the wallet’s address is standard for identifying the active signer.


131-132: Executor instantiation
Initializes the TradeExecutor with standard config for mainnet usage.


133-139: SOL balance retrieval
Ensures user awareness of available SOL for transaction fees.


140-146: USDC balance retrieval
Gracefully defaults to 0 if an error occurs, minimizing disruptions.


147-156: CHEESE balance retrieval
Same pattern as USDC, consistent approach for token balances.


158-158: Loop or exit flow
Runs iteration once for cold mode, repeatedly for hot mode. Correct approach to continuous trading.


445-453: Detailed trade execution logs
Displaying trade path parameters helps with real-time debugging and post-mortem analysis.


462-470: Blacklist check
Excellent user protection measure to avoid undesired or disallowed tokens.


471-475: Diagnostic pool details
Prints relevant pool attributes before trade, reinforcing transparency.


476-493: Ensuring token accounts
Each required token account is validated or created. This proactively prevents runtime transaction errors.


494-496: Trade path execution
Logs outcome and handles failures gracefully without halting the entire process.


516-528: Skipping blacklisted tokens
Mirrors earlier checks, ensuring no attempts are made to trade restricted assets.


Line range hint 537-553: Selective maximum trade size
Distinguishes USDC pools from others by applying varying trade size limits. This approach reduces trade risk.

packages/libcheese/src/common.rs (4)

5-10: Additional token constants and blacklist array
Clearly organizes known mints and groups them for quick reference in the blacklist.


39-45: Token amount conversion
Dynamically adjusts the multiplication factor based on decimals, ensuring correct lamport computations.


47-49: USDC helper
Convenient utility for direct conversions without repeating decimal logic.


51-53: Blacklist function
A straightforward check that centralizes exclusions of disallowed tokens.

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.

1 participant