Exponential.sol
View Source: contracts/Exponential.sol
↗ Extends: ErrorReporter, CarefulMath ↘ Derived Contracts: AlkemiEarnPublic, AlkemiEarnVerified, AlkemiRateModel, ExchangeRateModel, PriceOracle
Structs
Exp
struct Exp {
uint256 mantissa
}Contract Members
Constants & Variables
uint256 internal constant expScale;
uint256 internal constant halfExpScale;
uint256 internal constant mantissaOne;
uint256 internal constant mantissaOneTenth;Functions
getExp(uint256 num, uint256 denom)
addExp(struct Exponential.Exp a, struct Exponential.Exp b)
subExp(struct Exponential.Exp a, struct Exponential.Exp b)
mulScalar(struct Exponential.Exp a, uint256 scalar)
divScalar(struct Exponential.Exp a, uint256 scalar)
divScalarByExp(uint256 scalar, struct Exponential.Exp divisor)
mulExp(struct Exponential.Exp a, struct Exponential.Exp b)
divExp(struct Exponential.Exp a, struct Exponential.Exp b)
truncate(struct Exponential.Exp exp)
lessThanExp(struct Exponential.Exp left, struct Exponential.Exp right)
lessThanOrEqualExp(struct Exponential.Exp left, struct Exponential.Exp right)
greaterThanExp(struct Exponential.Exp left, struct Exponential.Exp right)
isZeroExp(struct Exponential.Exp value)
getExp
Creates an exponential from numerator and denominator values. Note: Returns an error if (num * 10e18) > MAX_INT, or if denom is zero.
Arguments
Name
Type
Description
num
uint256
denom
uint256
addExp
Adds two exponentials, returning a new exponential.
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp
subExp
Subtracts two exponentials, returning a new exponential.
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp
mulScalar
Multiply an Exp by a scalar, returning a new Exp.
Arguments
Name
Type
Description
a
struct Exponential.Exp
scalar
uint256
divScalar
Divide an Exp by a scalar, returning a new Exp.
Arguments
Name
Type
Description
a
struct Exponential.Exp
scalar
uint256
divScalarByExp
Divide a scalar by an Exp, returning a new Exp.
Arguments
Name
Type
Description
scalar
uint256
divisor
struct Exponential.Exp
mulExp
Multiplies two exponentials, returning a new exponential.
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp
divExp
Divides two exponentials, returning a new exponential. (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b, which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp
truncate
Truncates the given exp to a whole number value. For example, truncate(Exp{mantissa: 15 (10*18)}) = 15
Arguments
Name
Type
Description
exp
struct Exponential.Exp
lessThanExp
Checks if first Exp is less than second Exp.
Arguments
Name
Type
Description
left
struct Exponential.Exp
right
struct Exponential.Exp
lessThanOrEqualExp
Checks if left Exp <= right Exp.
Arguments
Name
Type
Description
left
struct Exponential.Exp
right
struct Exponential.Exp
greaterThanExp
Checks if first Exp is greater than second Exp.
Arguments
Name
Type
Description
left
struct Exponential.Exp
right
struct Exponential.Exp
isZeroExp
returns true if Exp is exactly zero
Arguments
Name
Type
Description
value
struct Exponential.Exp
Last updated
Was this helpful?