@@ -221,6 +221,7 @@ def cmd_fetch(args: argparse.Namespace) -> None:
221221def generate_cdc (data : dict ) -> str :
222222 scenario = data ["scenario" ]
223223 is_daily = "duration_days" in data
224+ prices = data .get ("prices" ) or data ["btc_prices" ]
224225
225226 lines : list [str ] = []
226227 lines .append ("import Test" )
@@ -293,8 +294,8 @@ def generate_cdc(data: dict) -> str:
293294
294295 # --- Price array ---
295296 lines .append (f"access(all) let { scenario } _prices: [UFix64] = [" )
296- for i , price in enumerate (data [ "btc_prices" ] ):
297- comma = "," if i < len (data [ "btc_prices" ] ) - 1 else ""
297+ for i , price in enumerate (prices ):
298+ comma = "," if i < len (prices ) - 1 else ""
298299 lines .append (f" { to_ufix64 (price )} { comma } " )
299300 lines .append ("]" )
300301 lines .append ("" )
@@ -308,28 +309,7 @@ def generate_cdc(data: dict) -> str:
308309 lines .append ("]" )
309310 lines .append ("" )
310311
311- # --- Agent array ---
312- lines .append (f"access(all) let { scenario } _agents: [SimAgent] = [" )
313- for i , agent in enumerate (data ["agents" ]):
314- comma = "," if i < len (data ["agents" ]) - 1 else ""
315- debt = (
316- agent ["debt_per_agent" ]
317- if isinstance (agent ["debt_per_agent" ], (int , float ))
318- else 0
319- )
320- total_debt = agent .get ("total_system_debt" , 0 )
321- lines .append (" SimAgent(" )
322- lines .append (f" count: { agent ['count' ]} ," )
323- lines .append (f" initialHF: { to_ufix64 (agent ['initial_hf' ])} ," )
324- lines .append (f" rebalancingHF: { to_ufix64 (agent ['rebalancing_hf' ])} ," )
325- lines .append (f" targetHF: { to_ufix64 (agent ['target_hf' ])} ," )
326- lines .append (f" debtPerAgent: { to_ufix64 (float (debt ))} ," )
327- lines .append (f" totalSystemDebt: { to_ufix64 (float (total_debt ))} " )
328- lines .append (f" ){ comma } " )
329- lines .append ("]" )
330- lines .append ("" )
331-
332- # --- Pool dict ---
312+ # --- Pool dict (before agents so scenarios read nicely) ---
333313 lines .append (f"access(all) let { scenario } _pools: {{String: SimPool}} = {{" )
334314 pool_items = list (data ["pools" ].items ())
335315 for i , (name , pool ) in enumerate (pool_items ):
@@ -354,28 +334,42 @@ def generate_cdc(data: dict) -> str:
354334 lines .append (")" )
355335 lines .append ("" )
356336
357- # --- Expected outcomes ---
358- e = data ["expected" ]
359- lines .append (
360- f"access(all) let { scenario } _expectedLiquidationCount: Int = { e ['liquidation_count' ]} "
361- )
362- lines .append (
363- f"access(all) let { scenario } _expectedAllAgentsSurvive: Bool = { 'true' if e ['all_agents_survive' ] else 'false' } "
364- )
365- lines .append ("" )
366-
367337 # --- Duration & notes ---
368338 if is_daily :
369- lines .append (
370- f"access(all) let { scenario } _durationDays: Int = { data ['duration_days' ]} "
371- )
372- else :
373- lines .append (
374- f"access(all) let { scenario } _durationMinutes: Int = { data ['duration_minutes' ]} "
375- )
376- lines .append (f'access(all) let { scenario } _notes: String = "{ data ["notes" ]} "' )
339+ lines .append (f"access(all) let { scenario } _durationDays: Int = { data ['duration_days' ]} " )
340+ elif "duration_minutes" in data :
341+ lines .append (f"access(all) let { scenario } _durationMinutes: Int = { data ['duration_minutes' ]} " )
342+ if "notes" in data :
343+ lines .append (f'access(all) let { scenario } _notes: String = "{ data ["notes" ]} "' )
377344 lines .append ("" )
378345
346+ # --- Agents & expected outcomes (supports multi-scenario via "scenarios" key) ---
347+ def _emit_agents_and_expected (prefix , agents , expected ):
348+ lines .append (f"access(all) let { prefix } _agents: [SimAgent] = [" )
349+ for i , agent in enumerate (agents ):
350+ comma = "," if i < len (agents ) - 1 else ""
351+ debt = agent ["debt_per_agent" ] if isinstance (agent ["debt_per_agent" ], (int , float )) else 0
352+ total_debt = agent .get ("total_system_debt" , 0 )
353+ lines .append (" SimAgent(" )
354+ lines .append (f" count: { agent ['count' ]} ," )
355+ lines .append (f" initialHF: { to_ufix64 (agent ['initial_hf' ])} ," )
356+ lines .append (f" rebalancingHF: { to_ufix64 (agent ['rebalancing_hf' ])} ," )
357+ lines .append (f" targetHF: { to_ufix64 (agent ['target_hf' ])} ," )
358+ lines .append (f" debtPerAgent: { to_ufix64 (float (debt ))} ," )
359+ lines .append (f" totalSystemDebt: { to_ufix64 (float (total_debt ))} " )
360+ lines .append (f" ){ comma } " )
361+ lines .append ("]" )
362+ lines .append ("" )
363+ lines .append (f"access(all) let { prefix } _expectedLiquidationCount: Int = { expected ['liquidation_count' ]} " )
364+ lines .append (f"access(all) let { prefix } _expectedAllAgentsSurvive: Bool = { 'true' if expected ['all_agents_survive' ] else 'false' } " )
365+ lines .append ("" )
366+
367+ if "scenarios" in data :
368+ for sub in data ["scenarios" ]:
369+ _emit_agents_and_expected (f"{ scenario } _{ sub ['name' ]} " , sub ["agents" ], sub ["expected" ])
370+ else :
371+ _emit_agents_and_expected (scenario , data ["agents" ], data ["expected" ])
372+
379373 return "\n " .join (lines )
380374
381375
@@ -390,8 +384,8 @@ def cmd_generate(args: argparse.Namespace) -> None:
390384 f .write (cdc )
391385
392386 scenario = data ["scenario" ]
393- n_prices = len ( data ["btc_prices" ])
394- print (f"Generated { args .output } ({ n_prices } prices, scenario: { scenario } )" )
387+ prices = data . get ( "prices" ) or data ["btc_prices" ]
388+ print (f"Generated { args .output } ({ len ( prices ) } prices, scenario: { scenario } )" )
395389
396390
397391# ---------------------------------------------------------------------------
0 commit comments