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 | ~400 | 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.| Constant | Value |
|---|---|
| MIN_SPOT | 1e-6 (smallest allowed spot price) |
| MAX_SPOT | 1e15 (largest allowed spot price) |
| MAX_EXPIRATION | 2 years (63,072,000 seconds) |
| MAX_RATE | 400% annual (4e18) |
| Error | Trigger |
|---|---|
| SpotLowerBoundError | spot ≤ MIN_SPOT |
| SpotUpperBoundError | spot ≥ MAX_SPOT |
| TimeToExpiryUpperBoundError | timeToExp ≥ MAX_EXPIRATION |
| RateUpperBoundError | rate ≥ MAX_RATE |