File tree Expand file tree Collapse file tree
src/omniclaw/protocols/nanopayments Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -754,7 +754,7 @@ async def check_balance(
754754 """
755755 await self .get_supported ()
756756
757- _caip2_to_circle_domain_id (network )
757+ expected_domain = _caip2_to_circle_domain_id (network )
758758 body : dict [str , Any ] = {
759759 "token" : "USDC" ,
760760 "sources" : [
@@ -789,7 +789,19 @@ async def check_balance(
789789 formatted_total = "0 USDC"
790790 formatted_available = "0 USDC"
791791 if balances :
792- bal = balances [0 ]
792+ depositor_lc = address .lower ()
793+
794+ # Circle may return multiple domains; never assume index 0 is the requested network.
795+ by_depositor = [
796+ b
797+ for b in balances
798+ if str (b .get ("depositor" , "" )).lower () == depositor_lc or not b .get ("depositor" )
799+ ]
800+ by_domain = [
801+ b for b in by_depositor if int (_to_int (b .get ("domain" , 0 ))) == expected_domain
802+ ]
803+ bal = by_domain [0 ] if by_domain else (by_depositor [0 ] if by_depositor else balances [0 ])
804+
793805 # Circle returns "balance" field with string amount, no separate available field
794806 balance_str = bal .get ("balance" , "0" )
795807 total = _to_int (balance_str )
You can’t perform that action at this time.
0 commit comments