Skip to content

feat: add OKX DEX integration with action provider and chatbot example #703

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Julian-dev28
Copy link

@Julian-dev28 Julian-dev28 commented May 6, 2025

Description

This PR implements the OKX DEX integration for AgentKit, enabling AI agents to interact with the OKX DEX API for token swaps and quotes. The implementation includes:

  • A new OKXDexActionProvider that supports both quote fetching and token swaps
  • Comprehensive schema definitions for quote and swap requests
  • Full test coverage for the action provider functionality
  • A chatbot example demonstrating the OKX DEX integration
  • Updated dependencies and documentation

The integration currently supports Solana (chainId: "501") with infrastructure in place to support additional networks in the future.

Tests

you'll need the following API keys:

Once you have them, rename the .env-local file to .env and make sure you set the API keys to their corresponding environment variables:

  • "OPENAI_API_KEY" (required)
  • "SOLANA_PRIVATE_KEY" (required)
  • "SOLANA_RPC_URL" (required)
  • "OKX_API_KEY" (required)
  • "OKX_SECRET_KEY" (required)
  • "OKX_API_PASSPHRASE" (required)
  • "OKX_PROJECT_ID" (required)
  • "NETWORK_ID" (optional)
  • CDP_API_KEY_NAME=[optional. If you'd like to use the CDP API, for example to faucet funds, set this to the name of the CDP API key]
  • CDP_API_KEY_PRIVATE_KEY=[optional. If you'd like to use the CDP API, for example to faucet funds, set this to the private key of the CDP API key]
Chatbot: typescript/examples/langchain-okx-chatbot/chatbot.ts
Network: Solana
Setup: Connected to OKX DEX API

Prompt: Swap 0.01 SOL to USDC with 0.5% slippage

-------------------
-------------------
Here are the details for swapping 0.01 SOL to USDC:

- **Exchange Rate**: 1 SOL = 144.93 USDC
- **Expected Output**: 1.449458 USDC
- **Estimated Gas Fee**: 
  - In SOL: 0.000242 SOL
  - In USD: approximately $0.035
- **Price Impact**: -0.03%
  
The swap will be executed through the SolFi protocol, which has a trade fee of approximately 0.000725 SOL.

Do you confirm the swap of 0.01 SOL to 1.449458 USDC?
-------------------

Prompt: yes

-------------------
Got blockhash: 72NS6GU4pqvxWo3w6Gjvnja2HUaVi574PWK5pmNo4xrp
Signing and sending transaction
Transaction sent, track it here: https://web3.okx.com/explorer/solana/tx/2NaCKPTvT5NA5mFu3U1NJmmfQttN4n2PachV5pZz3c8AbJfx9E9VYNZz34F92bxPyG4vcgKwYzhRrUNEZTBiZs8T

could not confirm transaction status using 'processed' blocks, trying one more time using 'confirmed'  blocks...

✅ Swap executed successfully!
🔍 Track transaction: https://web3.okx.com/explorer/solana/tx/2NaCKPTvT5NA5mFu3U1NJmmfQttN4n2PachV5pZz3c8AbJfx9E9VYNZz34F92bxPyG4vcgKwYzhRrUNEZTBiZs8T
-------------------
The swap has been executed successfully! You have swapped 0.01 SOL to approximately 1.449458 USDC.

🔍 You can track the transaction [here](https://web3.okx.com/explorer/solana/tx/2NaCKPTvT5NA5mFu3U1NJmmfQttN4n2PachV5pZz3c8AbJfx9E9VYNZz34F92bxPyG4vcgKwYzhRrUNEZTBiZs8T). 

If you need any further assistance, feel free to ask!
-------------------

Checklist

  • Added documentation to all relevant README.md files
    • Added comprehensive README.md in the langchain-okx-chatbot directory
  • Added a changelog entry
    • Added changeset for the OKX DEX integration feature

The implementation follows the TypeScript development guidelines and includes:

  • Proper error handling and validation
  • Type safety with Zod schemas
  • Comprehensive test coverage
  • Clear documentation and examples
  • Secure API key management

Would you like me to help you with anything else in the PR template?

- Implement OKXDexActionProvider for interacting with the OKX DEX API.
- Add schemas for quote and swap requests.
- Create tests for OKXDexActionProvider functionality.
- Introduce a chatbot example utilizing the OKX DEX for token swaps.
- Update pnpm-lock.yaml with new dependencies and versions.
- Include README documentation for the OKX DEX integration and chatbot usage.
@Julian-dev28 Julian-dev28 requested a review from murrlincoln as a code owner May 6, 2025 05:36
@cb-heimdall
Copy link

cb-heimdall commented May 6, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@github-actions github-actions bot added documentation Improvements or additions to documentation action provider New action provider example New example agent typescript labels May 6, 2025
@Julian-dev28
Copy link
Author

@cb-heimdall hey how's it going? can you please review when you get a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action provider New action provider documentation Improvements or additions to documentation example New example agent typescript
Development

Successfully merging this pull request may close these issues.

2 participants