Adds Yuval's solution
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/GreedyDecomposerTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/GreedyDecomposerTests.cs
@@ -32,7 +32,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
public void Decompose1Test(long amount, long[] expected)
{
var decomposer = new GreedyDecomposer(new Money[] { new(1L), new(2L), new(5L), new(10L) });
- var amounts = decomposer.Decompose(Money.Satoshis(amount));
+ var amounts = decomposer.Decompose(Money.Satoshis(amount), new FeeRate(0L));
Assert.Equal(Money.Satoshis(amount), amounts.Sum());
Assert.Equal(expected, amounts.Select(x => x.Satoshi));
}
@@ -62,7 +62,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
public void Decompose2Test(long amount, long[] expected)
{
var decomposer = new GreedyDecomposer(new Money[] { new(1L), new(3L), new(11L) });
- var amounts = decomposer.Decompose(Money.Satoshis(amount));
+ var amounts = decomposer.Decompose(Money.Satoshis(amount), new FeeRate(0L));
Assert.Equal(Money.Satoshis(amount), amounts.Sum());
Assert.Equal(expected, amounts.Select(x => x.Satoshi));
}

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
WalletWasabi/WabiSabi/Client/CoinJoinClient.cs
@@ -157,11 +157,11 @@ namespace WalletWasabi.WabiSabi.Client
private IEnumerable<Money> DecomposeAmounts(FeeRate feeRate, IEnumerable<Money>? forcedOutputDenominations = null)
{
- var allDenominations = forcedOutputDenominations is null ? BaseDenominationGenerator.Generate() : forcedOutputDenominations;
+ var allDenominations = forcedOutputDenominations is null ? StandardDenomination.Values : forcedOutputDenominations;
GreedyDecomposer greedyDecomposer = new(allDenominations);
- var amounts = Coins.Select(c => c.EffectiveValue(feeRate));
+ var amounts = Coins.Select(c => c.Amount);
var sum = amounts.Sum();
- var denominations = greedyDecomposer.Decompose(sum);
+ var denominations = greedyDecomposer.Decompose(sum, feeRate);
if (sum != denominations.Sum())
{
throw new InvalidOperationException("Decomposed amounts and inputs sum not equal.");

MODIFY
WalletWasabi/WabiSabi/Client/GreedyDecomposer.cs
WalletWasabi/WabiSabi/Client/GreedyDecomposer.cs
@@ -17,7 +17,7 @@ namespace WalletWasabi.WabiSabi.Client
public ImmutableList<Money> Denominations { get; }
- public IEnumerable<Money> Decompose(Money amount)
+ public IEnumerable<Money> Decompose(Money amount, FeeRate feeRate)
{
var i = 0;
var denomination = Denominations[i];
@@ -26,7 +26,7 @@ namespace WalletWasabi.WabiSabi.Client
if (denomination <= amount)
{
yield return denomination;
- amount -= denomination;
+ amount -= denomination + feeRate.GetFee(31); // TODO how to determine output size?;
}
else if ((i + 1) < Denominations.Count)
{

Adds Yuval's solution