Skip to content

Commit

Permalink
feat: Added Compound Finance Python Actions
Browse files Browse the repository at this point in the history
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
mikeghen committed Feb 13, 2025
1 parent 69c57fb commit 9e53b4b
Show file tree
Hide file tree
Showing 23 changed files with 2,227 additions and 41 deletions.
8 changes: 6 additions & 2 deletions python/coinbase-agentkit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ lint:

.PHONY: lint-fix
lint-fix:
poetry run ruff check . --fix
poetry run ruff check . --fix --unsafe-fixes

.PHONY: docs
docs:
Expand All @@ -20,4 +20,8 @@ local-docs: docs

.PHONY: test
test:
poetry run pytest
poetry run pytest -m "not integration"

.PHONY: test-integration
test-integration:
poetry run pytest -m "integration"
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).
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"]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9e53b4b

Please sign in to comment.