FixedPointMath.sol

On-chain fixed-point math library for cross-entropy scoring.

Usage

import {FixedPointMath} from "yiling-protocol/src/libraries/FixedPointMath.sol";

Functions

lnWad(uint256 x) → int256

Computes ln(x) in WAD format. Reverts if x == 0.

crossEntropyScore(uint256 q, uint256 p) → int256

S(q, p) = q × ln(p) + (1-q) × ln(1-p)

deltaPayout(uint256 qFinal, uint256 pBefore, uint256 pAfter) → int256

Delta score for payouts. Positive = moved toward truth.

WAD Format

All values use 1e18 fixed-point representation:

1.0   = 1000000000000000000  (1e18)
0.5   = 500000000000000000   (5e17)
0.01  = 10000000000000000    (1e16)

Standalone Usage

You can use FixedPointMath independently in your own contracts:

int256 result = FixedPointMath.lnWad(500000000000000000); // ln(0.5)
// result = -693147180559945309