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: Added Compound Finance Python Actions #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikeghen
Copy link

@mikeghen mikeghen commented Feb 3, 2025

What changed? Why?

Adds Compound Finance actions get portfolio details, supply, borrow, repay, and withdraw. Includes unit and integration (with CDP) tests for the actions. Utility functions are added to make getting borrow, supply, and health details easily accessible.

Qualified Impact

Wrap and Unwrap ETH Action Changes
  • Added an unwrap_eth action.
  • Moved wrap/unwrap_eth actions into actions/weth directory, created a constants file for weth.
  • Changed how amounts are input to the wrap ETH action, it uses whole amounts like 0.0001 ETH.
Integration Test
  • Introduces a CDP integration test, test_compound_integration.py, that executes all the actions against Base Sepolia network to verify they work.
  • Adds integration pytest marker and adds-m "not integration" marker flag on unit tests run in the Makefile and in the .github/workflows.
  • No integration workflow is added to the Github Actions, this would require configuring the coinbase/agentkit repo with secrets, like the CDP API name and key.
  • Adds make test-integration to test integration tests using the -m "integration" flag.
% make test-integration
poetry run pytest -m "integration"
============================== test session starts ==============================
platform darwin -- Python 3.11.10, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/mghen/Documents/Projects/agentkit/python/cdp-agentkit-core
configfile: pyproject.toml
plugins: cov-6.0.0, anyio-4.8.0, langsmith-0.3.1
collected 137 items / 136 deselected / 1 selected                               

tests/actions/compound/integration/test_compound_integration.py .         [100%]

====================== 1 passed, 136 deselected in 47.25s =======================
  • The addition on this integration test should not disrupt existing unit tests or the unit test CI action
  • When running the unit tests, it now shows the integration test as deselected
$ make test
poetry run pytest -m "not integration"
=============================== test session starts ===============================
...
...
======================== 136 passed, 1 deselected in 0.53s ========================

@cb-heimdall
Copy link

cb-heimdall commented Feb 3, 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 1
Sum 2

@mikeghen mikeghen force-pushed the compound-supply branch 3 times, most recently from b691818 to 80aadcb Compare February 3, 2025 21:45
@mikeghen
Copy link
Author

mikeghen commented Feb 3, 2025

Sample Conversation with Prototyped ReAct Agent. You can find the example code for this on a separate branch in my fork: https://github.com/mikeghen/agentkit/tree/compound-chatbot/python/examples/compound-finance-chatbot

Wraps ETH to WETH

Prompt: Use the default wallet to wrap 0.0001 ETH to WETH, then show me my WETH balance for the default wallet address.
-------------------
Wrapped 0.0001 ETH with transaction hash: 0x6bf7c912653faa3003dfeff76c0ca3b090507f5437b4d0f5447f22722f7a0ca2
-------------------
I have successfully wrapped **0.0001 ETH** to WETH. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x6bf7c912653faa3003dfeff76c0ca3b090507f5437b4d0f5447f22722f7a0ca2).
-------------------

Supplies WETH to Compound

Prompt: Next, supply the 0.0001 WETH to compound finance.  
-------------------
Supplied 0.0001 WETH to Compound V3.
Transaction hash: 0xbe800f1eb3c7e4d7067addb016a7d78c341f879d9aee22c12be02f4cea5d13ef
Transaction link: https://sepolia.basescan.org/tx/0xbe800f1eb3c7e4d7067addb016a7d78c341f879d9aee22c12be02f4cea5d13ef
-------------------
I have successfully supplied **0.0001 WETH** to Compound Finance. You can view the transaction details [here](https://sepolia.basescan.org/tx/0xbe800f1eb3c7e4d7067addb016a7d78c341f879d9aee22c12be02f4cea5d13ef). 

If you have any more requests or questions, just let me know!
-------------------

Borrows USDC from Compound

Prompt: Next, borrow 0.01 USDC from compound
-------------------
Borrowed 0.01 USDC from Compound V3.
Transaction hash: 0x1d2c8e7f18d8dd9fa5410f4e6444751fa95b6c4ccfa4a4d4be1c594dba0ca215
Transaction link: https://sepolia.basescan.org/tx/0x1d2c8e7f18d8dd9fa5410f4e6444751fa95b6c4ccfa4a4d4be1c594dba0ca215
-------------------
I have successfully borrowed **0.01 USDC** from Compound. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x1d2c8e7f18d8dd9fa5410f4e6444751fa95b6c4ccfa4a4d4be1c594dba0ca215).

If you have any further requests or questions, feel free to ask!
-------------------

Gets Its Compound Portfolio Details

Prompt: What is my health ratio on Compound?
-------------------
# Portfolio Details

## Supply Details

### WETH
- **Supply Amount:** 0.000100000000000000
- **Price:** $3477.28
- **Collateral Factor:** 0.78
- **Asset Value:** $0.35

### Total Supply Value: $0.35

## Borrow Details

