Skip to content

Commit 21be186

Browse files
authored
refactor: ♻️ Uncouple HyperLiquid & Associated code (#69)
* first attempt * refactor: ♻️ remove old references * update ci * typo
1 parent 2d8e548 commit 21be186

34 files changed

+172
-1846
lines changed

.github/workflows/CI.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,38 @@ jobs:
6262
- *uv-sync
6363
- name: Run CLI with help flag
6464
run: uv run tq-oracle --help
65-
66-
unittest:
65+
66+
unit-test:
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v4
70+
- *uv-install
71+
- *uv-python
72+
- *uv-sync
73+
- run: uv run pytest
74+
75+
integration-test:
6776
runs-on: ubuntu-latest
6877
steps:
6978
- uses: actions/checkout@v4
7079
- *uv-install
7180
- *uv-python
7281
- *uv-sync
73-
- name: Run unit tests with pytest
74-
run: uv run pytest
82+
- run: uv run pytest --run-integration
7583

84+
live-run:
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v4
88+
- *uv-install
89+
- *uv-python
90+
- *uv-sync
91+
- name: Run against eth test vault
92+
run: |
93+
uv run tq-oracle --network mainnet \
94+
--ignore-empty-vault \
95+
--ignore-timeout-check \
96+
--ignore-active-proposal-check \
97+
--log-level debug \
98+
--vault-rpc ${{ secrets.ETH_RPC }} \
99+
0xDbC81B33A23375A90c8Ba4039d5738CB6f56fE8d

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ CLAUDE.md
2828

2929
.env
3030

31-
test.toml
32-
config.toml
33-
tq-oracle.toml
31+
**/*.toml
32+
!py_project.toml

ARCHITECTURE.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The CLI entry point uses Typer for command-line interface management. It:
3333
**Key Configuration:**
3434

3535
- Network selection (mainnet, sepolia, base)
36-
- RPC endpoints (L1 and Hyperliquid)
36+
- RPC endpoints for vault network
3737
- Oracle and OracleHelper contract addresses
3838
- Safe multi-sig configuration
3939
- Dry-run vs production mode
@@ -55,7 +55,6 @@ The pipeline is the core orchestrator that sequences all oracle operations:
5555
Runs validation checks before processing TVL data to prevent race conditions and ensure data integrity:
5656

5757
- **Safe State Check** (`check_adapters/safe_state.py`): TODO: Ensures no duplicate or pending reports
58-
- **CCTP Bridge Check** (`check_adapters/cctp_bridge.py`): Detects in-flight USDC transfers between L1 and Hyperliquid
5958
- **Timeout Check** (`check_adapters/timeout_check.py`): Verifies sufficient time has passed since last report
6059
- **Active Proposal Check** (`check_adapters/active_submit_report_proposal_check.py`): Checks for existing pending proposals
6160

@@ -73,7 +72,6 @@ Discovers and aggregates asset holdings from multiple sources:
7372
**Supported Adapters** (`adapters/asset_adapters/`):
7473

7574
- `IdleBalancesAdapter`: Checks for assets sat dormant in subvault
76-
- `HyperliquidAdapter`: Fetches portfolio value from Hyperliquid DEX
7775

7876
#### 2.3 Pricing & Validation (`pipeline/pricing.py`)
7977

@@ -172,7 +170,7 @@ sequenceDiagram
172170
### Data Flow
173171

174172
1. **Off-Chain Aggregation**:
175-
- TQ Oracle queries multiple data sources (Hyperliquid API, L1 contracts, DEXs)
173+
- TQ Oracle queries multiple data sources (vault chain contracts, DEXs, optional integrations)
176174
- Aggregates asset amounts across all subvaults
177175
- Fetches market prices from various sources
178176

@@ -198,7 +196,8 @@ TQ Oracle uses a three-tier configuration system with precedence:
198196

199197
- `vault_address`: Target vault to report on
200198
- `oracle_helper_address`: OracleHelper contract for price normalization
201-
- `vault_rpc` / `hl_rpc`: RPC endpoints for different chains (vault network and Hyperliquid)
199+
- `vault_rpc`: RPC endpoint for the vault network
200+
- `hl_rpc` (optional/disabled): Hyperliquid RPC endpoint reserved for future use
202201
- `safe_address`: Gnosis Safe for multi-sig submission
203202
- `private_key`: Signer key for proposing Safe transactions
204203
- `subvault_adapters`: Per-subvault adapter configuration
@@ -208,7 +207,7 @@ TQ Oracle uses a three-tier configuration system with precedence:
208207
Allows fine-grained control over which adapters run for each subvault via TOML configuration:
209208

210209
- Specify target subvault address
211-
- Define which chain the subvault operates on (L1 or Hyperliquid)
210+
- Define which chain the subvault operates on (typically L1; Hyperliquid support requires re-enabling the integration)
212211
- List additional adapters to run for this subvault
213212
- Option to skip default idle balances check
214213
- Option to skip subvault existence validation

README.md

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,17 @@ All configuration options can be set via CLI arguments, environment variables, o
6464

6565
| CLI Option | Environment Variable | TOML Key | Default | Description |
6666
|------------|---------------------|-----------|---------|-------------|
67-
| `VAULT_ADDRESS` | - | `vault_address` | *required* | Vault contract address (positional argument) |
67+
| `vault_address` (argument) | `TQ_ORACLE_VAULT_ADDRESS` | `vault_address` | *required* | Vault contract address passed as positional argument |
6868
| `--config` `-c` | - | - | Auto-detect | Path to TOML configuration file |
69-
| `--oracle-helper-address` `-h` | - | `oracle_helper_address` | Auto (mainnet/testnet) | OracleHelper contract address |
70-
| `--vault-rpc` | `VAULT_RPC` | `vault_rpc` | Auto (mainnet/sepolia/base) | Vault network RPC endpoint |
71-
| `--hl-rpc` | `HL_EVM_RPC` | `hl_rpc` | Auto (mainnet/testnet) | Hyperliquid RPC endpoint |
72-
| `--l1-subvault-address` | `L1_SUBVAULT_ADDRESS` | `l1_subvault_address` | - | L1 subvault for CCTP monitoring |
73-
| `--hl-subvault-address` | `HL_SUBVAULT_ADDRESS` | `hl_subvault_address` | Vault address | Hyperliquid subvault address |
74-
| `--safe-address` `-s` | - | `safe_address` | - | Gnosis Safe address for multi-sig |
75-
| `--hyperliquid-env` | `HYPERLIQUID_ENV` | `hyperliquid_env` | `"mainnet"` | Hyperliquid environment (`"mainnet"` or `"testnet"`) |
76-
| `--cctp-env` | `CCTP_ENV` | `cctp_env` | `"mainnet"` | CCTP environment (`"mainnet"` or `"testnet"`) |
77-
| `--dry-run/--no-dry-run` | - | `dry_run` | `true` | Preview without sending transaction |
78-
| `--private-key` | `PRIVATE_KEY` |*Never use TOML* | - | Private key for signing (required with Safe on --no-dry-run) |
79-
| `--safe-key` | `SAFE_TRANSACTION_SERVICE_API_KEY` |*Never use TOML* | - | API key for Safe Transaction Service |
80-
| `--ignore-empty-vault` | - | `ignore_empty_vault` | `false` | Suppress errors for empty vaults |
81-
| `--ignore-timeout-check` | - | `ignore_timeout_check` | `false` | Allow forced submission bypassing timeout |
82-
| `--ignore-active-proposal-check` | - | `ignore_active_proposal_check` | `false` | Allow duplicate submissions |
83-
| `--pre-check-retries` | - | `pre_check_retries` | `3` | Number of pre-check retry attempts |
84-
| `--pre-check-timeout` | - | `pre_check_timeout` | `12.0` | Timeout between pre-check retries (seconds) |
85-
| - | - | `log_level` | `"INFO"` | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
86-
| - | - | `chainlink_price_warning_tolerance_percentage` | `0.5` | Price deviation warning threshold (%) |
87-
| - | - | `chainlink_price_failure_tolerance_percentage` | `1.0` | Price deviation failure threshold (%) |
69+
| `--network` `-n` | `TQ_ORACLE_NETWORK` | `network` | `"mainnet"` | Network to report on (`mainnet`, `sepolia`, `base`) |
70+
| `--block-number` | `TQ_ORACLE_BLOCK_NUMBER` | `block_number` | Latest block | Block number to snapshot vault state |
71+
| `--vault-rpc` | `TQ_ORACLE_VAULT_RPC` | `vault_rpc` | Network default | RPC endpoint for the selected vault network |
72+
| `--dry-run/--no-dry-run` | `TQ_ORACLE_DRY_RUN` | `dry_run` | `true` | Preview report without submitting a Safe transaction |
73+
| `--ignore-empty-vault/--require-nonempty-vault` | `TQ_ORACLE_IGNORE_EMPTY_VAULT` | `ignore_empty_vault` | `false` | Skip failure when vault holds zero assets |
74+
| `--ignore-timeout-check/--enforce-timeout-check/--enforce-timeout-check` | `TQ_ORACLE_IGNORE_TIMEOUT_CHECK` | `ignore_timeout_check` | `false` | Skip minimum interval guard between reports |
75+
| `--ignore-active-proposal-check/--enforce-active-proposal-check/--enforce-active-proposal-check` | `TQ_ORACLE_IGNORE_ACTIVE_PROPOSAL_CHECK` | `ignore_active_proposal_check` | `false` | Skip duplicate active proposal guard |
76+
| `--log-level` | `TQ_ORACLE_LOG_LEVEL` | `log_level` | `"INFO"` | Override logging verbosity (`TRACE`, `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`) |
77+
| `--show-config` | - | - | `false` | Dump effective configuration (with secrets redacted) and exit |
8878

8979
#### TOML-Only Options (Not available via CLI)
9080

@@ -94,6 +84,8 @@ All configuration options can be set via CLI arguments, environment variables, o
9484
| `rpc_max_concurrent_calls` | `5` | Maximum concurrent RPC connections |
9585
| `rpc_delay` | `0.15` | Delay between RPC calls (seconds) |
9686
| `rpc_jitter` | `0.10` | Random jitter for RPC delays (seconds) |
87+
| `price_warning_tolerance_percentage` | `0.5` | Price deviation warning threshold (%) |
88+
| `price_failure_tolerance_percentage` | `1.0` | Price deviation failure threshold (%) |
9789

9890
### Advanced Configuration: Subvault Adapters
9991

@@ -102,15 +94,17 @@ TQ Oracle supports configuring multiple asset adapters per subvault address, all
10294
**Configuration via TOML:**
10395

10496
- Specify target subvault address
105-
- Define which chain the subvault operates on (L1 or Hyperliquid)
97+
- Define which chain the subvault operates on (typically `vault_chain`)
10698
- List additional adapters to run for this subvault
10799
- Option to skip default idle balances check
108100
- Option to skip subvault existence validation
109101

110102
**Available Asset Adapters:**
111103

112104
- `idle_balances` - Checks for idle USDC balances not yet deployed
113-
- `hyperliquid` - Fetches portfolio value from Hyperliquid
105+
- `hyperliquid` *(disabled)* - See the restore checklist before re-enabling
106+
107+
114108

115109
See `tq-oracle-example.toml` for complete configuration examples.
116110

@@ -148,10 +142,15 @@ tq-oracle --network sepolia 0xYourVaultAddress
148142
tq-oracle --show-config
149143
```
150144

145+
**Increase verbosity for debugging:**
146+
147+
```bash
148+
tq-oracle --log-level DEBUG
149+
```
150+
151151
**Common Usage Patterns:**
152152

153153
- **Dry-run on mainnet**: Preview report generation without submitting to chain
154-
- **Custom subvault**: Specify Hyperliquid subvault address for cross-chain asset tracking
155154
- **Testnet execution**: Run against testnet with Safe multi-sig for testing
156155
- **Pre-deployment testing**: Test with empty vaults using ignore flags
157156

@@ -177,20 +176,20 @@ src/tq_oracle/
177176
Before processing TVL data, TQ Oracle runs automated pre-flight validation checks to ensure data integrity:
178177

179178
- **Safe State Validation**: Ensures no duplicate or pending reports exist
180-
- **CCTP Bridge Detection**: Identifies in-flight USDC transfers between L1 and Hyperliquid
181179
- **Check Retry Logic**: Automatically retries failed checks with exponential backoff when recommended
180+
- **CCTP Bridge Detection** *(disabled)*: Re-enable via the checklist when cross-chain monitoring is required
182181

183-
These checks prevent race conditions and ensure accurate TVL snapshots by detecting ongoing cross-chain transfers that could affect asset balances.
182+
These checks prevent race conditions and ensure accurate TVL snapshots by detecting ongoing cross-chain transfers that could affect asset balances. You can bypass individual guards when needed via the CLI flags `--ignore-empty-vault`, `--ignore-timeout-check/--enforce-timeout-check`, and `--ignore-active-proposal-check/--enforce-active-proposal-check`.
184183

185184
### Testing CCTP Bridge Detection
186185

187-
A standalone test script is available in `scripts/check_cctp_inflight.py` to verify CCTP bridge in-flight detection with L1 and Hyperliquid subvault addresses.
186+
A standalone test script is available in `scripts/check_cctp_inflight.py` and can be used once the CCTP integration is re-enabled.
188187

189188
## Adding New Adapters
190189

191190
### Asset Adapters
192191

193-
Asset adapters fetch asset holdings from specific protocols (e.g., Hyperliquid, Aave, Lido).
192+
Asset adapters fetch asset holdings from specific protocols (e.g., Aave, Lido).
194193

195194
Quick overview:
196195

@@ -223,8 +222,9 @@ Price validators cross-check prices from the main price adapters against referen
223222
5. **Write unit tests** in `tests/adapters/price_validators/`
224223

225224
Validators respect tolerance thresholds configured in `settings.py`:
226-
- `chainlink_price_warning_tolerance_percentage` (default: 0.5%) - Issues warnings
227-
- `chainlink_price_failure_tolerance_percentage` (default: 1.0%) - Halts execution
225+
226+
- `price_warning_tolerance_percentage` (default: 0.5%) - Issues warnings
227+
- `price_failure_tolerance_percentage` (default: 1.0%) - Halts execution
228228

229229
## Development
230230

@@ -238,6 +238,5 @@ Validators respect tolerance thresholds configured in `settings.py`:
238238
## External Links
239239

240240
- `flexible-vaults` [repo](https://github.com/mellow-finance/flexible-vaults)
241-
- Hyperliquid API [documentation](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint)
242241
- `cctp-v2` [contracts](https://github.com/circlefin/evm-cctp-contracts/tree/master/src/v2)
243242
- DeBridge [contracts](https://github.com/debridge-finance/dln-contracts/tree/main/contracts/DLN)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Hyperliquid & CCTP Restore Checklist
2+
3+
Use this checklist when you are ready to ship Hyperliquid support and the CCTP pre-check again. Work through every section before exposing the functionality.
4+
5+
## 1. Dependencies
6+
7+
- [ ] Add the hyperliquid sdk back to `pyproject.toml` and run **uv sync** to update `uv.lock`.
8+
- [ ] Confirm RPC providers and API endpoints for the target Hyperliquid environment(s).
9+
10+
## 2. Configuration & CLI Surface
11+
12+
- [ ] Restore Hyperliquid/CCTP fields in `OracleSettings` (environment toggles, RPC/subvault fields, token messenger settings).
13+
- [ ] Reinstate logging/telemetry in `pipeline/run.py` that records Hyperliquid and CCTP settings.
14+
- [ ] Reintroduce CLI flags for Hyperliquid/CCTP in `main.py` (`--hyperliquid-env`, `--hl-rpc`, `--hl-block-number`, `--cctp-env`).
15+
- [ ] Update documentation (README/ARCHITECTURE) and sample configs once fields exist again.
16+
17+
## 3. Runtime Wiring
18+
19+
- [ ] Re-register `HyperliquidAdapter` in `src/tq_oracle/adapters/asset_adapters/__init__.py`.
20+
- [ ] Allow `collect_assets` to schedule Hyperliquid adapters instead of skipping disabled entries.
21+
- [ ] Ensure idle balances on Hyperliquid still function (`IdleBalancesAdapter` with `chain="hyperliquid"`).
22+
23+
## 4. CCTP Pre-Check
24+
25+
- [ ] Re-enable `CCTPBridgeAdapter` in `src/tq_oracle/adapters/check_adapters/__init__.py`.
26+
- [ ] Validate CCTP config fields (token messenger address, hl/l1 subvault addresses) are surfaced and documented.
27+
- [ ] Confirm `scripts/check_cctp_inflight.py` still works end-to-end.
28+
29+
## 5. Validation & Monitoring
30+
31+
- [ ] Re-run unit/integration tests covering Hyperliquid + CCTP (`tests/adapters/asset_adapters/test_hyperliquid.py`, `tests/adapters/check_adapters/test_cctp_bridge.py`, pipeline smoke tests).
32+
- [ ] Execute manual dry-runs against staging vaults to verify NAV + pre-check behaviour.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ requires-python = ">=3.11"
77
dependencies = [
88
"backoff>=2.2.1",
99
"dotenv>=0.9.9",
10-
"hyperliquid-python-sdk>=0.19.0",
1110
"pydantic>=2.6",
1211
"pydantic-settings>=2.2",
1312
"requests>=2.32.5",

0 commit comments

Comments
 (0)