Skip to content

Currency refactor - #31

Merged
shroominic merged 18 commits into
masterfrom
currency-refactor
Jul 19, 2025
Merged

Currency refactor#31
shroominic merged 18 commits into
masterfrom
currency-refactor

rm debug prints

3108320
Select commit
Loading
Failed to load commit list.
Cursor / Cursor BugBot completed Jul 19, 2025 in 4m 9s

BugBot Review

BugBot Analysis Progress (4m 11s elapsed)

✅ Gathered PR context (1s)
✅ Analyzed code changes (0s)
✅ Completed bug detection — 3 potential bugs found (4m 7s)
✅ Validation and filtering completed (0s)
✅ Posted analysis results — 3 bugs reported (2s)
✅ Analysis completed successfully (0s)

Final Result: BugBot completed review and found 3 potential issues

Request ID: serverGenReqId_70b2ea38-e602-4951-bf5e-59ab4b417c5b

Details

Bug: Undefined Methods Cause Balance Calculation Errors

The total_balance_sat method in WalletState and the sats_value_of_proofs function in Wallet attempt to call undefined melt_exchange_rate and mint_exchange_rate methods, respectively, on Mint objects when processing non-BTC proofs. This causes an AttributeError and prevents accurate balance calculation. Additionally, Mint instances are created in a loop without proper cleanup, leading to resource leaks.

sixty_nuts/types.py#L142-L159

async def total_balance_sat(self, include_shitnuts: bool = False) -> int:
"""Get total balance in satoshis (only BTC-based currencies)."""
total_sats = 0
for proof in self.proofs:
if proof["unit"] == "sat":
total_sats += proof["amount"]
elif proof["unit"] == "msat":
total_sats += proof["amount"] // 1000
elif include_shitnuts:
from .mint import Mint
mint = Mint(proof["mint"])
exchange_rate = await mint.melt_exchange_rate(proof["unit"])
# Apply 0.99 multiplier as rough estimate for fees (1% buffer)
total_sats += int(proof["amount"] * exchange_rate * 0.99)
return total_sats

sixty_nuts/wallet.py#L2735-L2737

else:
exchange_rate = await Mint(proof["mint"]).mint_exchange_rate(proof["unit"])
total_sats += int(proof["amount"] * exchange_rate)

Fix in CursorFix in Web


Bug: Bitcoin Exchange Rate Method Inverts Values

The melt_exchange_rate method returns inverted exchange rates for Bitcoin units. For "sat", it incorrectly returns 1000 instead of 1. For "msat", it incorrectly returns 1 instead of 0.001. This results in incorrect currency conversions.

sixty_nuts/mint.py#L391-L398

"""
# TODO: include mint fee in exchange rate calculation
PRECISION_FACTOR = 100_000
if unit == "sat":
return 1000
elif unit == "msat":
return 1
elif unit in await self.get_currencies():

Fix in CursorFix in Web


Bug: Mint Quote Creation Fails Without Currencies

An IndexError occurs in Mint.create_mint_quote and Mint.create_melt_quote methods when the unit parameter is None. This happens because the code attempts to access currencies[0] from the list of available currencies without checking if the list is empty, leading to an error if the mint provides no currencies.

sixty_nuts/mint.py#L433-L434

else:
unit = currencies[0]

sixty_nuts/mint.py#L490-L491

else:
unit = currencies[0]

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