+class Wealth:
+ """Collects amounts mapped to currencies."""
+
+ def __init__(self, moneys: Optional[dict[str, Decimal]] = None) -> None:
+ self.moneys = moneys if moneys else {}
+
+ def _inc_by(self, other: Self, add=True) -> Self:
+ for currency, amount in other.moneys.items():
+ if currency not in self.moneys:
+ self.moneys[currency] = Decimal(0)
+ self.moneys[currency] += amount if add else -amount
+ return self
+
+ def __iadd__(self, other: Self) -> Self:
+ return self._inc_by(other, True)
+
+ def __isub__(self, other: Self) -> Self:
+ return self._inc_by(other, False)
+
+ @property
+ def sink_empty(self) -> bool:
+ """Return if all evens out to zero."""
+ return not bool(self.as_sink.moneys)
+
+ @property
+ def as_sink(self) -> 'Wealth':
+ """Drop zero amounts, invert non-zero ones."""
+ sink = Wealth()
+ for moneys in [Wealth({c: a}) for c, a in self.moneys.items() if a]:
+ sink = moneys
+ return sink
+
+