Forward-price calculation under continuous compounding. A single building block — spot · er·t — useful for marking futures, computing fair forwards, or as an input to richer derivatives.
Contract: Futures.sol
| Function | Gas | Description |
|---|---|---|
| futurePrice | 442 | Forward price: spot · e^(r·t) |
npm install defimath-lib
spot — uint128, 18-decimal fixed-point (1e18 = 1.0).timeToExp — uint32, seconds to contract expiration.rate — uint64, annualized risk-free rate as 18-decimal fixed-point.uint256 — futures price in 18-decimal fixed-point.internal pure.import "defimath-lib/contracts/derivatives/Futures.sol";
uint256 fwd = DeFiMathFutures.futurePrice(spot, timeToExp, rate);F = S · er·t. For dividend-paying assets, fold the dividend yield q into the rate as (r − q) at the call site.Every function reverts on out-of-bounds inputs with a named error — see the per-function pages for limits and error specifics.
Hardhat correctness layer. 13 tests on the single futurePrice function. Behaviour test sweeps 10 time × 20 rate = 200 samples covering t ∈ [0, 1y) and rate ∈ [0, 4) validated against spot · Math.exp(rate · t). Random test runs 200 log-uniform (spot, t, rate) triples. Limits pin behavior at SPOT_MIN, SPOT_MAX, TIME_MAX, RATE_MAX, and the expired/zero-carry corners.
Foundry property-fuzz layer. 9 mathematical properties × 32,000 random runs each = 288,000 random executions per CI run.
| Category | Count | What they check |
|---|---|---|
| Monotonicity | 3 | F ↑ in spot, F ↑ in time (rate > 0), F ↑ in rate (time > 0) |
| Identities | 5 | F(S, 0, r) = S, F(S, t, 0) = S, spot homogeneity (F(2S) = 2·F(S)), F(S, t, r) = S·er·t, semigroup composition (F(S, t1+t2, r) = F(F(S, t1, r), t2, r)) |
| Output bounds | 1 | F ≥ S (no arbitrage: rate ≥ 0 means future never below spot) |
Sources: test/Futures.test.mjs · test/foundry/Futures.t.sol