wayfinder-paths 0.1.19__py3-none-any.whl → 0.1.21__py3-none-any.whl

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.

Potentially problematic release.


This version of wayfinder-paths might be problematic. Click here for more details.

Files changed (98) hide show
  1. wayfinder_paths/__init__.py +0 -2
  2. wayfinder_paths/adapters/balance_adapter/README.md +59 -45
  3. wayfinder_paths/adapters/balance_adapter/adapter.py +1 -22
  4. wayfinder_paths/adapters/balance_adapter/test_adapter.py +0 -14
  5. wayfinder_paths/adapters/brap_adapter/README.md +61 -184
  6. wayfinder_paths/adapters/brap_adapter/__init__.py +0 -4
  7. wayfinder_paths/adapters/brap_adapter/adapter.py +1 -148
  8. wayfinder_paths/adapters/brap_adapter/test_adapter.py +0 -15
  9. wayfinder_paths/adapters/hyperlend_adapter/__init__.py +0 -4
  10. wayfinder_paths/adapters/hyperlend_adapter/adapter.py +1 -10
  11. wayfinder_paths/adapters/hyperlend_adapter/test_adapter.py +0 -17
  12. wayfinder_paths/adapters/hyperliquid_adapter/adapter.py +3 -312
  13. wayfinder_paths/adapters/hyperliquid_adapter/executor.py +1 -71
  14. wayfinder_paths/adapters/hyperliquid_adapter/paired_filler.py +0 -57
  15. wayfinder_paths/adapters/hyperliquid_adapter/test_adapter.py +0 -17
  16. wayfinder_paths/adapters/hyperliquid_adapter/test_adapter_live.py +2 -42
  17. wayfinder_paths/adapters/hyperliquid_adapter/test_executor.py +1 -9
  18. wayfinder_paths/adapters/hyperliquid_adapter/test_utils.py +15 -47
  19. wayfinder_paths/adapters/hyperliquid_adapter/utils.py +0 -7
  20. wayfinder_paths/adapters/ledger_adapter/README.md +54 -74
  21. wayfinder_paths/adapters/ledger_adapter/__init__.py +0 -4
  22. wayfinder_paths/adapters/ledger_adapter/adapter.py +0 -106
  23. wayfinder_paths/adapters/ledger_adapter/test_adapter.py +0 -12
  24. wayfinder_paths/adapters/moonwell_adapter/README.md +67 -106
  25. wayfinder_paths/adapters/moonwell_adapter/__init__.py +0 -4
  26. wayfinder_paths/adapters/moonwell_adapter/adapter.py +10 -122
  27. wayfinder_paths/adapters/moonwell_adapter/test_adapter.py +84 -83
  28. wayfinder_paths/adapters/pool_adapter/README.md +30 -51
  29. wayfinder_paths/adapters/pool_adapter/__init__.py +0 -4
  30. wayfinder_paths/adapters/pool_adapter/adapter.py +0 -19
  31. wayfinder_paths/adapters/pool_adapter/test_adapter.py +0 -8
  32. wayfinder_paths/adapters/token_adapter/README.md +41 -49
  33. wayfinder_paths/adapters/token_adapter/adapter.py +0 -32
  34. wayfinder_paths/adapters/token_adapter/test_adapter.py +1 -12
  35. wayfinder_paths/conftest.py +0 -8
  36. wayfinder_paths/core/__init__.py +0 -2
  37. wayfinder_paths/core/adapters/BaseAdapter.py +0 -22
  38. wayfinder_paths/core/adapters/__init__.py +0 -5
  39. wayfinder_paths/core/adapters/models.py +0 -5
  40. wayfinder_paths/core/analytics/__init__.py +0 -2
  41. wayfinder_paths/core/analytics/bootstrap.py +0 -16
  42. wayfinder_paths/core/analytics/stats.py +0 -7
  43. wayfinder_paths/core/analytics/test_analytics.py +5 -34
  44. wayfinder_paths/core/clients/BRAPClient.py +0 -35
  45. wayfinder_paths/core/clients/ClientManager.py +0 -51
  46. wayfinder_paths/core/clients/HyperlendClient.py +0 -77
  47. wayfinder_paths/core/clients/LedgerClient.py +2 -122
  48. wayfinder_paths/core/clients/PoolClient.py +0 -2
  49. wayfinder_paths/core/clients/TokenClient.py +0 -39
  50. wayfinder_paths/core/clients/WalletClient.py +0 -15
  51. wayfinder_paths/core/clients/WayfinderClient.py +0 -24
  52. wayfinder_paths/core/clients/__init__.py +0 -4
  53. wayfinder_paths/core/clients/protocols.py +25 -98
  54. wayfinder_paths/core/config.py +0 -24
  55. wayfinder_paths/core/constants/__init__.py +0 -7
  56. wayfinder_paths/core/constants/base.py +2 -9
  57. wayfinder_paths/core/constants/erc20_abi.py +0 -5
  58. wayfinder_paths/core/constants/hyperlend_abi.py +0 -7
  59. wayfinder_paths/core/constants/moonwell_abi.py +0 -35
  60. wayfinder_paths/core/engine/StrategyJob.py +0 -32
  61. wayfinder_paths/core/strategies/Strategy.py +0 -99
  62. wayfinder_paths/core/strategies/__init__.py +0 -2
  63. wayfinder_paths/core/utils/__init__.py +0 -1
  64. wayfinder_paths/core/utils/evm_helpers.py +0 -50
  65. wayfinder_paths/core/utils/{erc20_service.py → tokens.py} +25 -21
  66. wayfinder_paths/core/utils/transaction.py +0 -1
  67. wayfinder_paths/run_strategy.py +0 -46
  68. wayfinder_paths/scripts/create_strategy.py +0 -17
  69. wayfinder_paths/scripts/make_wallets.py +1 -4
  70. wayfinder_paths/strategies/basis_trading_strategy/README.md +71 -163
  71. wayfinder_paths/strategies/basis_trading_strategy/snapshot_mixin.py +0 -24
  72. wayfinder_paths/strategies/basis_trading_strategy/strategy.py +36 -400
  73. wayfinder_paths/strategies/basis_trading_strategy/test_strategy.py +15 -64
  74. wayfinder_paths/strategies/basis_trading_strategy/types.py +0 -4
  75. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/README.md +65 -56
  76. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/strategy.py +4 -27
  77. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/test_strategy.py +0 -10
  78. wayfinder_paths/strategies/moonwell_wsteth_loop_strategy/README.md +71 -72
  79. wayfinder_paths/strategies/moonwell_wsteth_loop_strategy/strategy.py +23 -227
  80. wayfinder_paths/strategies/moonwell_wsteth_loop_strategy/test_strategy.py +120 -113
  81. wayfinder_paths/strategies/stablecoin_yield_strategy/README.md +64 -59
  82. wayfinder_paths/strategies/stablecoin_yield_strategy/strategy.py +4 -44
  83. wayfinder_paths/strategies/stablecoin_yield_strategy/test_strategy.py +2 -35
  84. wayfinder_paths/templates/adapter/README.md +107 -46
  85. wayfinder_paths/templates/adapter/adapter.py +0 -9
  86. wayfinder_paths/templates/adapter/test_adapter.py +0 -19
  87. wayfinder_paths/templates/strategy/README.md +113 -59
  88. wayfinder_paths/templates/strategy/strategy.py +0 -22
  89. wayfinder_paths/templates/strategy/test_strategy.py +0 -28
  90. wayfinder_paths/tests/test_test_coverage.py +2 -12
  91. wayfinder_paths/tests/test_utils.py +1 -31
  92. wayfinder_paths-0.1.21.dist-info/METADATA +355 -0
  93. wayfinder_paths-0.1.21.dist-info/RECORD +129 -0
  94. {wayfinder_paths-0.1.19.dist-info → wayfinder_paths-0.1.21.dist-info}/WHEEL +1 -1
  95. wayfinder_paths/core/adapters/base.py +0 -5
  96. wayfinder_paths-0.1.19.dist-info/METADATA +0 -592
  97. wayfinder_paths-0.1.19.dist-info/RECORD +0 -130
  98. {wayfinder_paths-0.1.19.dist-info → wayfinder_paths-0.1.21.dist-info}/LICENSE +0 -0