### 0x036CbD53842c5426634e7929541eC2318f3dCF7e
- **Borrow Amount:** 0.010000
- **Price:** $1.00
- **Borrow Value:** $0.01

## Overall Health

- **Health Ratio:** 26.95

-------------------
Your health ratio on Compound is **26.95**. 

If you need any further assistance or have more questions, feel free to ask!
-------------------

Repays USDC to Compound

Prompt: Repay 0.01 USDC to Compound
-------------------
Repaid 0.01 USDC to Compound V3.
Transaction hash: 0x0de530f9b7dd0045b9581e0768547f538407b9e01312e44aee904a8215833b4f
Transaction link: https://sepolia.basescan.org/tx/0x0de530f9b7dd0045b9581e0768547f538407b9e01312e44aee904a8215833b4f
-------------------
I have successfully repaid **0.01 USDC** to Compound. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x0de530f9b7dd0045b9581e0768547f538407b9e01312e44aee904a8215833b4f).

If you have any more requests or questions, just let me know!
-------------------

Withdraws USDC from Compound

Prompt: Withdraw half of the WETH we have in Compound
-------------------
Withdrew 0.00005 WETH from Compound V3.
Transaction hash: 0x1d55b5d75468877cfe96d2ccf878fb264744fb76af0e754fc4fea6aed8cf8977
Transaction link: https://sepolia.basescan.org/tx/0x1d55b5d75468877cfe96d2ccf878fb264744fb76af0e754fc4fea6aed8cf8977
-------------------
I have successfully withdrawn **0.00005 WETH** from Compound. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x1d55b5d75468877cfe96d2ccf878fb264744fb76af0e754fc4fea6aed8cf8977).

If you have any more requests or questions, feel free to ask!
-------------------

Unwraps WETH to ETH

Prompt: Unwrap 0.0001 WETH to ETH
-------------------
Unwrapped 0.0001 WETH with transaction hash: 0x48ec8a391bf9ddd91829b1ba3467944865cefdeafc51548b2c0d4df30d29f135
-------------------
I have successfully unwrapped **0.0001 WETH** to ETH. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x48ec8a391bf9ddd91829b1ba3467944865cefdeafc51548b2c0d4df30d29f135).

If you have any more requests or questions, feel free to ask!
-------------------

@John-peterson-coinbase
Copy link
Contributor

@mikeghen PR generally LGTM! - Please fix breaking tests and we can merge. It looks like the integration test initialization is running in the GHA which is incorrect.

@mikeghen mikeghen force-pushed the compound-supply branch 5 times, most recently from 2e3c2b0 to 8bf5115 Compare February 7, 2025 17:23
Adds Compound Finance actions get portfolio details, supply, borrow, repay, and withdraw. Includes unit and integration (with CDP) tests for the actions. Utility functions are added to make getting borrow, supply, and health details easily accessible.
@mikeghen
Copy link
Author

mikeghen commented Feb 7, 2025

Thanks for your review, @John-peterson-coinbase! I just made the change to fix the unit test failure, and this time I tested the actions on my fork on Github so verify they worked first. Let me know if you'd like to see anymore changes.

@John-peterson-coinbase John-peterson-coinbase added action New action implemented on existing action provider triaged needs review PR / issue needs review banana labels Feb 10, 2025
@0xRAG 0xRAG removed the triaged label Feb 10, 2025
@0xRAG
Copy link
Contributor

0xRAG commented Feb 11, 2025

Hey @mikeghen, thank you for your patience here. This PR looks amazing! We're releasing Python 0.1.0 very soon (targeting end of day today) which includes a new pattern for writing actions. Once that lands, let's rebase this PR and update the actions to the new pattern. Here's an example showcasing how we migrated the wrap_eth action: https://github.com/coinbase/agentkit/pull/341/files#diff-8d95d17e60a40d36d3d08cef2a7c95d1fa1a376c620356e620b436ceac480a30. I'll keep you posted with the release and will be available to help with the migration to land this PR ASAP after release.

@0xRAG 0xRAG added blocked and removed needs review PR / issue needs review labels Feb 11, 2025
@0xRAG
Copy link
Contributor

0xRAG commented Feb 11, 2025

BTW @mikeghen great work on the integration test. I think it's reasonable to add a GitHub action with secrets configured in the repo settings. For this, we will need to update the test to accept either a JSON file, or API key name & secret which we can safely store in the repo settings. If you add the action and update the test, I can add the keys. If ok, let's use:

  • INTEGRATION_CDP_API_KEY_NAME
  • INTEGRATION_CDP_API_KEY_PRIVATE_KEY

@mikeghen
Copy link
Author

Thanks @0xRAG and @John-peterson-coinbase for your attention on this PR!

Yes, I can revise my actions to use that new action provider pattern in v0.1.0. And, I can add the action as well for make test-integration using INTEGRATION_CDP_API_KEY_NAME
and INTEGRATION_CDP_API_KEY_PRIVATE_KEY.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action New action implemented on existing action provider banana blocked
Development

Successfully merging this pull request may close these issues.

4 participants