defi-omni-cli 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- defi_omni_cli-0.2.0/LICENSE +21 -0
- defi_omni_cli-0.2.0/PKG-INFO +282 -0
- defi_omni_cli-0.2.0/README.md +256 -0
- defi_omni_cli-0.2.0/defi_autopilot/__init__.py +3 -0
- defi_omni_cli-0.2.0/defi_autopilot/audit.py +194 -0
- defi_omni_cli-0.2.0/defi_autopilot/cli.py +1114 -0
- defi_omni_cli-0.2.0/defi_autopilot/core/__init__.py +0 -0
- defi_omni_cli-0.2.0/defi_autopilot/core/chains.py +108 -0
- defi_omni_cli-0.2.0/defi_autopilot/core/rpc.py +69 -0
- defi_omni_cli-0.2.0/defi_autopilot/core/signer.py +28 -0
- defi_omni_cli-0.2.0/defi_autopilot/core/tokens.py +111 -0
- defi_omni_cli-0.2.0/defi_autopilot/core/tx.py +422 -0
- defi_omni_cli-0.2.0/defi_autopilot/doctor.py +118 -0
- defi_omni_cli-0.2.0/defi_autopilot/policy.py +334 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/__init__.py +0 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/aave/__init__.py +19 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/aave/client.py +385 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/cctp/__init__.py +47 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/cctp/client.py +443 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/cctp/client_v2.py +460 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/cctp/doctor.py +118 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/compound/__init__.py +13 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/compound/client.py +401 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/curve/__init__.py +13 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/curve/client.py +306 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/debridge/__init__.py +17 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/debridge/client.py +167 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/lido/__init__.py +15 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/lido/client.py +261 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/moonwell/__init__.py +15 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/moonwell/client.py +340 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/morpho/__init__.py +19 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/morpho/client.py +541 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/oneinch/__init__.py +15 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/oneinch/client.py +169 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/uniswap/__init__.py +17 -0
- defi_omni_cli-0.2.0/defi_autopilot/protocols/uniswap/client.py +218 -0
- defi_omni_cli-0.2.0/defi_autopilot/py.typed +0 -0
- defi_omni_cli-0.2.0/defi_autopilot/state_machine.py +315 -0
- defi_omni_cli-0.2.0/defi_omni_cli.egg-info/PKG-INFO +282 -0
- defi_omni_cli-0.2.0/defi_omni_cli.egg-info/SOURCES.txt +46 -0
- defi_omni_cli-0.2.0/defi_omni_cli.egg-info/dependency_links.txt +1 -0
- defi_omni_cli-0.2.0/defi_omni_cli.egg-info/entry_points.txt +2 -0
- defi_omni_cli-0.2.0/defi_omni_cli.egg-info/requires.txt +14 -0
- defi_omni_cli-0.2.0/defi_omni_cli.egg-info/top_level.txt +1 -0
- defi_omni_cli-0.2.0/pyproject.toml +54 -0
- defi_omni_cli-0.2.0/setup.cfg +4 -0
- defi_omni_cli-0.2.0/tests/test_doctor.py +126 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 counterfactual5
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: defi-omni-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: 多链多协议 DeFi 自动化工具集 — 供应链借贷、Swap、质押于一体
|
|
5
|
+
Author: counterfactual5
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/counterfactual5/defi-autopilot
|
|
8
|
+
Project-URL: Issues, https://github.com/counterfactual5/defi-autopilot/issues
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: web3>=6.15
|
|
13
|
+
Requires-Dist: eth-account>=0.11
|
|
14
|
+
Requires-Dist: eth-utils>=2.3
|
|
15
|
+
Requires-Dist: python-dotenv>=1.0
|
|
16
|
+
Requires-Dist: click>=8.1
|
|
17
|
+
Requires-Dist: rich>=13.0
|
|
18
|
+
Requires-Dist: httpx>=0.27
|
|
19
|
+
Requires-Dist: pydantic>=2.5
|
|
20
|
+
Requires-Dist: requests>=2.31
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# defi-autopilot
|
|
28
|
+
|
|
29
|
+
> Multi-chain, multi-protocol DeFi automation toolkit
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<img src="https://img.shields.io/badge/python-%E2%89%A53.10-blue" alt="Python">
|
|
33
|
+
<img src="https://img.shields.io/badge/License-MIT-green" alt="License">
|
|
34
|
+
<a href="https://github.com/counterfactual5/defi-autopilot/actions/workflows/test.yml"><img src="https://github.com/counterfactual5/defi-autopilot/actions/workflows/test.yml/badge.svg" alt="Tests"></a>
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
Supply, borrow, repay, collateral management, and DEX aggregation — all from one CLI. Extensible protocol architecture with Morpho Blue, Moonwell, Aave V3, and 1inch.
|
|
38
|
+
|
|
39
|
+
## Architecture
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
defi-autopilot/
|
|
43
|
+
├── defi_autopilot/
|
|
44
|
+
│ ├── core/ # Shared infrastructure
|
|
45
|
+
│ │ ├── chains.py # Multi-chain configuration
|
|
46
|
+
│ │ ├── rpc.py # Web3 instance management
|
|
47
|
+
│ │ ├── signer.py # Transaction signer
|
|
48
|
+
│ │ └── tx.py # TX build/sign/broadcast + ERC20 approval
|
|
49
|
+
│ ├── protocols/
|
|
50
|
+
│ │ ├── morpho/ # Morpho Blue (isolated lending markets)
|
|
51
|
+
│ │ ├── moonwell/ # Moonwell (Compound V2 fork)
|
|
52
|
+
│ │ ├── aave/ # Aave V3 (lending)
|
|
53
|
+
│ │ ├── uniswap/ # Uniswap V3 (DEX)
|
|
54
|
+
│ │ ├── oneinch/ # 1inch (DEX aggregator)
|
|
55
|
+
│ │ ├── lido/ # Lido (liquid staking)
|
|
56
|
+
│ │ ├── compound/ # Compound V3 (lending)
|
|
57
|
+
│ │ ├── curve/ # Curve Finance (DEX)
|
|
58
|
+
│ │ ├── cctp/ # Circle CCTP — V1 + V2 (cross-chain USDC, resumable)
|
|
59
|
+
│ │ └── debridge/ # deBridge DLN (arbitrary-token cross-chain swaps)
|
|
60
|
+
│ └── cli.py # Click CLI entry point
|
|
61
|
+
└── tests/
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Supported Protocols
|
|
65
|
+
|
|
66
|
+
| Protocol | Type | Chains | Operations |
|
|
67
|
+
|----------|------|--------|------------|
|
|
68
|
+
| **Morpho Blue** | Isolated Lending | Base, Ethereum, Arbitrum | supply, supplyCollateral, borrow, repay, withdraw, withdrawCollateral |
|
|
69
|
+
| **Moonwell** | Lending (Compound V2) | Base | supply(mint), redeem, borrow, repayBorrow |
|
|
70
|
+
| **Aave V3** | Lending | Base, Ethereum, Arbitrum, Optimism, Polygon | supply, withdraw, borrow, repay, collateral toggle |
|
|
71
|
+
| **Uniswap V3** | DEX | Base, Ethereum, Arbitrum, Optimism, Polygon, Unichain | quote, swap, price |
|
|
72
|
+
| **1inch** | DEX Aggregator | Base, Ethereum, Arbitrum, Optimism, Polygon | quote, swap |
|
|
73
|
+
| **Lido** | Liquid Staking | Ethereum, Base, Arbitrum, Optimism, Polygon | stake ETH, wrap/unwrap stETH/wstETH |
|
|
74
|
+
| **Compound V3** | Lending | Ethereum, Base, Arbitrum, Polygon | supply, withdraw, supplyCollateral, borrow, repay |
|
|
75
|
+
| **Curve** | Stablecoin DEX | Ethereum, Base, Arbitrum, Optimism | swap, add/remove liquidity, quote |
|
|
76
|
+
| **Circle CCTP** | Cross-chain USDC bridge | Ethereum, Optimism, Arbitrum, Base, Polygon, Unichain, Avalanche | transfer (burn→attest→mint), resumable; **V1** (default) + **V2** (Fast/Standard) |
|
|
77
|
+
| **deBridge DLN** | Cross-chain swap (any token) | Ethereum, Base, Arbitrum, Optimism, Polygon, Avalanche, Unichain | quote, send (cross-chain order via DLN REST API) |
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Install
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install defi-autopilot
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Or from source:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
git clone https://github.com/counterfactual5/defi-autopilot.git
|
|
91
|
+
cd defi-autopilot
|
|
92
|
+
pip install -e .
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Configure
|
|
96
|
+
|
|
97
|
+
Copy `.env.example` to `.env` and fill in your values:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cp .env.example .env
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```env
|
|
104
|
+
# RPC endpoints
|
|
105
|
+
RPC_BASE=https://mainnet.base.org
|
|
106
|
+
RPC_ETHEREUM=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
|
|
107
|
+
RPC_ARBITRUM=https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY
|
|
108
|
+
|
|
109
|
+
# Signer private key (never commit to Git)
|
|
110
|
+
SIGNER_PRIVATE_KEY=***
|
|
111
|
+
|
|
112
|
+
# Optional: 1inch API key (free tier works without it)
|
|
113
|
+
INCH_API_KEY=
|
|
114
|
+
|
|
115
|
+
# Optional: seconds to wait for a tx receipt before timing out (default 120).
|
|
116
|
+
# On timeout the tx is already broadcast; re-query the receipt later.
|
|
117
|
+
TX_RECEIPT_TIMEOUT=120
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
RPC calls automatically retry transient failures (connection errors, HTTP 429
|
|
121
|
+
rate-limits, and 5xx) up to 3 times with exponential backoff, respecting any
|
|
122
|
+
`Retry-After` header.
|
|
123
|
+
|
|
124
|
+
### Usage
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# List all available markets
|
|
128
|
+
defi markets
|
|
129
|
+
|
|
130
|
+
# --- Morpho Blue ---
|
|
131
|
+
defi morpho position --market USDC-WETH-77
|
|
132
|
+
defi morpho supply --market USDC-WETH-77 --amount 1000000000
|
|
133
|
+
defi morpho supply-collateral --market USDC-WETH-77 --amount 500000000000000000
|
|
134
|
+
defi morpho borrow --market USDC-WETH-77 --amount 500000000
|
|
135
|
+
defi morpho repay --market USDC-WETH-77 --amount 500000000
|
|
136
|
+
defi morpho withdraw --market USDC-WETH-77 --amount 1000000000
|
|
137
|
+
|
|
138
|
+
# --- Moonwell ---
|
|
139
|
+
defi moonwell supply --token USDC --amount 1000000000
|
|
140
|
+
defi moonwell borrow --token WETH --amount 500000000000000000
|
|
141
|
+
defi moonwell repay --token WETH --amount 500000000000000000
|
|
142
|
+
defi moonwell position --token USDC
|
|
143
|
+
|
|
144
|
+
# --- Aave V3 ---
|
|
145
|
+
defi aave supply --asset USDC --amount 1000000000
|
|
146
|
+
defi aave borrow --asset WETH --amount 500000000000000000
|
|
147
|
+
defi aave repay --asset WETH
|
|
148
|
+
defi aave position
|
|
149
|
+
|
|
150
|
+
# --- Uniswap V3 ---
|
|
151
|
+
defi uniswap quote --in USDC --out WETH --amount 1000000000
|
|
152
|
+
defi uniswap swap --in USDC --out WETH --amount 1000000000
|
|
153
|
+
defi uniswap price --in WETH --out USDC
|
|
154
|
+
|
|
155
|
+
# --- 1inch ---
|
|
156
|
+
defi inch quote --src USDC --dst WETH --amount 1000000000
|
|
157
|
+
defi inch swap --src USDC --dst WETH --amount 1000000000 --slippage 1.0
|
|
158
|
+
|
|
159
|
+
# --- Circle CCTP (native cross-chain USDC) ---
|
|
160
|
+
defi cctp domains # list supported chains + domain IDs
|
|
161
|
+
# Burn 10 USDC on Base (-c 8453) and mint on Arbitrum (--to 42161).
|
|
162
|
+
# Amount is in USDC base units (6 decimals): 10 USDC = 10000000
|
|
163
|
+
defi -c 8453 cctp transfer --to 42161 --amount 10000000 --run-id move-usdc-1
|
|
164
|
+
defi cctp status --run-id move-usdc-1 # inspect checkpoint
|
|
165
|
+
# Interrupted mid-flight? Re-run the SAME command — it resumes at attest/mint,
|
|
166
|
+
# never re-burning.
|
|
167
|
+
defi -c 8453 cctp transfer --to 42161 --amount 10000000 --run-id move-usdc-1
|
|
168
|
+
|
|
169
|
+
# CCTP V2 — Fast Transfer (~seconds, small fee; max fee auto-fetched from Circle)
|
|
170
|
+
defi -c 8453 cctp transfer --v2 --fast --to 42161 --amount 10000000 --run-id fast-1
|
|
171
|
+
# CCTP V2 — Standard Transfer (hard finality, usually fee-free)
|
|
172
|
+
defi -c 8453 cctp transfer --v2 --standard --to 42161 --amount 10000000 --run-id std-1
|
|
173
|
+
|
|
174
|
+
# --- Preflight doctor (no transactions sent) ---
|
|
175
|
+
defi -c 8453 doctor # RPC, chainId, signer, gas balance
|
|
176
|
+
defi -c 8453 doctor --policy --amount 1000 # also evaluate the risk policy
|
|
177
|
+
defi -c 8453 cctp doctor --to 42161 --amount 10000000 # CCTP V1 route
|
|
178
|
+
defi -c 8453 cctp doctor --v2 --fast --to 42161 --amount 10000000 # + fee quote
|
|
179
|
+
|
|
180
|
+
# --- General ---
|
|
181
|
+
defi -c 1 morpho position --market ... # specify chain
|
|
182
|
+
defi --dry-run morpho supply ... # simulate only
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## SDK Usage
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from defi_autopilot.protocols.morpho import MorphoClient, BASE_MARKETS
|
|
189
|
+
from defi_autopilot.protocols.moonwell import MoonwellClient
|
|
190
|
+
from defi_autopilot.protocols.aave import AaveV3Client, BASE_TOKENS_AAVE
|
|
191
|
+
from defi_autopilot.protocols.oneinch import OneInchClient, BASE_TOKENS_INCH
|
|
192
|
+
|
|
193
|
+
# Morpho Blue
|
|
194
|
+
morpho = MorphoClient(8453)
|
|
195
|
+
result = morpho.supply(BASE_MARKETS["USDC-WETH-77"], amount=1000000000)
|
|
196
|
+
|
|
197
|
+
# Moonwell
|
|
198
|
+
moonwell = MoonwellClient(8453)
|
|
199
|
+
result = moonwell.supply("USDC", amount=1000000000)
|
|
200
|
+
|
|
201
|
+
# Aave V3
|
|
202
|
+
aave = AaveV3Client(8453)
|
|
203
|
+
result = aave.supply(BASE_TOKENS_AAVE["USDC"], amount=1000000000)
|
|
204
|
+
health = aave.get_user_account_data("0xYourAddress")
|
|
205
|
+
|
|
206
|
+
# 1inch
|
|
207
|
+
inch = OneInchClient(8453)
|
|
208
|
+
quote = inch.get_quote(
|
|
209
|
+
BASE_TOKENS_INCH["USDC"],
|
|
210
|
+
BASE_TOKENS_INCH["WETH"],
|
|
211
|
+
amount=1000000000,
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# Circle CCTP V1 — native cross-chain USDC, resumable via state machine
|
|
215
|
+
from defi_autopilot.protocols.cctp import CCTPClient
|
|
216
|
+
|
|
217
|
+
cctp = CCTPClient(8453) # source = Base
|
|
218
|
+
result = cctp.transfer(
|
|
219
|
+
amount=10_000_000, # 10 USDC (6 decimals)
|
|
220
|
+
dest_chain_id=42161, # Arbitrum
|
|
221
|
+
run_id="move-usdc-1", # re-run with same id to resume after a crash
|
|
222
|
+
)
|
|
223
|
+
# {"status": "completed", "burn_tx": ..., "mint_tx": ...}
|
|
224
|
+
|
|
225
|
+
# Circle CCTP V2 — Fast Transfer (~seconds) or Standard (hard finality)
|
|
226
|
+
from defi_autopilot.protocols.cctp import CCTPv2Client
|
|
227
|
+
|
|
228
|
+
cctp_v2 = CCTPv2Client(8453)
|
|
229
|
+
result = cctp_v2.transfer(
|
|
230
|
+
amount=10_000_000,
|
|
231
|
+
dest_chain_id=42161,
|
|
232
|
+
fast=True, # Fast Transfer; max_fee auto-fetched from Circle
|
|
233
|
+
run_id="fast-1",
|
|
234
|
+
)
|
|
235
|
+
# {"status": "completed", "version": "v2", "burn_tx": ..., "mint_tx": ..., "max_fee": ...}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 🛠️ Development
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
git clone https://github.com/counterfactual5/defi-autopilot.git
|
|
242
|
+
cd defi-autopilot
|
|
243
|
+
uv pip install -e ".[dev]"
|
|
244
|
+
uv run pytest tests/ -v
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
167 tests covering chain config, market params, ABI validation, client initialization, token mappings, the risk-policy gate (chokepoint + ERC-20 notional), the CCTP V1/V2 transfer state machine, the CCTP preflight doctor, the top-level chain/wallet preflight doctor, the estimateGas simulation gate, RPC retry/backoff, and the configurable receipt timeout.
|
|
248
|
+
|
|
249
|
+
## 🗺️ Roadmap
|
|
250
|
+
|
|
251
|
+
- [x] Morpho Blue lending operations
|
|
252
|
+
- [x] Moonwell supply/borrow/repay
|
|
253
|
+
- [x] Aave V3 lending + health factor
|
|
254
|
+
- [x] 1inch DEX aggregation
|
|
255
|
+
- [x] Multi-chain (Base, Ethereum, Arbitrum, Optimism, Polygon)
|
|
256
|
+
- [x] Compound V3 integration
|
|
257
|
+
- [x] Circle CCTP cross-chain USDC (resumable burn & mint) — V1 + V2 (Fast/Standard)
|
|
258
|
+
- [ ] Uniswap V3/V4 LP management
|
|
259
|
+
- [ ] Strategy automation (auto-compound, yield optimization)
|
|
260
|
+
- [ ] Position monitoring & alerting
|
|
261
|
+
- [ ] WebSocket support for real-time data
|
|
262
|
+
|
|
263
|
+
## Security
|
|
264
|
+
|
|
265
|
+
- Private keys loaded from environment variables (never hardcoded)
|
|
266
|
+
- Transactions require explicit amounts (no default all-in operations)
|
|
267
|
+
- Gas estimation with 10% buffer
|
|
268
|
+
- EIP-1559 fee auto-fetch
|
|
269
|
+
|
|
270
|
+
## License
|
|
271
|
+
|
|
272
|
+
MIT
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
If this project helped you, please ⭐ star this repo — it helps others find it!
|
|
277
|
+
|
|
278
|
+
### Related Projects
|
|
279
|
+
|
|
280
|
+
- **[uniswap-autopilot](https://github.com/counterfactual5/uniswap-autopilot)** — Deep Uniswap SDK with LP management, V4 support, and 13K lines of battle-tested code. If you need advanced Uniswap features beyond basic swaps, use that.
|
|
281
|
+
- **[evm-wallet-scanner](https://github.com/counterfactual5/evm-wallet-scanner)** — Multi-chain wallet balance scanner, transaction history, and gas analytics.
|
|
282
|
+
- **[erc20-checker](https://github.com/counterfactual5/erc20-checker)** — Scan and revoke ERC20 approvals across chains.
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# defi-autopilot
|
|
2
|
+
|
|
3
|
+
> Multi-chain, multi-protocol DeFi automation toolkit
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="https://img.shields.io/badge/python-%E2%89%A53.10-blue" alt="Python">
|
|
7
|
+
<img src="https://img.shields.io/badge/License-MIT-green" alt="License">
|
|
8
|
+
<a href="https://github.com/counterfactual5/defi-autopilot/actions/workflows/test.yml"><img src="https://github.com/counterfactual5/defi-autopilot/actions/workflows/test.yml/badge.svg" alt="Tests"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
Supply, borrow, repay, collateral management, and DEX aggregation — all from one CLI. Extensible protocol architecture with Morpho Blue, Moonwell, Aave V3, and 1inch.
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
defi-autopilot/
|
|
17
|
+
├── defi_autopilot/
|
|
18
|
+
│ ├── core/ # Shared infrastructure
|
|
19
|
+
│ │ ├── chains.py # Multi-chain configuration
|
|
20
|
+
│ │ ├── rpc.py # Web3 instance management
|
|
21
|
+
│ │ ├── signer.py # Transaction signer
|
|
22
|
+
│ │ └── tx.py # TX build/sign/broadcast + ERC20 approval
|
|
23
|
+
│ ├── protocols/
|
|
24
|
+
│ │ ├── morpho/ # Morpho Blue (isolated lending markets)
|
|
25
|
+
│ │ ├── moonwell/ # Moonwell (Compound V2 fork)
|
|
26
|
+
│ │ ├── aave/ # Aave V3 (lending)
|
|
27
|
+
│ │ ├── uniswap/ # Uniswap V3 (DEX)
|
|
28
|
+
│ │ ├── oneinch/ # 1inch (DEX aggregator)
|
|
29
|
+
│ │ ├── lido/ # Lido (liquid staking)
|
|
30
|
+
│ │ ├── compound/ # Compound V3 (lending)
|
|
31
|
+
│ │ ├── curve/ # Curve Finance (DEX)
|
|
32
|
+
│ │ ├── cctp/ # Circle CCTP — V1 + V2 (cross-chain USDC, resumable)
|
|
33
|
+
│ │ └── debridge/ # deBridge DLN (arbitrary-token cross-chain swaps)
|
|
34
|
+
│ └── cli.py # Click CLI entry point
|
|
35
|
+
└── tests/
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Supported Protocols
|
|
39
|
+
|
|
40
|
+
| Protocol | Type | Chains | Operations |
|
|
41
|
+
|----------|------|--------|------------|
|
|
42
|
+
| **Morpho Blue** | Isolated Lending | Base, Ethereum, Arbitrum | supply, supplyCollateral, borrow, repay, withdraw, withdrawCollateral |
|
|
43
|
+
| **Moonwell** | Lending (Compound V2) | Base | supply(mint), redeem, borrow, repayBorrow |
|
|
44
|
+
| **Aave V3** | Lending | Base, Ethereum, Arbitrum, Optimism, Polygon | supply, withdraw, borrow, repay, collateral toggle |
|
|
45
|
+
| **Uniswap V3** | DEX | Base, Ethereum, Arbitrum, Optimism, Polygon, Unichain | quote, swap, price |
|
|
46
|
+
| **1inch** | DEX Aggregator | Base, Ethereum, Arbitrum, Optimism, Polygon | quote, swap |
|
|
47
|
+
| **Lido** | Liquid Staking | Ethereum, Base, Arbitrum, Optimism, Polygon | stake ETH, wrap/unwrap stETH/wstETH |
|
|
48
|
+
| **Compound V3** | Lending | Ethereum, Base, Arbitrum, Polygon | supply, withdraw, supplyCollateral, borrow, repay |
|
|
49
|
+
| **Curve** | Stablecoin DEX | Ethereum, Base, Arbitrum, Optimism | swap, add/remove liquidity, quote |
|
|
50
|
+
| **Circle CCTP** | Cross-chain USDC bridge | Ethereum, Optimism, Arbitrum, Base, Polygon, Unichain, Avalanche | transfer (burn→attest→mint), resumable; **V1** (default) + **V2** (Fast/Standard) |
|
|
51
|
+
| **deBridge DLN** | Cross-chain swap (any token) | Ethereum, Base, Arbitrum, Optimism, Polygon, Avalanche, Unichain | quote, send (cross-chain order via DLN REST API) |
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
### Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install defi-autopilot
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or from source:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/counterfactual5/defi-autopilot.git
|
|
65
|
+
cd defi-autopilot
|
|
66
|
+
pip install -e .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Configure
|
|
70
|
+
|
|
71
|
+
Copy `.env.example` to `.env` and fill in your values:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cp .env.example .env
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```env
|
|
78
|
+
# RPC endpoints
|
|
79
|
+
RPC_BASE=https://mainnet.base.org
|
|
80
|
+
RPC_ETHEREUM=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
|
|
81
|
+
RPC_ARBITRUM=https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY
|
|
82
|
+
|
|
83
|
+
# Signer private key (never commit to Git)
|
|
84
|
+
SIGNER_PRIVATE_KEY=***
|
|
85
|
+
|
|
86
|
+
# Optional: 1inch API key (free tier works without it)
|
|
87
|
+
INCH_API_KEY=
|
|
88
|
+
|
|
89
|
+
# Optional: seconds to wait for a tx receipt before timing out (default 120).
|
|
90
|
+
# On timeout the tx is already broadcast; re-query the receipt later.
|
|
91
|
+
TX_RECEIPT_TIMEOUT=120
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
RPC calls automatically retry transient failures (connection errors, HTTP 429
|
|
95
|
+
rate-limits, and 5xx) up to 3 times with exponential backoff, respecting any
|
|
96
|
+
`Retry-After` header.
|
|
97
|
+
|
|
98
|
+
### Usage
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# List all available markets
|
|
102
|
+
defi markets
|
|
103
|
+
|
|
104
|
+
# --- Morpho Blue ---
|
|
105
|
+
defi morpho position --market USDC-WETH-77
|
|
106
|
+
defi morpho supply --market USDC-WETH-77 --amount 1000000000
|
|
107
|
+
defi morpho supply-collateral --market USDC-WETH-77 --amount 500000000000000000
|
|
108
|
+
defi morpho borrow --market USDC-WETH-77 --amount 500000000
|
|
109
|
+
defi morpho repay --market USDC-WETH-77 --amount 500000000
|
|
110
|
+
defi morpho withdraw --market USDC-WETH-77 --amount 1000000000
|
|
111
|
+
|
|
112
|
+
# --- Moonwell ---
|
|
113
|
+
defi moonwell supply --token USDC --amount 1000000000
|
|
114
|
+
defi moonwell borrow --token WETH --amount 500000000000000000
|
|
115
|
+
defi moonwell repay --token WETH --amount 500000000000000000
|
|
116
|
+
defi moonwell position --token USDC
|
|
117
|
+
|
|
118
|
+
# --- Aave V3 ---
|
|
119
|
+
defi aave supply --asset USDC --amount 1000000000
|
|
120
|
+
defi aave borrow --asset WETH --amount 500000000000000000
|
|
121
|
+
defi aave repay --asset WETH
|
|
122
|
+
defi aave position
|
|
123
|
+
|
|
124
|
+
# --- Uniswap V3 ---
|
|
125
|
+
defi uniswap quote --in USDC --out WETH --amount 1000000000
|
|
126
|
+
defi uniswap swap --in USDC --out WETH --amount 1000000000
|
|
127
|
+
defi uniswap price --in WETH --out USDC
|
|
128
|
+
|
|
129
|
+
# --- 1inch ---
|
|
130
|
+
defi inch quote --src USDC --dst WETH --amount 1000000000
|
|
131
|
+
defi inch swap --src USDC --dst WETH --amount 1000000000 --slippage 1.0
|
|
132
|
+
|
|
133
|
+
# --- Circle CCTP (native cross-chain USDC) ---
|
|
134
|
+
defi cctp domains # list supported chains + domain IDs
|
|
135
|
+
# Burn 10 USDC on Base (-c 8453) and mint on Arbitrum (--to 42161).
|
|
136
|
+
# Amount is in USDC base units (6 decimals): 10 USDC = 10000000
|
|
137
|
+
defi -c 8453 cctp transfer --to 42161 --amount 10000000 --run-id move-usdc-1
|
|
138
|
+
defi cctp status --run-id move-usdc-1 # inspect checkpoint
|
|
139
|
+
# Interrupted mid-flight? Re-run the SAME command — it resumes at attest/mint,
|
|
140
|
+
# never re-burning.
|
|
141
|
+
defi -c 8453 cctp transfer --to 42161 --amount 10000000 --run-id move-usdc-1
|
|
142
|
+
|
|
143
|
+
# CCTP V2 — Fast Transfer (~seconds, small fee; max fee auto-fetched from Circle)
|
|
144
|
+
defi -c 8453 cctp transfer --v2 --fast --to 42161 --amount 10000000 --run-id fast-1
|
|
145
|
+
# CCTP V2 — Standard Transfer (hard finality, usually fee-free)
|
|
146
|
+
defi -c 8453 cctp transfer --v2 --standard --to 42161 --amount 10000000 --run-id std-1
|
|
147
|
+
|
|
148
|
+
# --- Preflight doctor (no transactions sent) ---
|
|
149
|
+
defi -c 8453 doctor # RPC, chainId, signer, gas balance
|
|
150
|
+
defi -c 8453 doctor --policy --amount 1000 # also evaluate the risk policy
|
|
151
|
+
defi -c 8453 cctp doctor --to 42161 --amount 10000000 # CCTP V1 route
|
|
152
|
+
defi -c 8453 cctp doctor --v2 --fast --to 42161 --amount 10000000 # + fee quote
|
|
153
|
+
|
|
154
|
+
# --- General ---
|
|
155
|
+
defi -c 1 morpho position --market ... # specify chain
|
|
156
|
+
defi --dry-run morpho supply ... # simulate only
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## SDK Usage
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from defi_autopilot.protocols.morpho import MorphoClient, BASE_MARKETS
|
|
163
|
+
from defi_autopilot.protocols.moonwell import MoonwellClient
|
|
164
|
+
from defi_autopilot.protocols.aave import AaveV3Client, BASE_TOKENS_AAVE
|
|
165
|
+
from defi_autopilot.protocols.oneinch import OneInchClient, BASE_TOKENS_INCH
|
|
166
|
+
|
|
167
|
+
# Morpho Blue
|
|
168
|
+
morpho = MorphoClient(8453)
|
|
169
|
+
result = morpho.supply(BASE_MARKETS["USDC-WETH-77"], amount=1000000000)
|
|
170
|
+
|
|
171
|
+
# Moonwell
|
|
172
|
+
moonwell = MoonwellClient(8453)
|
|
173
|
+
result = moonwell.supply("USDC", amount=1000000000)
|
|
174
|
+
|
|
175
|
+
# Aave V3
|
|
176
|
+
aave = AaveV3Client(8453)
|
|
177
|
+
result = aave.supply(BASE_TOKENS_AAVE["USDC"], amount=1000000000)
|
|
178
|
+
health = aave.get_user_account_data("0xYourAddress")
|
|
179
|
+
|
|
180
|
+
# 1inch
|
|
181
|
+
inch = OneInchClient(8453)
|
|
182
|
+
quote = inch.get_quote(
|
|
183
|
+
BASE_TOKENS_INCH["USDC"],
|
|
184
|
+
BASE_TOKENS_INCH["WETH"],
|
|
185
|
+
amount=1000000000,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
# Circle CCTP V1 — native cross-chain USDC, resumable via state machine
|
|
189
|
+
from defi_autopilot.protocols.cctp import CCTPClient
|
|
190
|
+
|
|
191
|
+
cctp = CCTPClient(8453) # source = Base
|
|
192
|
+
result = cctp.transfer(
|
|
193
|
+
amount=10_000_000, # 10 USDC (6 decimals)
|
|
194
|
+
dest_chain_id=42161, # Arbitrum
|
|
195
|
+
run_id="move-usdc-1", # re-run with same id to resume after a crash
|
|
196
|
+
)
|
|
197
|
+
# {"status": "completed", "burn_tx": ..., "mint_tx": ...}
|
|
198
|
+
|
|
199
|
+
# Circle CCTP V2 — Fast Transfer (~seconds) or Standard (hard finality)
|
|
200
|
+
from defi_autopilot.protocols.cctp import CCTPv2Client
|
|
201
|
+
|
|
202
|
+
cctp_v2 = CCTPv2Client(8453)
|
|
203
|
+
result = cctp_v2.transfer(
|
|
204
|
+
amount=10_000_000,
|
|
205
|
+
dest_chain_id=42161,
|
|
206
|
+
fast=True, # Fast Transfer; max_fee auto-fetched from Circle
|
|
207
|
+
run_id="fast-1",
|
|
208
|
+
)
|
|
209
|
+
# {"status": "completed", "version": "v2", "burn_tx": ..., "mint_tx": ..., "max_fee": ...}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## 🛠️ Development
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
git clone https://github.com/counterfactual5/defi-autopilot.git
|
|
216
|
+
cd defi-autopilot
|
|
217
|
+
uv pip install -e ".[dev]"
|
|
218
|
+
uv run pytest tests/ -v
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
167 tests covering chain config, market params, ABI validation, client initialization, token mappings, the risk-policy gate (chokepoint + ERC-20 notional), the CCTP V1/V2 transfer state machine, the CCTP preflight doctor, the top-level chain/wallet preflight doctor, the estimateGas simulation gate, RPC retry/backoff, and the configurable receipt timeout.
|
|
222
|
+
|
|
223
|
+
## 🗺️ Roadmap
|
|
224
|
+
|
|
225
|
+
- [x] Morpho Blue lending operations
|
|
226
|
+
- [x] Moonwell supply/borrow/repay
|
|
227
|
+
- [x] Aave V3 lending + health factor
|
|
228
|
+
- [x] 1inch DEX aggregation
|
|
229
|
+
- [x] Multi-chain (Base, Ethereum, Arbitrum, Optimism, Polygon)
|
|
230
|
+
- [x] Compound V3 integration
|
|
231
|
+
- [x] Circle CCTP cross-chain USDC (resumable burn & mint) — V1 + V2 (Fast/Standard)
|
|
232
|
+
- [ ] Uniswap V3/V4 LP management
|
|
233
|
+
- [ ] Strategy automation (auto-compound, yield optimization)
|
|
234
|
+
- [ ] Position monitoring & alerting
|
|
235
|
+
- [ ] WebSocket support for real-time data
|
|
236
|
+
|
|
237
|
+
## Security
|
|
238
|
+
|
|
239
|
+
- Private keys loaded from environment variables (never hardcoded)
|
|
240
|
+
- Transactions require explicit amounts (no default all-in operations)
|
|
241
|
+
- Gas estimation with 10% buffer
|
|
242
|
+
- EIP-1559 fee auto-fetch
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
MIT
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
If this project helped you, please ⭐ star this repo — it helps others find it!
|
|
251
|
+
|
|
252
|
+
### Related Projects
|
|
253
|
+
|
|
254
|
+
- **[uniswap-autopilot](https://github.com/counterfactual5/uniswap-autopilot)** — Deep Uniswap SDK with LP management, V4 support, and 13K lines of battle-tested code. If you need advanced Uniswap features beyond basic swaps, use that.
|
|
255
|
+
- **[evm-wallet-scanner](https://github.com/counterfactual5/evm-wallet-scanner)** — Multi-chain wallet balance scanner, transaction history, and gas analytics.
|
|
256
|
+
- **[erc20-checker](https://github.com/counterfactual5/erc20-checker)** — Scan and revoke ERC20 approvals across chains.
|