Skip to content

Currency refactor#31

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

Currency refactor#31
shroominic merged 18 commits intomasterfrom
currency-refactor

Conversation

@shroominic
Copy link
Collaborator

No description provided.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@shroominic shroominic merged commit 0653aa9 into master Jul 19, 2025
5 checks passed
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant