Encoding and Decoding Special Data Types
Some data in the ReserveManager contract are stored with fewer than 128 bits of precision to allow more efficient storage access and reduce gas consumption.
To convert these values to 128.128 fixed-point format, multiply them by:
2^(TARGET_FRACTIONAL_BITS - ORIGINAL_FRACTIONAL_BITS).
For example, converting a 0.32 value to 128.128 requires multiplying by 2^(128 - 32).
Fixed-Point Notation Reminder
Fixed-point precision is written in the form X.Y, where:
- X is the number of bits for the integer portion
- Y is the number of bits for the fractional portion
So a fixed-point format labeled 69.420 means:
- 69 bits for the integer component
- 420 bits for the fractional component
For a list of special data types, see /api/data-types.mdx.
Example: AssetParams Struct
To retrieve and decode the configuration details of a specific asset:
ReserveManager.getAssetParams(ASSET_ADDRESS); //returns AssetParams data type
struct AssetParams {
address assetAddress,
uint88 allocation, // a 0.88 fixed point number
uint8 decimals
}If you want to convert allocation to 128.128 fixed-point format, use:
allocation * 2^(128 - 88)
This ensures the result is in the same precision scale the pool uses for calculations.
You’ll need to apply this scaling if you’re trying to emulate pool behavior exactly.