@@ -1,213 +1,121 @@
1
1
  # Basis Trading Strategy
2
2
 
3
- Delta-neutral basis trading on Hyperliquid that captures funding rate payments through matched spot long and perpetual short positions.
3
+ Delta-neutral basis trading on Hyperliquid for funding rate capture.
4
4
 
5
- ## How It Works
5
+ - **Module**: `wayfinder_paths.strategies.basis_trading_strategy.strategy.BasisTradingStrategy`
6
+ - **Platform**: Hyperliquid
7
+ - **Token**: USDC
6
8
 
7
- ### Delta-Neutral Basis Trading
9
+ ## Overview
8
10
 
9
- The strategy maintains market neutrality by holding equal-and-opposite positions:
11
+ This strategy captures funding rate payments through matched positions:
10
12
  - **Long Spot**: Buy the underlying asset (e.g., HYPE)
11
13
  - **Short Perp**: Short the perpetual contract for the same asset
12
14
 
13
- This creates a "basis trade" where:
14
- - Price movements cancel out (if HYPE goes up 10%, spot gains +10%, perp loses -10%)
15
- - You collect funding payments when longs pay shorts (positive funding rate)
16
- - The position is "delta-neutral" - profit comes from funding, not price direction
15
+ Price movements cancel out, and profit comes from collecting funding payments when longs pay shorts.
16
+
17
+ ## How It Works
17
18
 
