55import asyncio
66import json
77import logging
8+ import os
89from pathlib import Path
910from typing import Annotated
1011
1112import typer
12-
1313from web3 import Web3
1414
1515from .constants import (
4040
4141app = typer .Typer (
4242 add_completion = False ,
43- no_args_is_help = True ,
43+ no_args_is_help = False ,
4444 add_help_option = True ,
4545 pretty_exceptions_enable = True ,
4646 pretty_exceptions_short = True ,
4747 pretty_exceptions_show_locals = False ,
48+ rich_markup_mode = "rich" ,
4849 help = "TVL reporting and Safe submission tool." ,
4950)
5051
@@ -59,9 +60,11 @@ def _redacted_dump(settings: OracleSettings) -> dict:
5960 return settings .as_safe_dict ()
6061
6162
62- @app .callback ()
63- def initialize_context (
64- ctx : typer .Context ,
63+ @app .callback (invoke_without_command = True )
64+ def report (
65+ vault_address : Annotated [
66+ str | None , typer .Argument (help = "Vault address to report." )
67+ ] = None ,
6568 config_path : Annotated [
6669 Path | None ,
6770 typer .Option (
@@ -121,14 +124,11 @@ def initialize_context(
121124 ),
122125 ] = False ,
123126):
124- """Typer callback to initialize application state before any subcommand executes .
127+ """Build a TVL report and (optionally) submit to Safe .
125128
126- This function runs automatically before commands like 'report'. It loads configuration,
127- applies network-specific defaults, and stores the initialized AppState in ctx.obj
128- for subcommands to access.
129+ This is the default command that loads configuration, applies network-specific
130+ defaults, validates settings, and executes the TVL reporting pipeline.
129131 """
130- import os
131-
132132 if config_path :
133133 os .environ ["TQ_ORACLE_CONFIG" ] = str (config_path )
134134
@@ -183,52 +183,39 @@ def initialize_context(
183183
184184 setup_logging (settings .log_level )
185185 logger = _build_logger ()
186-
187- ctx .obj = AppState (settings = settings , logger = logger )
186+ state = AppState (settings = settings , logger = logger )
188187
189188 if show_config :
190189 typer .echo (json .dumps (_redacted_dump (settings ), indent = 2 ))
191190 raise typer .Exit (code = 0 )
192191
193-
194- @app .command ()
195- def report (
196- ctx : typer .Context ,
197- vault_address : Annotated [
198- str | None , typer .Argument (help = "Vault address to report." )
199- ] = None ,
200- ):
201- """Build a TVL report and (optionally) submit to Safe."""
202- state : AppState = ctx .obj
203- s = state .settings
204-
205192 if vault_address :
206- s .vault_address = vault_address
193+ state . settings .vault_address = vault_address
207194
208- if not s .vault_address :
195+ if not state . settings .vault_address :
209196 raise typer .BadParameter ("vault_address must be configured" )
210- if not s .vault_rpc :
197+ if not state . settings .vault_rpc :
211198 raise typer .BadParameter ("vault_rpc must be configured" )
212- if not s .oracle_helper_address :
199+ if not state . settings .oracle_helper_address :
213200 raise typer .BadParameter ("oracle_helper_address must be configured" )
214- if not s .hl_rpc :
201+ if not state . settings .hl_rpc :
215202 raise typer .BadParameter ("hl_rpc must be configured" )
216203
217- if not s .dry_run :
218- if not s .safe_address :
204+ if not state . settings .dry_run :
205+ if not state . settings .safe_address :
219206 raise typer .BadParameter (
220207 "safe_address is required when running with --no-dry-run." ,
221208 param_hint = ["--safe-address" , "TQ_ORACLE_SAFE_ADDRESS" ],
222209 )
223- if not s .private_key :
210+ if not state . settings .private_key :
224211 raise typer .BadParameter (
225212 "private_key is required when running with --no-dry-run." ,
226213 param_hint = ["--private-key" , "TQ_ORACLE_PRIVATE_KEY" ],
227214 )
228215
229216 from .pipeline .run import run_report
230217
231- asyncio .run (run_report (state , s .vault_address_required ))
218+ asyncio .run (run_report (state , state . settings .vault_address_required ))
232219
233220
234221def run () -> None :
0 commit comments