Skip to content

Commit f3ffcf5

Browse files
committed
Fix gateway balance selection by domain in check_balance
1 parent 991cc6e commit f3ffcf5

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
@@ -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)

0 commit comments

Comments
 (0)