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: main
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.

@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 0
Sum 1

@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 6 times, most recently from 8bf5115 to 67c2c05 Compare February 7, 2025 17:24
@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.

@0xRAG
Copy link
Contributor

0xRAG commented Feb 13, 2025

Hey @mikeghen the Python 0.1.0 release is out! Please reference the docs for instructions on creating actions in the new pattern, or reference an implementation

Let me know how we can help. Looking forward to landing this soon!

@0xRAG
Copy link
Contributor

0xRAG commented Feb 13, 2025

Also @mikeghen re: creating a GitHub action to run the integration tests: let's hold off on this for now. We're going to discuss the best approach for this. Definitely appreciate the addition of the integration tests!

@mikeghen
Copy link
Author

You're welcome @0xRAG, I'm glad to hear its getting addressed upstream. Thanks for following up on this. I have mostly refactored it for 0.1.0-python so I should have something for review again soon.

@0xRAG 0xRAG added action provider New action provider python and removed action New action implemented on existing action provider blocked labels Feb 13, 2025
@0xRAG 0xRAG added the changes requested PR / Issue has changes requested label Feb 13, 2025
@mikeghen mikeghen marked this pull request as draft February 13, 2025 17:33
@mikeghen mikeghen force-pushed the compound-supply branch 9 times, most recently from baa10f9 to c055e90 Compare February 14, 2025 00:52
@mikeghen mikeghen marked this pull request as ready for review February 14, 2025 00:54
@mikeghen
Copy link
Author

@murrlincoln, @0xRAG, @John-peterson-coinbase, I was able to migrate to the new action provider design pattern and it's ready for another review. Let me know if there's anything you think I need to change.

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.
@0xRAG 0xRAG added needs review PR / issue needs review and removed changes requested PR / Issue has changes requested labels Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action provider New action provider banana needs review PR / issue needs review python
Development

Successfully merging this pull request may close these issues.

4 participants