muthuk1 commited on
Commit
c3f6357
Β·
verified Β·
1 Parent(s): aa73523

Add config/constants.py

Browse files
Files changed (1) hide show
  1. config/constants.py +322 -0
config/constants.py ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Dynamic RWA Yield Router β€” Configuration & Constants
3
+ =====================================================
4
+ All contract addresses, ABIs, chain configuration, and protocol parameters
5
+ for the Mantle L2 ecosystem (Chain ID 5000).
6
+ """
7
+
8
+ import os
9
+ from dataclasses import dataclass, field
10
+ from typing import Dict, List, Optional
11
+ from enum import Enum
12
+
13
+ # ─────────────────────────── Chain Config ───────────────────────────
14
+
15
+ MANTLE_CHAIN_ID = 5000
16
+ MANTLE_RPC_URL = os.getenv("MANTLE_RPC_URL", "https://rpc.mantle.xyz")
17
+ MANTLE_WSS_URL = os.getenv("MANTLE_WSS_URL", "wss://ws.mantle.xyz")
18
+ MANTLE_EXPLORER = "https://explorer.mantle.xyz"
19
+ MANTLE_BLOCK_TIME_SECONDS = 2 # Mantle L2 ~2s blocks
20
+
21
+ # ─────────────────────────── Token Addresses (Mantle Mainnet) ───────
22
+
23
+ class Tokens:
24
+ """Core token contract addresses on Mantle L2."""
25
+ # Stablecoins
26
+ USDC = "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9"
27
+ USDT = "0x201EBa5CC46D216Ce6DC03F6a759e8E766e956aE"
28
+
29
+ # Native / Wrapped
30
+ WMNT = "0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8"
31
+ WETH = "0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111"
32
+
33
+ # RWA Assets β€” Core Portfolio
34
+ USDY = "0x5bE26527e817998A7206475496fDE1E68957c5A6" # Ondo USDY (tokenized T-bills, ~4.25% APY)
35
+ METH = "0xcDA86A272531e8640cD7F1a92c01839911B90bb0" # Mantle Staked ETH (~3-5% APY)
36
+ CMETH = "0xE6829d9a7eE3040e1276Fa75293Bde931859e8fD" # Mantle Restaked ETH (cmETH)
37
+
38
+ # MI4 β€” Mantle Index Four (multi-chain, primary on Avalanche)
39
+ # On Mantle, MI4 exposure may be achieved via bridged tokens or Securitize portal
40
+ MI4_AVALANCHE = "0xe87db19a4a45a804f9b6e8038777c9a0ffbc5808"
41
+ MI4_PROXY = None # Set via env if bridged to Mantle
42
+
43
+ # Fluxion xStocks RWA tokens (on Mantle)
44
+ XAAPL = "0x3E6f0A37E795dA0304a7fC400f4CF6D8D028e1Ee"
45
+ XGOOG = "0x98a4eaB8B6CFE76EB8e36FcB5a0F09E2E4B62c2b"
46
+ XAMZN = "0x3607c534e9Ae5B4f1e968d9E7480e9D8a5f22eAa"
47
+ XTSLA = "0x5762E9828C8EEF98Ae08C7F8eB2C53C3dF6C4c2C"
48
+ XSPY = "0x5D9D2F2d8b8E7B5C0E5d6A4b0E7F1c2A3D4E5F6A" # Placeholder
49
+
50
+
51
+ # ─────────────────────────── DEX Router Addresses ───────────────────
52
+
53
+ class DEXRouters:
54
+ """DEX router contracts on Mantle."""
55
+ FLUXION_SWAP_ROUTER = "0x5628a59df0ecac3f3171f877a94beb26ba6dfaa0"
56
+ AGNI_SWAP_ROUTER = "0x319B69888b0d11cEC22caA5034e25FfFBDc88421"
57
+ MERCHANT_MOE_ROUTER = "0xeaEE7EE68874218c3558b40063c42B82D3E7232a"
58
+
59
+ # Fluxion V3 (Uni V3 fork) β€” primary for RWA pairs
60
+ FLUXION_FACTORY = "0x5CA14E40bB7Bc70A3c2e672D5F43e5B8cE48ec68"
61
+ FLUXION_QUOTER = "0x64B421eE1a1Ed22ed2288B4e3e15Dd9bD5AC5B68"
62
+
63
+
64
+ # ─────────────────────────── Lending Protocol Addresses ─────────────
65
+
66
+ class LendingProtocols:
67
+ """Lending/yield protocol contracts on Mantle."""
68
+ # Aave V3 (Lendle fork on Mantle)
69
+ AAVE_V3_POOL = "0x458F293454fE0d67EC0655f3672301301DD51422"
70
+ AAVE_V3_POOL_DATA_PROVIDER = "0x5DA14e30e92E20C9B4Fe3e22c2B499D7EA0E8b02"
71
+
72
+ # INIT Capital
73
+ INIT_CORE = "0x972BcD3960c17E5e1f2B98713c2B1A1E1eE1e2D3" # Verify on deploy
74
+
75
+ # Pendle (yield tokenization)
76
+ PENDLE_ROUTER = "0x00000000005BBB0EF59571E58418F9a4357b68A0"
77
+
78
+
79
+ # ─────────────────────────── Minimal ABIs ───────────────────────────
80
+
81
+ ERC20_ABI = [
82
+ {"constant": True, "inputs": [], "name": "name", "outputs": [{"name": "", "type": "string"}], "type": "function"},
83
+ {"constant": True, "inputs": [], "name": "symbol", "outputs": [{"name": "", "type": "string"}], "type": "function"},
84
+ {"constant": True, "inputs": [], "name": "decimals", "outputs": [{"name": "", "type": "uint8"}], "type": "function"},
85
+ {"constant": True, "inputs": [], "name": "totalSupply", "outputs": [{"name": "", "type": "uint256"}], "type": "function"},
86
+ {"constant": True, "inputs": [{"name": "_owner", "type": "address"}], "name": "balanceOf", "outputs": [{"name": "balance", "type": "uint256"}], "type": "function"},
87
+ {"constant": False, "inputs": [{"name": "_spender", "type": "address"}, {"name": "_value", "type": "uint256"}], "name": "approve", "outputs": [{"name": "", "type": "bool"}], "type": "function"},
88
+ {"constant": True, "inputs": [{"name": "_owner", "type": "address"}, {"name": "_spender", "type": "address"}], "name": "allowance", "outputs": [{"name": "", "type": "uint256"}], "type": "function"},
89
+ {"constant": False, "inputs": [{"name": "_to", "type": "address"}, {"name": "_value", "type": "uint256"}], "name": "transfer", "outputs": [{"name": "", "type": "bool"}], "type": "function"},
90
+ ]
91
+
92
+ # Uniswap V3 SwapRouter (Fluxion/Agni compatible)
93
+ SWAP_ROUTER_ABI = [
94
+ {
95
+ "inputs": [
96
+ {
97
+ "components": [
98
+ {"name": "tokenIn", "type": "address"},
99
+ {"name": "tokenOut", "type": "address"},
100
+ {"name": "fee", "type": "uint24"},
101
+ {"name": "recipient", "type": "address"},
102
+ {"name": "deadline", "type": "uint256"},
103
+ {"name": "amountIn", "type": "uint256"},
104
+ {"name": "amountOutMinimum", "type": "uint256"},
105
+ {"name": "sqrtPriceLimitX96", "type": "uint160"},
106
+ ],
107
+ "name": "params",
108
+ "type": "tuple",
109
+ }
110
+ ],
111
+ "name": "exactInputSingle",
112
+ "outputs": [{"name": "amountOut", "type": "uint256"}],
113
+ "type": "function",
114
+ },
115
+ {
116
+ "inputs": [
117
+ {
118
+ "components": [
119
+ {"name": "path", "type": "bytes"},
120
+ {"name": "recipient", "type": "address"},
121
+ {"name": "deadline", "type": "uint256"},
122
+ {"name": "amountIn", "type": "uint256"},
123
+ {"name": "amountOutMinimum", "type": "uint256"},
124
+ ],
125
+ "name": "params",
126
+ "type": "tuple",
127
+ }
128
+ ],
129
+ "name": "exactInput",
130
+ "outputs": [{"name": "amountOut", "type": "uint256"}],
131
+ "type": "function",
132
+ },
133
+ ]
134
+
135
+ # Aave V3 Pool β€” supply/withdraw
136
+ AAVE_POOL_ABI = [
137
+ {
138
+ "inputs": [
139
+ {"name": "asset", "type": "address"},
140
+ {"name": "amount", "type": "uint256"},
141
+ {"name": "onBehalfOf", "type": "address"},
142
+ {"name": "referralCode", "type": "uint16"},
143
+ ],
144
+ "name": "supply",
145
+ "outputs": [],
146
+ "type": "function",
147
+ },
148
+ {
149
+ "inputs": [
150
+ {"name": "asset", "type": "address"},
151
+ {"name": "amount", "type": "uint256"},
152
+ {"name": "to", "type": "address"},
153
+ ],
154
+ "name": "withdraw",
155
+ "outputs": [{"name": "", "type": "uint256"}],
156
+ "type": "function",
157
+ },
158
+ {
159
+ "inputs": [{"name": "asset", "type": "address"}],
160
+ "name": "getReserveData",
161
+ "outputs": [
162
+ {
163
+ "components": [
164
+ {"name": "configuration", "type": "uint256"},
165
+ {"name": "liquidityIndex", "type": "uint128"},
166
+ {"name": "currentLiquidityRate", "type": "uint128"},
167
+ {"name": "variableBorrowIndex", "type": "uint128"},
168
+ {"name": "currentVariableBorrowRate", "type": "uint128"},
169
+ {"name": "currentStableBorrowRate", "type": "uint128"},
170
+ {"name": "lastUpdateTimestamp", "type": "uint40"},
171
+ {"name": "id", "type": "uint16"},
172
+ {"name": "aTokenAddress", "type": "address"},
173
+ {"name": "stableDebtTokenAddress", "type": "address"},
174
+ {"name": "variableDebtTokenAddress", "type": "address"},
175
+ {"name": "interestRateStrategyAddress", "type": "address"},
176
+ {"name": "accruedToTreasury", "type": "uint128"},
177
+ {"name": "unbacked", "type": "uint128"},
178
+ {"name": "isolationModeTotalDebt", "type": "uint128"},
179
+ ],
180
+ "name": "",
181
+ "type": "tuple",
182
+ }
183
+ ],
184
+ "type": "function",
185
+ },
186
+ ]
187
+
188
+ # mETH staking β€” read staking yield
189
+ METH_STAKING_ABI = [
190
+ {"constant": True, "inputs": [], "name": "mETHToETH", "outputs": [{"name": "", "type": "uint256"}], "type": "function"},
191
+ {"constant": True, "inputs": [], "name": "totalControlled", "outputs": [{"name": "", "type": "uint256"}], "type": "function"},
192
+ {"constant": True, "inputs": [], "name": "exchangeRateUpdatedAt", "outputs": [{"name": "", "type": "uint256"}], "type": "function"},
193
+ ]
194
+
195
+
196
+ # ─────────────────────────── Portfolio Parameters ───────────────────
197
+
198
+ @dataclass
199
+ class PortfolioConfig:
200
+ """Default portfolio allocation parameters."""
201
+ # Asset universe
202
+ assets: List[str] = field(default_factory=lambda: ["USDY", "mETH", "MI4"])
203
+
204
+ # Target yield (annualized)
205
+ min_target_apy: float = 3.5 # minimum acceptable APY %
206
+ max_target_apy: float = 12.0 # aspirational max
207
+
208
+ # Risk constraints
209
+ max_single_asset_weight: float = 0.60 # no single asset > 60%
210
+ min_single_asset_weight: float = 0.05 # minimum 5% in each active asset
211
+ max_drawdown_pct: float = 0.10 # 10% max drawdown trigger
212
+
213
+ # Rebalancing
214
+ rebalance_threshold_pct: float = 0.05 # rebalance when drift > 5%
215
+ min_rebalance_interval_hours: int = 4 # no more frequent than 4h
216
+ max_rebalance_interval_hours: int = 168 # at least weekly
217
+
218
+ # Gas budget
219
+ max_gas_per_rebalance_usd: float = 5.0 # Mantle gas is cheap (~$0.01-0.10/tx)
220
+
221
+ # Slippage
222
+ max_slippage_bps: int = 50 # 0.5% max slippage
223
+
224
+
225
+ @dataclass
226
+ class RiskConfig:
227
+ """Risk management parameters."""
228
+ # Depeg detection thresholds
229
+ usdy_depeg_threshold: float = 0.005 # USDY/USD deviation > 0.5%
230
+ meth_depeg_threshold: float = 0.02 # mETH/ETH deviation > 2%
231
+
232
+ # Circuit breakers
233
+ circuit_breaker_cooldown_hours: int = 24
234
+ emergency_exit_to: str = "USDC" # flee to stablecoin on emergency
235
+
236
+ # Smart contract risk scores (0-1, higher = riskier)
237
+ protocol_risk_scores: Dict[str, float] = field(default_factory=lambda: {
238
+ "USDY": 0.15, # Ondo β€” audited, regulated, low risk
239
+ "mETH": 0.25, # Mantle LSP β€” battle-tested but smart contract risk
240
+ "MI4": 0.30, # Securitize β€” newer product, moderate risk
241
+ "Aave": 0.10, # Heavily audited
242
+ "Fluxion": 0.35, # Newer DEX, higher risk
243
+ })
244
+
245
+ # Volatility lookback
246
+ volatility_window_days: int = 30
247
+ correlation_window_days: int = 90
248
+
249
+
250
+ @dataclass
251
+ class RLConfig:
252
+ """Reinforcement Learning hyperparameters."""
253
+ # PPO parameters
254
+ learning_rate: float = 3e-4
255
+ gamma: float = 0.99 # discount factor
256
+ gae_lambda: float = 0.95 # GAE lambda
257
+ clip_range: float = 0.2 # PPO clip
258
+ entropy_coef: float = 0.01 # exploration bonus
259
+ value_coef: float = 0.5
260
+ max_grad_norm: float = 0.5
261
+
262
+ # Training
263
+ n_steps: int = 2048
264
+ batch_size: int = 64
265
+ n_epochs: int = 10
266
+ total_timesteps: int = 1_000_000
267
+
268
+ # State space dimension
269
+ state_dim: int = 15 # yield rates, prices, volatilities, portfolio weights, macro
270
+ action_dim: int = 3 # weights for [USDY, mETH, MI4]
271
+
272
+ # Environment
273
+ episode_length_days: int = 30
274
+ reward_scaling: float = 100.0 # scale small yield differences
275
+
276
+
277
+ # ─────────────────────────── API Endpoints ──────────────────────────
278
+
279
+ class APIEndpoints:
280
+ """External data source endpoints."""
281
+ DEFILLAMA_YIELDS = "https://yields.llama.fi/pools"
282
+ DEFILLAMA_PROTOCOL = "https://api.llama.fi/protocol/{protocol}"
283
+ DEFILLAMA_TVL = "https://api.llama.fi/tvl/{protocol}"
284
+
285
+ COINGECKO_PRICE = "https://api.coingecko.com/api/v3/simple/price"
286
+ COINGECKO_HISTORY = "https://api.coingecko.com/api/v3/coins/{coin_id}/market_chart"
287
+
288
+ BYBIT_TICKER = "https://api.bybit.com/v5/market/tickers"
289
+ BYBIT_KLINE = "https://api.bybit.com/v5/market/kline"
290
+
291
+ # Federal Reserve data
292
+ FRED_API = "https://api.stlouisfed.org/fred/series/observations"
293
+
294
+ # Mantle-specific
295
+ MANTLE_SUBGRAPH = "https://subgraph.mantle.xyz/subgraphs/name/{name}"
296
+
297
+
298
+ # ─────────────────────────── Logging Config ─────────────────────────
299
+
300
+ LOG_FORMAT = "%(asctime)s | %(name)-20s | %(levelname)-7s | %(message)s"
301
+ LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
302
+ LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
303
+
304
+ # ─────────────────────────── ERC-8004 Agent Identity ────────────────
305
+
306
+ ERC8004_CAPABILITIES = [
307
+ "yield_optimization",
308
+ "portfolio_rebalancing",
309
+ "risk_assessment",
310
+ "market_analysis",
311
+ "strategy_reporting",
312
+ ]
313
+
314
+ AGENT_METADATA = {
315
+ "name": "Dynamic RWA Yield Router",
316
+ "version": "1.0.0",
317
+ "description": "Autonomous AI agent for yield-optimized RWA portfolio management on Mantle",
318
+ "chain_id": MANTLE_CHAIN_ID,
319
+ "supported_assets": ["USDY", "mETH", "MI4"],
320
+ "risk_framework": "risk-parity-adaptive",
321
+ "rl_algorithm": "PPO",
322
+ }