@@ -26,15 +26,8 @@ func NewBalancesCmd() *cobra.Command {
2626 RunE : runBalances ,
2727 }
2828
29- cmd .Flags ().String ("chain-ids" , "" , "Comma-separated chain IDs or tags (default: all default chains)" )
30- cmd .Flags ().String ("filters" , "" , "Token filter: erc20 or native" )
29+ addBalanceFlags (cmd )
3130 cmd .Flags ().String ("asset-class" , "" , "Asset class filter: stablecoin" )
32- cmd .Flags ().String ("metadata" , "" , "Extra metadata fields: logo,url,pools" )
33- cmd .Flags ().Bool ("exclude-spam" , false , "Exclude tokens with <100 USD liquidity" )
34- cmd .Flags ().String ("historical-prices" , "" , "Hour offsets for historical prices (e.g. 720,168,24)" )
35- cmd .Flags ().Int ("limit" , 0 , "Max results (1-1000)" )
36- cmd .Flags ().String ("offset" , "" , "Pagination cursor from previous response" )
37- output .AddFormatFlag (cmd , "text" )
3831
3932 return cmd
4033}
@@ -70,6 +63,30 @@ type warningEntry struct {
7063}
7164
7265func runBalances (cmd * cobra.Command , args []string ) error {
66+ return runBalancesEndpoint (cmd , args , "/v1/evm/balances/" , "" )
67+ }
68+
69+ // addBalanceFlags registers the common flags shared by the balances and
70+ // stablecoins commands.
71+ func addBalanceFlags (cmd * cobra.Command ) {
72+ cmd .Flags ().String ("chain-ids" , "" , "Comma-separated chain IDs or tags (default: all default chains)" )
73+ cmd .Flags ().String ("filters" , "" , "Token filter: erc20 or native" )
74+ cmd .Flags ().String ("metadata" , "" , "Extra metadata fields: logo,url,pools" )
75+ cmd .Flags ().Bool ("exclude-spam" , false , "Exclude tokens with <100 USD liquidity" )
76+ cmd .Flags ().String ("historical-prices" , "" , "Hour offsets for historical prices (e.g. 720,168,24)" )
77+ cmd .Flags ().Int ("limit" , 0 , "Max results (1-1000)" )
78+ cmd .Flags ().String ("offset" , "" , "Pagination cursor from previous response" )
79+ output .AddFormatFlag (cmd , "text" )
80+ }
81+
82+ // runBalancesEndpoint is the shared run implementation for the balances and
83+ // stablecoins commands. The final API path is built as:
84+ //
85+ // pathPrefix + address + pathSuffix
86+ //
87+ // For example "/v1/evm/balances/" + addr + "" for balances,
88+ // or "/v1/evm/balances/" + addr + "/stablecoins" for stablecoins.
89+ func runBalancesEndpoint (cmd * cobra.Command , args []string , pathPrefix , pathSuffix string ) error {
7390 client := SimClientFromCmd (cmd )
7491 if client == nil {
7592 return fmt .Errorf ("sim client not initialized" )
@@ -84,6 +101,8 @@ func runBalances(cmd *cobra.Command, args []string) error {
84101 if v , _ := cmd .Flags ().GetString ("filters" ); v != "" {
85102 params .Set ("filters" , v )
86103 }
104+ // asset-class is only registered on the balances command; silently ignored
105+ // when the flag is absent.
87106 if v , _ := cmd .Flags ().GetString ("asset-class" ); v != "" {
88107 params .Set ("asset_class" , v )
89108 }
@@ -103,7 +122,7 @@ func runBalances(cmd *cobra.Command, args []string) error {
103122 params .Set ("offset" , v )
104123 }
105124
106- data , err := client .Get (cmd .Context (), "/v1/evm/balances/" + address , params )
125+ data , err := client .Get (cmd .Context (), pathPrefix + address + pathSuffix , params )
107126 if err != nil {
108127 return err
109128 }
0 commit comments