Skip to main content

MathUtils

Git Source Author: @oscarsernarosero @mpetersoCode55 @cirsteve

State Variables

WAD

uint256 constant WAD = 1e18;

Functions

uncheckedMultiply

This function expects the parameters to not have been multiplied by WAD, and the result will be a WAD number. This function provides an abstraction layer for division between liquidity-altbc and the underlying math library
function uncheckedMultiply(uint256 x, uint256 y) internal pure returns (uint256 result);
Parameters
NameTypeDescription
xuint256represents the first factor
yuint256represents the second factor
Returns
NameTypeDescription
resultuint256of the division operation

convertToWAD

This function converts a raw number to a WAD number
function convertToWAD(uint256 value) internal pure returns (uint256 result);
Parameters
NameTypeDescription
valueuint256The number to be converted
Returns
NameTypeDescription
resultuint256resulting WAD number

convertToRaw

This function converts a WAD number to a raw number
function convertToRaw(uint256 value) internal pure returns (uint256 result);
Parameters
NameTypeDescription
valueuint256The number to be converted
Returns
NameTypeDescription
resultuint256resulting raw number

findWADsToSlashTo0

this function tells how many WADs a number needs to be divided by to get to 0
function findWADsToSlashTo0(uint256 x) internal pure returns (uint256 precisionSlashingFactor);
Parameters
NameTypeDescription
xuint256the number to be divided
Returns
NameTypeDescription
precisionSlashingFactoruint256the number of WADs needed to be divided to get to 0

convertToRaw512

this function requires a0 to be greater than 0 and less or equal than 2**254 Divides a 512 bit unsigned integer by WAD where the result can be a 512 bit unsigned integer.
function convertToRaw512(uint256 a0, uint256 a1) internal pure returns (uint256 r0, uint256 r1);
Parameters
NameTypeDescription
a0uint256A uint256 representing the low bits of the numerator
a1uint256A uint256 representing the high bits of the numerator
Returns
NameTypeDescription
r0uint256The lower bits of the result
r1uint256The highre bits of the result