-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Compound Finance Python Actions
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.
- Loading branch information
Showing
23 changed files
with
2,227 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
python/coinbase-agentkit/coinbase_agentkit/action_providers/compound/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<p align="center"> | ||
<img src="comp.svg" width="200" height="200"> | ||
</p> | ||
|
||
<h1 align="center">Compound Finance Actions for AI Agents to Lend and Borrow on Base</h1> | ||
|
||
|
||
These actions allow you to supply, borrow, repay, withdraw ETH or USDC to Compound V3 markets through the Base USDC Comet Contract. | ||
|
||
> 🧪 **Try it on Base Sepolia First!** | ||
> These actions work seamlessly on Base Sepolia testnet, allowing you to develop and test your agent's Compound interactions without using real funds. Once you're confident in your implementation, you can switch to Base mainnet for production use. | ||
|
||
## Example Usage | ||
### Supply WETH as Collateral to Compound | ||
``` | ||
Prompt: 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! | ||
------------------- | ||
``` | ||
|
||
### Borrow 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 Your 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! | ||
------------------- | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
## Actions | ||
The actions in this package are intended to support agents that want to interact with Compound V3 markets on Base. It supports the following actions: | ||
|
||
- `supply`: Supply ETH or USDC to Compound V3 markets on Base. | ||
- `borrow`: Borrow ETH or USDC from Compound V3 markets on Base. | ||
- `repay`: Repay ETH or USDC to Compound V3 markets on Base. | ||
- `withdraw`: Withdraw ETH or USDC from Compound V3 markets on Base. | ||
- `get_portfolio_details`: Get the portfolio details for the Compound V3 markets on Base. | ||
|
||
## Supported Compound Markets (aka. Comets) | ||
|
||
### Base | ||
- USDC Comet | ||
- Supply Assets: USDC, WETH, cbBTC, cbETH, wstETH | ||
- Borrow Asset: USDC | ||
|
||
### Base Sepolia | ||
- USDC Comet | ||
- Supply Assets: USDC, WETH | ||
- Borrow Asset: USDC | ||
|
||
## Limitations and Assumptions | ||
- Only supports one Comet contract, the Base/Base Sepolia USDC Comet | ||
- The only borrowable asset is USDC as a result of the above. | ||
- Native ETH is not supported, supply must be done with Wrapped ETH (WETH). | ||
- The `approve` transaction needed for `supply` and `repay` is included in the action. | ||
- The amounts sent to these actions are _whole units_ of the asset (e.g., 0.01 ETH, 100 USDC). | ||
- Token symbols are the `asset_id` (lowercase) rather than the symbol. There's currently no way to get the symbol from the cdp `Asset` model object. | ||
|
||
## Funded by Compound Grants Program | ||
Compound Actions for AgentKit is funded by the Compound Grants Program. Learn more about the Grant on Questbook [here](https://new.questbook.app/dashboard/?role=builder&chainId=10&proposalId=678c218180bdbe26619c3ae8&grantId=66f29bb58868f5130abc054d). For support, please reach out the original author of this action provider: [@mikeghen](https://x.com/mikeghen). |
5 changes: 5 additions & 0 deletions
5
python/coinbase-agentkit/coinbase_agentkit/action_providers/compound/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Compound action provider package.""" | ||
|
||
from .compound_action_provider import CompoundActionProvider, compound_action_provider | ||
|
||
__all__ = ["CompoundActionProvider", "compound_action_provider"] |
16 changes: 16 additions & 0 deletions
16
python/coinbase-agentkit/coinbase_agentkit/action_providers/compound/comp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.