Onchain.Aave.Math.V4 (onchain_aave v0.2.0)

Copy Markdown View Source

Aave V4 integer-native math ports.

V4 split the V3 half-up WadRay helpers into explicit down/up variants. These functions preserve the deployed Solidity formulas for valid non-overflowing inputs while relying on BEAM arbitrary-precision integers instead of uint256 overflow reverts.

Source: aave/aave-v4 src/libraries/math/{WadRayMath,MathUtils}.sol and src/spoke/libraries/LiquidationLogic.sol.

Summary

Functions

Add a signed integer to a non-negative integer, rejecting underflow.

Convert basis points to ray scale.

Convert basis points to wad scale.

Calculate V4 linear interest between two timestamps at a ray-scaled rate.

Divide two integers, rounding up.

Remove ray precision, rounding up.

Remove wad precision, rounding down.

Return the smaller of two non-negative integers.

Multiply two integers and divide by a third, rounding down.

Multiply two integers and divide by a third, rounding up.

Divide two ray-scaled integers, rounding down.

Divide two ray-scaled integers, rounding up.

Multiply two ray-scaled integers, rounding down.

Multiply two ray-scaled integers, rounding up.

Round a ray value up to the nearest whole ray.

Cast an integer to ray scale by multiplying by 10^27.

Cast an integer to wad scale by multiplying by 10^18.

Divide two wad-scaled integers, rounding down.

Divide two wad-scaled integers, rounding up.

Multiply two wad-scaled integers, rounding down.

Multiply two wad-scaled integers, rounding up.

Subtract with a floor at zero.

Functions

add(a, b)

@spec add(non_neg_integer(), integer()) :: non_neg_integer()

Add a signed integer to a non-negative integer, rejecting underflow.

bps_to_ray(a)

@spec bps_to_ray(non_neg_integer()) :: non_neg_integer()

Convert basis points to ray scale.

bps_to_wad(a)

@spec bps_to_wad(non_neg_integer()) :: non_neg_integer()

Convert basis points to wad scale.

calculate_linear_interest(rate, last_update_timestamp, current_timestamp)

@spec calculate_linear_interest(
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer()
) ::
  non_neg_integer()

Calculate V4 linear interest between two timestamps at a ray-scaled rate.

calculate_liquidation_bonus(health_factor_for_max_bonus, liquidation_bonus_factor, health_factor, max_liquidation_bonus)

@spec calculate_liquidation_bonus(
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer()
) :: non_neg_integer()

Calculate V4's liquidation bonus from health-factor and bonus parameters.

div_up(a, b)

@spec div_up(non_neg_integer(), pos_integer()) :: non_neg_integer()

Divide two integers, rounding up.

from_ray_up(a)

@spec from_ray_up(non_neg_integer()) :: non_neg_integer()

Remove ray precision, rounding up.

from_wad_down(a)

@spec from_wad_down(non_neg_integer()) :: non_neg_integer()

Remove wad precision, rounding down.

min(a, b)

Return the smaller of two non-negative integers.

mul_div_down(a, b, c)

@spec mul_div_down(non_neg_integer(), non_neg_integer(), pos_integer()) ::
  non_neg_integer()

Multiply two integers and divide by a third, rounding down.

mul_div_up(a, b, c)

Multiply two integers and divide by a third, rounding up.

ray_div_down(a, b)

@spec ray_div_down(non_neg_integer(), pos_integer()) :: non_neg_integer()

Divide two ray-scaled integers, rounding down.

ray_div_up(a, b)

@spec ray_div_up(non_neg_integer(), pos_integer()) :: non_neg_integer()

Divide two ray-scaled integers, rounding up.

ray_mul_down(a, b)

@spec ray_mul_down(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Multiply two ray-scaled integers, rounding down.

ray_mul_up(a, b)

@spec ray_mul_up(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Multiply two ray-scaled integers, rounding up.

round_ray_up(a)

@spec round_ray_up(non_neg_integer()) :: non_neg_integer()

Round a ray value up to the nearest whole ray.

to_ray(a)

@spec to_ray(non_neg_integer()) :: non_neg_integer()

Cast an integer to ray scale by multiplying by 10^27.

to_wad(a)

@spec to_wad(non_neg_integer()) :: non_neg_integer()

Cast an integer to wad scale by multiplying by 10^18.

wad_div_down(a, b)

@spec wad_div_down(non_neg_integer(), pos_integer()) :: non_neg_integer()

Divide two wad-scaled integers, rounding down.

wad_div_up(a, b)

@spec wad_div_up(non_neg_integer(), pos_integer()) :: non_neg_integer()

Divide two wad-scaled integers, rounding up.

wad_mul_down(a, b)

@spec wad_mul_down(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Multiply two wad-scaled integers, rounding down.

wad_mul_up(a, b)

@spec wad_mul_up(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Multiply two wad-scaled integers, rounding up.

zero_floor_sub(a, b)

@spec zero_floor_sub(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Subtract with a floor at zero.