-
Description: Currently, Example (current): UD60x18 targetCL = ud(mulDiv(TVL.mul(ud(weight)).unwrap(), longLeverage.unwrap(), price.unwrap())); Proposed Solution: Add an overloaded version of Example (proposed): UD60x18 targetCL = mulDiv(TVL.mul(ud(weight)), longLeverage, price); This enhancement would be especially valuable when chaining multiple fixed-point operations, as it helps reduce boilerplate and potential errors. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi @ivanvolov, thanks for your question. Could you please help me understand why you cannot use the UD60x18 a = TVL.mul(ud(weight));
UD60x18 b = a.mul(longLeverage);
UD60x18 c = b.div(price);
uint256 result = c.unwrap(); or, more succinctly: uint256 result = TVL.mul(ud(weight)).mul(longLeverage).div(price).unwrap();
`mulDiv` is an internal component that is by design not meant to be relied upon by end users.
The code in your example doesn't actually use 18-decimal numbers, but this is the very purpose of using `UD60x18` (and catch errors at build time!). |
Beta Was this translation helpful? Give feedback.
-
Created issue to track this: #260 |
Beta Was this translation helpful? Give feedback.
As per a private chat on Telegram, I was wrong when I said:
Phantom overflow can be an issue when operating with large values near the maximum
uint256
value, e.g.In light of this, I am now in favor of implementing a
mulDiv
function that takes onlyUD60x18
as inputs and outputs.