0

I am creating a uniswapv2 contract clone. I am not able to understand how they have encoded 0.03% swap fee since smart contracts can't handle floating point numbers?

Overall I want to know how to specify such floating point numbers in smart contracts.

2
  • i don't know how uniswapv2 handle 0.03%, but you can use basis points to handle floating number percentage : 100% -> 10000 basis points, so 0.03% is 3 basis points .
    – noro meb
    Jan 8 at 11:02
  • Read the docs. Look for deployment addresses, locate how the fee is represented in the smart contract, and change it. If you handle money, you must understand what you're doing docs.uniswap.org/contracts/v2/concepts/advanced-topics/fees Jan 8 at 12:10

1 Answer 1

0

In the case of Uniswap, the swap fee is specified as a percentage, so it is stored as a fractional value. For example, a 3% fee would be stored as 3/100 = 0.03.

You can use the fixed type, which represents a fixed point decimal number with a specified number of decimal places. For example, to specify a number with 3 decimal places, you can use the fixed128x18 type, which represents a 128-bit fixed point number with 18 decimal places.

The fixed type was introduced in Solidity version 0.5.0, so you will need to use a version of Solidity that is at least 0.5.0 to use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.