18
- ### Position Sizing with Leverage
19
+ ### Position Sizing
19
20
 
20
- Given a deposit of `D` USDC and leverage `L`:
21
- - **Order Size**: `order_usd = D * (L / (L + 1))`
21
+ Given deposit `D` USDC and leverage `L`:
22
+ - **Order Size**: `D * (L / (L + 1))`
22
23
  - **Margin Reserved**: `D / (L + 1)`
23
24
 
24
25
  Example with $100 deposit at 2x leverage:
25
- - Order size: $100 * (2/3) = $66.67 per leg
26
- - Margin: $100 / 3 = $33.33
27
-
28
- ## Opportunity Selection
26
+ - Order size: $66.67 per leg
27
+ - Margin: $33.33
29
28
 
30
- ### 1. Candidate Discovery
29
+ ### Opportunity Selection
31
30
 
32
- The strategy scans all Hyperliquid markets to find spot-perp pairs:
33
- - Spots quoted in USDC that have matching perpetual contracts
34
- - Filters: minimum open interest, daily volume, order book depth
31
+ 1. **Discovery**: Scan Hyperliquid markets for spot-perp pairs
32
+ 2. **Historical Analysis**: Fetch up to 180 days of hourly funding/price data
33
+ 3. **Safe Leverage Calculation**: Stress test over rolling windows
34
+ 4. **Ranking**: Sort by expected APY = mean_funding * 24 * 365 * safe_leverage
35
35
 
36
- ### 2. Historical Analysis (Backtesting)
36
+ ## Key Parameters
37
37
 
38
- For each candidate, fetches up to 180 days of hourly data:
39
- - **Funding rates**: Mean, volatility, negative hour fraction, worst 24h/7d sums
40
- - **Price candles**: Hourly closes and highs for volatility calculation
41
-
42
- ### 3. Safe Leverage Calculation
38
+ | Parameter | Default | Description |
39
+ |-----------|---------|-------------|
40
+ | `max_leverage` | 3 | Maximum leverage allowed |
41
+ | `lookback_days` | 180 | Days of historical data |
42
+ | `confidence` | 0.975 | VaR confidence level (97.5%) |
43
+ | `fee_eps` | 0.003 | Fee buffer (0.3%) |
44
+ | `bootstrap_sims` | 50 | Monte Carlo simulations |
45
+ | `MIN_DEPOSIT_USDC` | 50 | Minimum deposit |
43
46
 
