fixed_pow

Raises an 18-decimal fixed-point (WAD) base to a WAD exponent as exp(y * ln(x)), with integer arithmetic only, for example to annualise a growth factor. NULL propagates. Results equal, digit for digit, those of the LogExpMath library that Balancer V2 and Pendle V2 contracts use, so a query recomputes an on-chain rate exactly. Accuracy: within 1e-16 relative for results of 1e17 or more (fixed_pow(2e18, 1e18) is 1999999999999999998).

Example

Runs locally

-- Annualise a 7-day growth factor of 1.003456789012345678: (growth)^(365 / 7) - 1
SELECT format_units(fixed_pow(1003456789012345678::UINT256, muldiv(365::UINT256, 1000000000000000000::UINT256, 7::UINT256)) - 1000000000000000000::UINT256, 18) AS apy;
-- => [{"apy":"0.197140784436020924"}]

API reference

fixed_pow(UINT256, UINT256) #

Raises an 18-decimal fixed-point (WAD) base to a WAD exponent as exp(y * ln(x)), with integer arithmetic only, for example to annualise a growth factor. NULL propagates.

Inputs

Name Type Use
x UINT256

UINT256 base with 18 decimals, below 2^255.

required positional
y UINT256

UINT256 exponent with 18 decimals, below 2^254 / 1e20.

required positional

Returns

Name Type
result UINT256

WAD x^y. UINT256 (x / 1e18)^(y / 1e18) * 1e18 = exp(y * ln(x)); 1e18 when y is 0 and 0 when x is 0. NULL for NULL input. y * ln(x) outside [-41e18, 130e18] errors: annualising a large move over a short window (a 45% gain or an 11% loss in one day) leaves it.