Skip to content

Commit 4c59909

Browse files
authored
Merge branch 'main' into core-buyer-infra-cleanup
2 parents ff12c33 + b0e344f commit 4c59909

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/omniclaw/protocols/nanopayments/client.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ async def check_balance(
762762
"""
763763
await self.get_supported()
764764

765-
domain_id = _caip2_to_circle_domain_id(network)
765+
expected_domain = _caip2_to_circle_domain_id(network)
766766
body: dict[str, Any] = {
767767
"token": "USDC",
768768
"sources": [
@@ -797,7 +797,19 @@ async def check_balance(
797797
formatted_total = "0 USDC"
798798
formatted_available = "0 USDC"
799799
if balances:
800-
bal = _select_gateway_balance(balances, domain_id)
800+
depositor_lc = address.lower()
801+
802+
# Circle may return multiple domains; never assume index 0 is the requested network.
803+
by_depositor = [
804+
b
805+
for b in balances
806+
if str(b.get("depositor", "")).lower() == depositor_lc or not b.get("depositor")
807+
]
808+
by_domain = [
809+
b for b in by_depositor if int(_to_int(b.get("domain", 0))) == expected_domain
810+
]
811+
bal = by_domain[0] if by_domain else (by_depositor[0] if by_depositor else balances[0])
812+
801813
# Circle returns "balance" field with string amount, no separate available field
802814
balance_str = bal.get("balance", "0")
803815
total = _to_int(balance_str)

0 commit comments

Comments
 (0)