BSIP38: update variable names for rounding

This commit is contained in:
Abit 2018-04-16 01:43:37 +02:00 committed by GitHub
parent a1e5901540
commit f817f1d886
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -118,19 +118,23 @@ target collateral ratio. Which means if `max_debt_to_cover` has no
fractional component (e.g. 5.00 as opposed to 5.23), need to plus it by one
Satoshi; otherwise, need to round it up.
An effectively same approach is to round down then add one Satoshi onto the
result.
result:
With `max_debt_to_cover` in integer, `max_amount_to_sell` in integer should be
```
max_debt_to_cover_int = round_down(max_debt_to_cover) + 1
```
With `max_debt_to_cover_int` in integer, `max_amount_to_sell_int` in integer should be
calculated as:
```
max_amount_to_sell = round_up(max_debt_to_cover / match_price)
max_amount_to_sell_int = round_up(max_debt_to_cover_int / match_price)
```
Then adjust `max_debt_to_cover` to be more accurate with:
Then adjust `max_debt_to_cover_int` to be more accurate with:
```
max_debt_to_cover = round_down(max_amount_to_sell * match_price)
max_debt_to_cover_int = round_down(max_amount_to_sell_int * match_price)
```
## Rounding on Order Matching, and Edge Cases
@ -142,7 +146,7 @@ the larger order while rounding.
When a call order got matched with a limit order, if the call order has no
`target_CR` option set but its debt is more than the limit order offered,
or the call order has `target_CR` option set but `max_debt_to_cover`
or the call order has `target_CR` option set but `max_debt_to_cover_int`
is more than the limit order offered, both means the call order is larger,
according to the rounding rule, the call order's paid collateral will be
rounded down, so its collateral ratio will increase after partially filled.