44
- Uses a deterministic "stress test" approach over rolling historical windows:
47
+ ## Adapters Used
45
48
 
46
- ```
47
- For each window of N hours:
48
- - Track cumulative negative funding (adjusted for price run-up)
49
- - Track maximum price run-up (high / entry - 1)
50
- - Calculate buffer requirement:
51
- buffer = maintenance_margin * (1 + runup) + runup + cum_neg_funding + fees
52
- ```
49
+ - **BalanceAdapter**: Wallet balances, ERC20 transfers
50
+ - **LedgerAdapter**: Deposit/withdraw tracking
51
+ - **TokenAdapter**: Token metadata
52
+ - **HyperliquidAdapter**: Market data, order execution, account state
53
53
 
54
- The worst-case buffer across all windows determines the maximum safe leverage:
55
- - If buffer requirement is 50%, max safe leverage = 2x
56
- - If buffer requirement is 33%, max safe leverage = 3x
57
-
58
- ### 4. Bootstrap Simulation (Optional)
59
-
60
- For additional statistical confidence, the strategy can run Monte Carlo simulations:
61
- - Resamples historical funding/price data in blocks (default 24h blocks)
62
- - Runs N simulations (configurable, e.g., 1000)
63
- - Calculates VaR at specified confidence level (default 97.5%)
64
-
65
- Configure via:
66
- ```json
67
- {
68
- "strategy_config": {
69
- "bootstrap_sims": 1000,
70
- "bootstrap_block_hours": 24
71
- }
72
- }
73
- ```
54
+ ## Actions
74
55
 
75
- ### 5. Ranking
56
+ ### Analyze
76
57
 
77
- Opportunities are ranked by expected APY:
78
- ```
79
- expected_apy = mean_hourly_funding * 24 * 365 * safe_leverage
58
+ ```bash
59
+ poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
60
+ --action analyze --amount 1000 --config config.json
80
61
  ```
81
62
 
82
- ## Position Management
83
-
84
- ### Opening a Position
85
-
86
- 1. Transfers USDC from main wallet to strategy wallet
87
- 2. Bridges USDC to Hyperliquid via Arbitrum
88
- 3. Splits between perp margin and spot
89
- 4. Uses `PairedFiller` to atomically execute both legs (buy spot + sell perp)
90
- 5. Places protective orders:
91
- - **Stop-loss**: Triggers if price approaches liquidation (default 65% of distance)
92
- - **Limit sell**: Closes spot if funding flips negative
93
-
94
- ### Incremental Scaling
63
+ Analyzes opportunities without opening positions.
95
64
 
96
- When you deposit additional funds with an existing position:
97
- - Detects idle capital (undeployed USDC on Hyperliquid)
98
- - Calculates additional units to add to each leg
99
- - Uses `PairedFiller` to atomically add to both positions
100
- - Maintains delta neutrality throughout
65
+ ### Deposit
101
66
 
102
- ### Monitoring (update)
103
-
104
- The `update` action:
105
- 1. Checks if position needs rebalancing (funding flipped, leverage drift, etc.)
106
- 2. Deploys any idle capital via scale-up
107
- 3. Verifies leg balance (spot amount ≈ perp amount)
108
- 4. Updates stop-loss/limit orders if liquidation price changed
109
-
110
- ### Closing a Position
67
+ ```bash
68
+ poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
69
+ --action deposit --main-token-amount 100 --config config.json
70
+ ```
111
71
 
112
- 1. Cancels all open orders
113
- 2. Uses `PairedFiller` to atomically close both legs (sell spot + buy perp)
114
- 3. Withdraws USDC from Hyperliquid to Arbitrum
115
- 4. Sends funds back to main wallet
72
+ - Transfers USDC from main wallet to strategy wallet
73
+ - Bridges USDC to Hyperliquid via Arbitrum
74
+ - Splits between perp margin and spot
75
+ - Uses PairedFiller for atomic execution (buy spot + sell perp)
76
+ - Places protective orders (stop-loss, limit sell)
116
77
 
117
- ## CLI Usage
78
+ ### Update
118
79
 
119
80
  ```bash
