wayfinder-paths 0.1.7__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 (149) hide show
  1. wayfinder_paths/CONFIG_GUIDE.md +399 -0
  2. wayfinder_paths/__init__.py +22 -0
  3. wayfinder_paths/abis/generic/erc20.json +383 -0
  4. wayfinder_paths/adapters/__init__.py +0 -0
  5. wayfinder_paths/adapters/balance_adapter/README.md +94 -0
  6. wayfinder_paths/adapters/balance_adapter/adapter.py +238 -0
  7. wayfinder_paths/adapters/balance_adapter/examples.json +6 -0
  8. wayfinder_paths/adapters/balance_adapter/manifest.yaml +8 -0
  9. wayfinder_paths/adapters/balance_adapter/test_adapter.py +59 -0
  10. wayfinder_paths/adapters/brap_adapter/README.md +249 -0
  11. wayfinder_paths/adapters/brap_adapter/__init__.py +7 -0
  12. wayfinder_paths/adapters/brap_adapter/adapter.py +726 -0
  13. wayfinder_paths/adapters/brap_adapter/examples.json +175 -0
  14. wayfinder_paths/adapters/brap_adapter/manifest.yaml +11 -0
  15. wayfinder_paths/adapters/brap_adapter/test_adapter.py +286 -0
  16. wayfinder_paths/adapters/hyperlend_adapter/__init__.py +7 -0
  17. wayfinder_paths/adapters/hyperlend_adapter/adapter.py +305 -0
  18. wayfinder_paths/adapters/hyperlend_adapter/manifest.yaml +10 -0
  19. wayfinder_paths/adapters/hyperlend_adapter/test_adapter.py +274 -0
  20. wayfinder_paths/adapters/hyperliquid_adapter/__init__.py +18 -0
  21. wayfinder_paths/adapters/hyperliquid_adapter/adapter.py +1093 -0
  22. wayfinder_paths/adapters/hyperliquid_adapter/executor.py +549 -0
  23. wayfinder_paths/adapters/hyperliquid_adapter/manifest.yaml +8 -0
  24. wayfinder_paths/adapters/hyperliquid_adapter/paired_filler.py +1050 -0
  25. wayfinder_paths/adapters/hyperliquid_adapter/test_adapter.py +126 -0
  26. wayfinder_paths/adapters/hyperliquid_adapter/test_adapter_live.py +219 -0
  27. wayfinder_paths/adapters/hyperliquid_adapter/test_utils.py +220 -0
  28. wayfinder_paths/adapters/hyperliquid_adapter/utils.py +134 -0
  29. wayfinder_paths/adapters/ledger_adapter/README.md +145 -0
  30. wayfinder_paths/adapters/ledger_adapter/__init__.py +7 -0
  31. wayfinder_paths/adapters/ledger_adapter/adapter.py +289 -0
  32. wayfinder_paths/adapters/ledger_adapter/examples.json +137 -0
  33. wayfinder_paths/adapters/ledger_adapter/manifest.yaml +11 -0
  34. wayfinder_paths/adapters/ledger_adapter/test_adapter.py +205 -0
  35. wayfinder_paths/adapters/pool_adapter/README.md +206 -0
  36. wayfinder_paths/adapters/pool_adapter/__init__.py +7 -0
  37. wayfinder_paths/adapters/pool_adapter/adapter.py +282 -0
  38. wayfinder_paths/adapters/pool_adapter/examples.json +143 -0
  39. wayfinder_paths/adapters/pool_adapter/manifest.yaml +10 -0
  40. wayfinder_paths/adapters/pool_adapter/test_adapter.py +220 -0
  41. wayfinder_paths/adapters/token_adapter/README.md +101 -0
  42. wayfinder_paths/adapters/token_adapter/__init__.py +3 -0
  43. wayfinder_paths/adapters/token_adapter/adapter.py +96 -0
  44. wayfinder_paths/adapters/token_adapter/examples.json +26 -0
  45. wayfinder_paths/adapters/token_adapter/manifest.yaml +6 -0
  46. wayfinder_paths/adapters/token_adapter/test_adapter.py +125 -0
  47. wayfinder_paths/config.example.json +22 -0
  48. wayfinder_paths/conftest.py +31 -0
  49. wayfinder_paths/core/__init__.py +18 -0
  50. wayfinder_paths/core/adapters/BaseAdapter.py +65 -0
  51. wayfinder_paths/core/adapters/__init__.py +5 -0
  52. wayfinder_paths/core/adapters/base.py +5 -0
  53. wayfinder_paths/core/adapters/models.py +46 -0
  54. wayfinder_paths/core/analytics/__init__.py +11 -0
  55. wayfinder_paths/core/analytics/bootstrap.py +57 -0
  56. wayfinder_paths/core/analytics/stats.py +48 -0
  57. wayfinder_paths/core/analytics/test_analytics.py +170 -0
  58. wayfinder_paths/core/clients/AuthClient.py +83 -0
  59. wayfinder_paths/core/clients/BRAPClient.py +109 -0
  60. wayfinder_paths/core/clients/ClientManager.py +210 -0
  61. wayfinder_paths/core/clients/HyperlendClient.py +192 -0
  62. wayfinder_paths/core/clients/LedgerClient.py +443 -0
  63. wayfinder_paths/core/clients/PoolClient.py +128 -0
  64. wayfinder_paths/core/clients/SimulationClient.py +192 -0
  65. wayfinder_paths/core/clients/TokenClient.py +89 -0
  66. wayfinder_paths/core/clients/TransactionClient.py +63 -0
  67. wayfinder_paths/core/clients/WalletClient.py +94 -0
  68. wayfinder_paths/core/clients/WayfinderClient.py +269 -0
  69. wayfinder_paths/core/clients/__init__.py +48 -0
  70. wayfinder_paths/core/clients/protocols.py +392 -0
  71. wayfinder_paths/core/clients/sdk_example.py +110 -0
  72. wayfinder_paths/core/config.py +458 -0
  73. wayfinder_paths/core/constants/__init__.py +26 -0
  74. wayfinder_paths/core/constants/base.py +42 -0
  75. wayfinder_paths/core/constants/erc20_abi.py +118 -0
  76. wayfinder_paths/core/constants/hyperlend_abi.py +152 -0
  77. wayfinder_paths/core/engine/StrategyJob.py +188 -0
  78. wayfinder_paths/core/engine/__init__.py +5 -0
  79. wayfinder_paths/core/engine/manifest.py +97 -0
  80. wayfinder_paths/core/services/__init__.py +0 -0
  81. wayfinder_paths/core/services/base.py +179 -0
  82. wayfinder_paths/core/services/local_evm_txn.py +430 -0
  83. wayfinder_paths/core/services/local_token_txn.py +231 -0
  84. wayfinder_paths/core/services/web3_service.py +45 -0
  85. wayfinder_paths/core/settings.py +61 -0
  86. wayfinder_paths/core/strategies/Strategy.py +280 -0
  87. wayfinder_paths/core/strategies/__init__.py +5 -0
  88. wayfinder_paths/core/strategies/base.py +7 -0
  89. wayfinder_paths/core/strategies/descriptors.py +81 -0
  90. wayfinder_paths/core/utils/__init__.py +1 -0
  91. wayfinder_paths/core/utils/evm_helpers.py +206 -0
  92. wayfinder_paths/core/utils/wallets.py +77 -0
  93. wayfinder_paths/core/wallets/README.md +91 -0
  94. wayfinder_paths/core/wallets/WalletManager.py +56 -0
  95. wayfinder_paths/core/wallets/__init__.py +7 -0
  96. wayfinder_paths/policies/enso.py +17 -0
  97. wayfinder_paths/policies/erc20.py +34 -0
  98. wayfinder_paths/policies/evm.py +21 -0
  99. wayfinder_paths/policies/hyper_evm.py +19 -0
  100. wayfinder_paths/policies/hyperlend.py +12 -0
  101. wayfinder_paths/policies/hyperliquid.py +30 -0
  102. wayfinder_paths/policies/moonwell.py +54 -0
  103. wayfinder_paths/policies/prjx.py +30 -0
  104. wayfinder_paths/policies/util.py +27 -0
  105. wayfinder_paths/run_strategy.py +411 -0
  106. wayfinder_paths/scripts/__init__.py +0 -0
  107. wayfinder_paths/scripts/create_strategy.py +181 -0
  108. wayfinder_paths/scripts/make_wallets.py +169 -0
  109. wayfinder_paths/scripts/run_strategy.py +124 -0
  110. wayfinder_paths/scripts/validate_manifests.py +213 -0
  111. wayfinder_paths/strategies/__init__.py +0 -0
  112. wayfinder_paths/strategies/basis_trading_strategy/README.md +213 -0
  113. wayfinder_paths/strategies/basis_trading_strategy/__init__.py +3 -0
  114. wayfinder_paths/strategies/basis_trading_strategy/constants.py +1 -0
  115. wayfinder_paths/strategies/basis_trading_strategy/examples.json +16 -0
  116. wayfinder_paths/strategies/basis_trading_strategy/manifest.yaml +23 -0
  117. wayfinder_paths/strategies/basis_trading_strategy/snapshot_mixin.py +1011 -0
  118. wayfinder_paths/strategies/basis_trading_strategy/strategy.py +4522 -0
  119. wayfinder_paths/strategies/basis_trading_strategy/test_strategy.py +727 -0
  120. wayfinder_paths/strategies/basis_trading_strategy/types.py +39 -0
  121. wayfinder_paths/strategies/config.py +85 -0
  122. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/README.md +100 -0
  123. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/examples.json +8 -0
  124. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/manifest.yaml +7 -0
  125. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/strategy.py +2270 -0
  126. wayfinder_paths/strategies/hyperlend_stable_yield_strategy/test_strategy.py +352 -0
  127. wayfinder_paths/strategies/stablecoin_yield_strategy/README.md +96 -0
  128. wayfinder_paths/strategies/stablecoin_yield_strategy/examples.json +17 -0
  129. wayfinder_paths/strategies/stablecoin_yield_strategy/manifest.yaml +17 -0
  130. wayfinder_paths/strategies/stablecoin_yield_strategy/strategy.py +1810 -0
  131. wayfinder_paths/strategies/stablecoin_yield_strategy/test_strategy.py +520 -0
  132. wayfinder_paths/templates/adapter/README.md +105 -0
  133. wayfinder_paths/templates/adapter/adapter.py +26 -0
  134. wayfinder_paths/templates/adapter/examples.json +8 -0
  135. wayfinder_paths/templates/adapter/manifest.yaml +6 -0
  136. wayfinder_paths/templates/adapter/test_adapter.py +49 -0
  137. wayfinder_paths/templates/strategy/README.md +153 -0
  138. wayfinder_paths/templates/strategy/examples.json +11 -0
  139. wayfinder_paths/templates/strategy/manifest.yaml +8 -0
  140. wayfinder_paths/templates/strategy/strategy.py +57 -0
  141. wayfinder_paths/templates/strategy/test_strategy.py +197 -0
  142. wayfinder_paths/tests/__init__.py +0 -0
  143. wayfinder_paths/tests/test_smoke_manifest.py +48 -0
  144. wayfinder_paths/tests/test_test_coverage.py +212 -0
  145. wayfinder_paths/tests/test_utils.py +64 -0
  146. wayfinder_paths-0.1.7.dist-info/LICENSE +21 -0
  147. wayfinder_paths-0.1.7.dist-info/METADATA +777 -0
  148. wayfinder_paths-0.1.7.dist-info/RECORD +149 -0
  149. wayfinder_paths-0.1.7.dist-info/WHEEL +4 -0
