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
futurePrice~400Forward 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.
  • Lowest gas in the library. ~400 gas total — typically cheaper than reading a single storage slot, so feel free to call it inline.

Limits & errors

ConstantValue
MIN_SPOT1e-6 (smallest allowed spot price)
MAX_SPOT1e15 (largest allowed spot price)
MAX_EXPIRATION2 years (63,072,000 seconds)
MAX_RATE400% annual (4e18)
ErrorTrigger
SpotLowerBoundErrorspot ≤ MIN_SPOT
SpotUpperBoundErrorspot ≥ MAX_SPOT
TimeToExpiryUpperBoundErrortimeToExp ≥ MAX_EXPIRATION
RateUpperBoundErrorrate ≥ MAX_RATE