120
- # Analyze opportunities for a $1000 deposit (doesn't open position)
121
81
  poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
122
- --action analyze --amount 1000 --config config.json
82
+ --action update --config config.json
83
+ ```
123
84
 
124
- # Deposit $100 USDC from main wallet
125
- poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
126
- --action deposit --main-token-amount 100 --config config.json
85
+ - Checks if position needs rebalancing
86
+ - Deploys idle capital via scale-up
87
+ - Verifies leg balance (spot ≈ perp)
88
+ - Updates stop-loss/limit orders if needed
127
89
 
128
- # Analyze and open/manage position
129
- poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
130
- --action update --config config.json
90
+ ### Status
131
91
 
132
- # Check current status
92
+ ```bash
133
93
  poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
134
94
  --action status --config config.json
95
+ ```
135
96
 
136
- # Withdraw all funds back to main wallet
137
- poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
138
- --action withdraw --config config.json
97
+ ### Withdraw
139
98
 
140
- # Generate batch snapshot of all opportunities
99
+ ```bash
141
100
  poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
142
- --action snapshot --amount 1000 --config config.json
143
- ```
144
-
145
- ## Configuration
146
-
147
- ```json
148
- {
149
- "main_wallet": {
150
- "address": "0x...",
151
- "private_key": "0x..."
152
- },
153
- "strategy_wallet": {
154
- "address": "0x...",
155
- "private_key": "0x..."
156
- },
157
- "strategy_config": {
158
- "max_leverage": 3,
159
- "lookback_days": 180,
160
- "bootstrap_sims": 0,
161
- "bootstrap_block_hours": 24
162
- }
163
- }
101
+ --action withdraw --config config.json
164
102
  ```
165
103
 
166
- ### Parameters
167
-
168
- | Parameter | Default | Description |
169
- |-----------|---------|-------------|
170
- | `max_leverage` | 3 | Maximum leverage allowed |
171
- | `lookback_days` | 180 | Days of historical data for analysis |
172
- | `confidence` | 0.975 | VaR confidence level (97.5%) |
173
- | `fee_eps` | 0.003 | Fee buffer (0.3%) |
174
- | `oi_floor` | 50 | Minimum open interest (USD) |
175
- | `day_vlm_floor` | 100,000 | Minimum daily volume (USD) |
176
- | `bootstrap_sims` | 50 | Monte Carlo simulations for VaR estimation |
177
- | `bootstrap_block_hours` | 24 | Block size for bootstrap resampling |
178
-
179
- ### Thresholds
180
-
181
- | Constant | Value | Description |
182
- |----------|-------|-------------|
183
- | `MIN_DEPOSIT_USDC` | 50 | Minimum deposit |
184
- | `LIQUIDATION_REBALANCE_THRESHOLD` | 0.65 | Stop-loss at 65% of liquidation distance |
185
- | `MIN_UNUSED_USD` | 5.0 | Minimum idle capital to trigger scale-up |
186
- | `UNUSED_REL_EPS` | 0.05 | Relative threshold (5% of deposit) |
187
-
188
- ## Adapters Used
189
-
190
- - **BALANCE**: Wallet balances and ERC20 transfers
191
- - **LEDGER**: Transaction recording for deposit/withdraw tracking
192
- - **TOKEN**: Token metadata (decimals, addresses)
193
- - **HYPERLIQUID**: Market data, order execution, account state
104
+ - Cancels all open orders
105
+ - Uses PairedFiller to close both legs (sell spot + buy perp)
106
+ - Withdraws USDC from Hyperliquid to Arbitrum
107
+ - Sends funds back to main wallet
194
108
 
195
109
  ## Risk Factors
196
110
 
197
- 1. **Funding Rate Flips**: Rates can turn negative, causing losses instead of gains
198
- 2. **Liquidation Risk**: High leverage + adverse price movement can liquidate the perp
111
+ 1. **Funding Rate Flips**: Rates can turn negative
112
+ 2. **Liquidation Risk**: High leverage + adverse price movement
199
113
  3. **Execution Slippage**: Large orders may move the market
200
114
  4. **Withdrawal Delays**: Hyperliquid withdrawals take ~15-30 minutes
201
115
  5. **Smart Contract Risk**: Funds are held on Hyperliquid's L1
202
116
 
203
- ## Architecture
117
+ ## Testing
204
118
 
205
- ```
206
- BasisTradingStrategy
207
- ├── HyperliquidAdapter # Market data, account state
208
- ├── LocalHyperliquidExecutor # Order execution (spot + perp)
209
- ├── PairedFiller # Atomic paired order execution
210
- ├── BalanceAdapter # Arbitrum wallet balances
211
- ├── LedgerAdapter # Deposit/withdraw tracking
212
- └── LocalEvmTxn # Arbitrum transaction signing
119
+ ```bash
120
+ poetry run pytest wayfinder_paths/strategies/basis_trading_strategy/ -v
213
121
  ```
