Skip to content

Latest commit

 

History

History
254 lines (177 loc) · 6.12 KB

exponential.md

File metadata and controls

254 lines (177 loc) · 6.12 KB
layout title
default
Exponential

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.

function getExp(uint256 num, uint256 denom) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

Arguments

Name Type Description
num uint256
denom uint256

addExp

Adds two exponentials, returning a new exponential.

function addExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

Arguments

Name Type Description
a struct Exponential.Exp
b struct Exponential.Exp

subExp

Subtracts two exponentials, returning a new exponential.

function subExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

Arguments

Name Type Description
a struct Exponential.Exp
b struct Exponential.Exp

mulScalar

Multiply an Exp by a scalar, returning a new Exp.

function mulScalar(struct Exponential.Exp a, uint256 scalar) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

Arguments

Name Type Description
a struct Exponential.Exp
scalar uint256

divScalar

Divide an Exp by a scalar, returning a new Exp.

function divScalar(struct Exponential.Exp a, uint256 scalar) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

Arguments

Name Type Description
a struct Exponential.Exp
scalar uint256

divScalarByExp

Divide a scalar by an Exp, returning a new Exp.

function divScalarByExp(uint256 scalar, struct Exponential.Exp divisor) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

Arguments

Name Type Description
scalar uint256
divisor struct Exponential.Exp

mulExp

Multiplies two exponentials, returning a new exponential.

function mulExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

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)

function divExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)

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

function truncate(struct Exponential.Exp exp) internal pure
returns(uint256)

Arguments

Name Type Description
exp struct Exponential.Exp

lessThanExp

Checks if first Exp is less than second Exp.

function lessThanExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
returns(bool)

Arguments

Name Type Description
left struct Exponential.Exp
right struct Exponential.Exp

lessThanOrEqualExp

Checks if left Exp <= right Exp.

function lessThanOrEqualExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
returns(bool)

Arguments

Name Type Description
left struct Exponential.Exp
right struct Exponential.Exp

greaterThanExp

Checks if first Exp is greater than second Exp.

function greaterThanExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
returns(bool)

Arguments

Name Type Description
left struct Exponential.Exp
right struct Exponential.Exp

isZeroExp

returns true if Exp is exactly zero

function isZeroExp(struct Exponential.Exp value) internal pure
returns(bool)

Arguments

Name Type Description
value struct Exponential.Exp