Futures

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

Functions

FunctionGasDescription
futurePrice442Forward price: spot · e^(r·t)

npm install defimath-lib

Conventions

  • spotuint128, 18-decimal fixed-point (1e18 = 1.0).
  • timeToExpuint32, seconds to contract expiration.
  • rateuint64, annualized risk-free rate as 18-decimal fixed-point.
  • Returns uint256 — futures price in 18-decimal fixed-point.
  • The function is internal pure.

Quick example

solidity
import "defimath-lib/contracts/derivatives/Futures.sol";

uint256 fwd = DeFiMathFutures.futurePrice(spot, timeToExp, rate);

Important notes

  • Continuous compounding. The model uses F = S · er·t. For dividend-paying assets, fold the dividend yield q into the rate as (r − q) at the call site.
  • No strike — this is a forward, not an option. For option pricing, use the Options module; for cash-or-nothing digitals, use Binary options.

Every function reverts on out-of-bounds inputs with a named error — see the per-function pages for limits and error specifics.

Testing

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.

CategoryCountWhat they check
Monotonicity3F ↑ in spot, F ↑ in time (rate > 0), F ↑ in rate (time > 0)
Identities5F(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 bounds1F ≥ S (no arbitrage: rate ≥ 0 means future never below spot)

Sources: test/Futures.test.mjs · test/foundry/Futures.t.sol