tdex-network / tdex-daemon

Go implementation of the TDEX Beta Daemon
https://tdex.network
MIT License
11 stars 13 forks source link

Fix preview amounts after supporting precisions #674

Closed altafan closed 1 year ago

altafan commented 1 year ago

This updates the marketmaking Formula interface in order to express numbers via decimal.Decimals instead of uint64s.

Before this change the the formula interface was designed to support satoshis, but this becomes problematic after supporting market assets precision. By changing the representation to decimal.Decimal, balances and amounts can be scaled by asset precision before and after applying a formula to calculate a preview amount (in domain layer).

This adds test cases to make sure the applied change work as expected.

This also simplify the calc of the min tradable amount of SpotPrice by applying the following formula:

mkt.FixedFee.BaseFee > 0 -> minTradableAmount = mkt.FixedFee.BaseFee+1
mkt.SpotPrice.BasePrice >= 1 -> minTradableAmount = 1
mkt.SpotPrice.BasePrice < 0 > minTradableAmount = minQuoteAmount * mkt.SpotPrice.BasePrice

where minQuoteAmount = 10^(-quoteAssetPrecision), ie. precision = 2 -> minQuoteAmount = 0,01.

Please @tiero review this.

what-the-diff[bot] commented 1 year ago