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: implement coinbase trading #608

Merged
merged 26 commits into from
Nov 28, 2024

Conversation

monilpat
Copy link
Collaborator

@monilpat monilpat commented Nov 26, 2024


Relates to:

Coinbase support


Risks

  • Risk Level: Medium
  • Potential Risks:
    • Integration issues with the Coinbase SDK could impact trading functionality.
    • Possible edge cases in wallet initialization might cause unexpected errors.
    • Dependencies updated in package.json may cause version conflicts.

Background

What does this PR do?

This PR implements the Coinbase trading functionality using the Coinbase SDK. It adds the ability to:

  • Execute trades between assets (e.g., ETH to USDC).
  • Log trades and export trade details to a CSV file.
  • Dynamically initialize wallets and handle on-chain trading operations.

What kind of change is this?

  • Feature: Non-breaking change adding new functionality.
  • Adds Coinbase trading plugin to the project, enabling automated trading.
  • Updates dependencies and introduces new helper methods for wallet initialization.

Documentation changes needed?

  • Yes: The trading functionality and wallet setup process need documentation.
    • Added a section in the README on how to configure Coinbase API keys.
  • No: N/A

Testing

Where should a reviewer start?

Begin with the following files:

  1. packages/plugin-coinbase/src/plugins/trade.ts: Contains the trading logic and integration.
  2. packages/plugin-coinbase/src/utils.ts: Handles wallet initialization.

Detailed testing steps:

  1. Wallet Initialization:

    • Use the initializeWallet function to create a new wallet with the Coinbase API keys.
    • Verify wallet details are correctly saved to the environment or character files.
  2. Execute a Trade:

    • Trigger a trade using the executeTradeAction in the tradePlugin.
    • Example: Swap 0.01 ETH for USDC on the "base" network.
  3. Verify Trade Logging:

    • Check the trades.csv file for accurate logging of the executed trade.
    • Validate fields like network, source asset, and target asset.
  4. Negative Testing:

    • Attempt a trade with an invalid network or unsupported asset.
    • Confirm appropriate error messages are displayed.

Screenshots (if applicable):

Before:

N/A (New feature).

After:

Screenshot 2024-11-28 at 7 21 20 AM

https://drive.google.com/file/d/1xeUW9sbQ74DinzFrXjqps7o2wqFWRSNv/view?usp=sharing

Successful Trade:

Trade executed successfully:
- Network: base
- Amount: 0.01
- From: ETH
- To: USDC

Error Handling:

Error: Invalid network. Supported networks are: base, sol, eth, arb, pol.

Deploy Notes:

  • Ensure Coinbase API keys are correctly configured in the environment variables before deployment.

Database Changes:

None.


Deployment Instructions:

  1. Add the following environment variables to .env:

    COINBASE_API_KEY=<your-api-key>
    COINBASE_PRIVATE_KEY=<your-private-key>
    
  2. Run pnpm install to update dependencies.

  3. Test all features in a staging environment before deploying to production.


@monilpat monilpat marked this pull request as ready for review November 28, 2024 15:30
@jkbrooks
Copy link
Contributor

@monilpat

We have conflicts

.env.example
agent/src/index.ts
docs/docs/packages/plugins.md
package.json
pnpm-lock.yaml

@monilpat
Copy link
Collaborator Author

plugins.md

Yup aware and resolving them :)

Copy link
Contributor

@snobbee snobbee left a comment

Choose a reason for hiding this comment

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

LGTM! great work!

@jkbrooks jkbrooks merged commit 13b212d into elizaOS:main Nov 28, 2024
2 checks passed
@jkbrooks jkbrooks mentioned this pull request Nov 29, 2024
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