@@ -1,9 +1,3 @@
1
- """
2
- Basis trading snapshot/backtest helpers.
3
-
4
- Kept as a mixin so the main strategy file stays readable without changing behavior.
5
- """
6
-
7
1
  from __future__ import annotations
8
2
 
9
3
  import asyncio
@@ -38,7 +32,6 @@ class BasisSnapshotMixin:
38
32
  entry_cost_usd: float,
39
33
  exit_cost_usd: float,
40
34
  ) -> dict[str, Any]:
41
- """Build the `safe[horizon]` entry matching the expected output shape."""
42
35
  L = max(1, int(leverage))
43
36
 
44
37
  depth_checks = depth_checks or {}
@@ -167,8 +160,6 @@ class BasisSnapshotMixin:
167
160
  bootstrap_block_hours: int | None = None,
168
161
  bootstrap_seed: int | None = None,
169
162
  ) -> dict[str, Any] | None:
170
- """Return the top-ranked candidate with solver diagnostics for downstream use."""
171
-
172
163
  bootstrap_sims = int(
173
164
  self.DEFAULT_BOOTSTRAP_SIMS if bootstrap_sims is None else bootstrap_sims
174
165
  )
@@ -315,14 +306,6 @@ class BasisSnapshotMixin:
315
306
  bootstrap_block_hours: int | None = None,
316
307
  bootstrap_seed: int | None = None,
317
308
  ) -> dict[str, Any]:
318
- """
319
- Build an hourly, shareable snapshot of:
320
- - performance table (net APY + churn stats)
321
- - liquidity capacity per pair (max order/deposit supported by depth checks)
322
-
323
- Intended for batch jobs: compute once, distribute to workers, and have workers
324
- filter by user deposit size without re-hitting Hyperliquid APIs.
325
- """
326
309
  stop_frac = float(
327
310
  stop_frac if stop_frac is not None else self.LIQUIDATION_REBALANCE_THRESHOLD
328
311
  )
@@ -681,7 +664,6 @@ class BasisSnapshotMixin:
681
664
  snapshot: dict[str, Any],
682
665
  deposit_usdc: float,
683
666
  ) -> list[dict[str, Any]]:
684
- """Filter a batch snapshot for a specific deposit size."""
685
667
  if deposit_usdc <= 0:
686
668
  return []
687
669
 
@@ -754,12 +736,6 @@ class BasisSnapshotMixin:
754
736
  bootstrap_block_hours: int = 48,
755
737
  bootstrap_seed: int | None = None,
756
738
  ) -> dict[str, Any] | None:
757
- """
758
- Given a snapshot-selected opportunity, recompute a full single-coin backtest
759
- + safe sizing for the user's exact deposit size using fresh market data.
760
-
761
- This avoids running the full cross-asset scan on every worker.
762
- """
763
739
  if deposit_usdc <= 0:
764
740
  return None
765
741