How to calc the price for token pair according to decimals usage in tokens in Predicate?

I have written predicate code for my order book with the following logic.

In this predicate, I calc the token price where I consider that tokens decimals can be different so I have to convert the price to have decimals 9. I calculate price using this formula

amount1 * 10.pow(price_decimals + asset0_decimals - asset1_decimals) / amount0

But the U128 standard is implementing pow and divide functions with while cycle usage, predicates are now allowed to use while

After that I decided to make the price decimal smaller in order to use u64, but there is no implementation of the point of view function

Is there any ideas how to calc price in predicate with another way?

1 Like

This feature was just released recently: Allow loops in predicates by IGI-111 · Pull Request #4526 · FuelLabs/sway · GitHub . You would have to use the master branch for this.

1 Like

Thanks, will try master version today!!

Is there any tutorial on how to use forc version from master?

You can use the nightly toolchain channel with fuelup: nightly - fuelup