@@ -0,0 +1,213 @@
1
+ # Basis Trading Strategy
2
+
3
+ Delta-neutral basis trading on Hyperliquid that captures funding rate payments through matched spot long and perpetual short positions.
4
+
5
+ ## How It Works
6
+
7
+ ### Delta-Neutral Basis Trading
8
+
9
+ The strategy maintains market neutrality by holding equal-and-opposite positions:
10
+ - **Long Spot**: Buy the underlying asset (e.g., HYPE)
11
+ - **Short Perp**: Short the perpetual contract for the same asset
12
+
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
17
+
18
+ ### Position Sizing with Leverage
19
+
20
+ Given a deposit of `D` USDC and leverage `L`:
21
+ - **Order Size**: `order_usd = D * (L / (L + 1))`
22
+ - **Margin Reserved**: `D / (L + 1)`
23
+
24
+ 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
29
+
30
+ ### 1. Candidate Discovery
31
+
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
35
+
36
+ ### 2. Historical Analysis (Backtesting)
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
43
+
44
+ Uses a deterministic "stress test" approach over rolling historical windows:
45
+
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
+ ```
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
+ ```
74
+
75
+ ### 5. Ranking
76
+
77
+ Opportunities are ranked by expected APY:
78
+ ```
79
+ expected_apy = mean_hourly_funding * 24 * 365 * safe_leverage
80
+ ```
81
+
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
95
+
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
101
+
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
111
+
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
116
+
117
+ ## CLI Usage
118
+
119
+ ```bash
120
+ # Analyze opportunities for a $1000 deposit (doesn't open position)
121
+ poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
122
+ --action analyze --amount 1000 --config config.json
123
+
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
127
+
128
+ # Analyze and open/manage position
129
+ poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
130
+ --action update --config config.json
131
+
132
+ # Check current status
133
+ poetry run python wayfinder_paths/run_strategy.py basis_trading_strategy \
134
+ --action status --config config.json
135
+
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
139
+
140
+ # Generate batch snapshot of all opportunities
141
+ 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
+ }
164
+ ```
165
+
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
194
+
195
+ ## Risk Factors
196
+
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
199
+ 3. **Execution Slippage**: Large orders may move the market
200
+ 4. **Withdrawal Delays**: Hyperliquid withdrawals take ~15-30 minutes
201
+ 5. **Smart Contract Risk**: Funds are held on Hyperliquid's L1
202
+
203
+ ## Architecture
204
+
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
213
+ ```
@@ -0,0 +1,3 @@
1
+ from .strategy import BasisTradingStrategy
2
+
3
+ __all__ = ["BasisTradingStrategy"]
@@ -0,0 +1 @@
1
+ USDC_ARBITRUM_TOKEN_ID = "usd-coin-arbitrum"
@@ -0,0 +1,16 @@
1
+ {
2
+ "smoke": {
3
+ "deposit": {"main_token_amount": 100, "gas_token_amount": 0.0001},
4
+ "update": {},
5
+ "status": {},
6
+ "withdraw": {}
7
+ },
8
+ "min_deposit_fail": {
9
+ "deposit": {"main_token_amount": 10, "gas_token_amount": 0.0},
10
+ "expect": {"success": false, "message_contains": "Minimum deposit"}
11
+ },
12
+ "analysis_only": {
13
+ "deposit": {"main_token_amount": 200, "gas_token_amount": 0.0001},
14
+ "update": {}
15
+ }
16
+ }
@@ -0,0 +1,23 @@
1
+ schema_version: "0.1"
2
+ entrypoint: "wayfinder_paths.strategies.basis_trading_strategy.strategy.BasisTradingStrategy"
3
+ permissions:
4
+ policy: |
5
+ (wallet.id == 'FORMAT_WALLET_ID') AND (
6
+ # Allow Hyperliquid EIP-712 order actions
7
+ (action.type == 'hyperliquid_order') OR
8
+ (action.type == 'hyperliquid_cancel') OR
9
+ (action.type == 'hyperliquid_transfer') OR
10
+ # Allow USDC transfers to Hyperliquid bridge
11
+ (action.type == 'erc20_transfer' AND action.to == '0x2Df1c51E09aECF9cacB7bc98cB1742757f163dF7') OR
12
+ # Allow USDC withdraw to main wallet
13
+ (action.type == 'erc20_transfer' AND action.to == main_wallet.address)
14
+ )
15
+ adapters:
16
+ - name: "BALANCE"
17
+ capabilities: ["wallet_read", "wallet_transfer"]
18
+ - name: "LEDGER"
19
+ capabilities: ["ledger.read", "ledger.write", "strategy.transactions"]
20
+ - name: "TOKEN"
21
+ capabilities: ["token.read"]
22
+ - name: "HYPERLIQUID"
23
+ capabilities: ["market.read", "market.meta", "market.funding", "market.candles", "market.orderbook", "order.execute", "order.cancel", "position.manage", "transfer"]