Python SDK for Compound V3 (Comet)
Project description
Comet DevX Python SDK
A Python SDK for interacting with Compound V3 (Comet).
This SDK provides a simple, high-level interface for:
- Supplying collateral to Comet.
- Borrowing the base asset.
- Repaying borrowed assets.
- Querying positions and market data.
Table of Contents
Overview
The Comet SDK is designed to streamline interactions with Compound V3 (Comet). It leverages Web3.py for blockchain communication and provides clear exceptions and transaction handling.
The main class, Comet, initializes using a network identifier, a Web3 provider, and an optional account address, and it exposes methods to supply collateral, borrow assets, and repay loans.
Installation
To install the Comet Python SDK, run:
pip install comet-devx
Usage
Initializing the Comet Instance
Import the Comet class from the SDK, create a Web3 instance, and then instantiate the class.
from web3 import Web3
from comet import Comet # Adjust the import as needed
# Connect to your RPC provider (e.g., Infura)
provider = Web3.HTTPProvider("https://sepolia.infura.io/v3/YOUR_INFURA_KEY")
web3 = Web3(provider)
# Optionally, set your account (checksum address)
account = web3.toChecksumAddress("0xYourAccountAddress")
# Create a Comet instance for the 'sepolia' network
comet = Comet(network="sepolia", web3=web3, account=account)
print(comet.get_network()) # Should output: "Connected to sepolia network"
Core Methods
Supply
Supply an ERC20 asset as collateral to Comet.
from web3 import Web3
# Example: Supply 1,000 USDC (USDC has 6 decimals)
usdc_address = web3.toChecksumAddress("0xA0b86991C6218B36C1d19D4a2E9Eb0CE3606EB48")
amount = Web3.toWei(1_000, 'mwei') # or use your preferred conversion
try:
receipt = await comet.supply(asset=usdc_address, amount=amount)
print("Supply successful, receipt:", receipt)
except Exception as e:
print("Supply failed:", e)
Borrow
Borrow the base asset from Comet.
# Example: Borrow 100 USDC (assume base asset uses 6 decimals)
borrow_amount = Web3.toWei(100, 'mwei')
try:
receipt = await comet.borrow(amount=borrow_amount)
print("Borrow successful, receipt:", receipt)
except Exception as e:
print("Borrow failed:", e)
Repay
Repay the borrowed base asset.
# Example: Repay 50 USDC (using 6 decimals)
repay_amount = Web3.toWei(50, 'mwei')
try:
receipt = await comet.repay(amount=repay_amount)
print("Repay successful, receipt:", receipt)
except Exception as e:
print("Repay failed:", e)
Configuration
The SDK reads network-specific settings from a configuration module. You can customize the configuration by editing the configuration files under the config/ directory.
- NetworkConfig:
Provides settings such as the Comet contract address and oracle configurations. - ABI Files:
The SDK loads the Comet ABI from theabis/directory. Ensure this file is present and updated.
Examples
For more detailed examples, refer to the examples/ directory which includes sample scripts demonstrating:
- Setting up the environment.
- Supplying collateral.
- Borrowing and repaying assets.
- Querying market data and positions.
Development
Setting Up the Environment
-
Clone the repository.
-
Install dependencies in editable mode:
pip install -e ".[dev]"
-
Update configuration files under
config/as needed.
Running the SDK
Run your example scripts from the command line:
python examples/supply_example.py
Contributing
Contributions are welcome!
- Fork the repository.
- Create a feature branch.
- Write tests and update documentation.
- Submit a pull request with your changes.
For major changes, please open an issue first to discuss the design.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file comet_devx-0.1.1.tar.gz.
File metadata
- Download URL: comet_devx-0.1.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
297669fd657bd3d02acc1d75e8fd98b2b67c1e5d2a1c5420b6b84195b00ea84e
|
|
| MD5 |
97dafd25224e21b08eae5a69f1a9ee82
|
|
| BLAKE2b-256 |
e693dedab57ec9482bda8c785705a947ed902ab198f899b87ae6f13855b9172e
|
File details
Details for the file comet_devx-0.1.1-py3-none-any.whl.
File metadata
- Download URL: comet_devx-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5a6d0f93c8976b18a06a706d4cf1cc2077e28487d1848bbab4cefcdba3342f9
|
|
| MD5 |
4c7a8b03f5d161f4d811e0e4df53886e
|
|
| BLAKE2b-256 |
a3f58811b35942e6f3f405cdbb39b6b6c2bb4cf06bb32bb7ca50e8eb0bce3962
|