Skip to main content
A price-sensitive operation should reject a spot price far from an independent time-weighted reference. This legacy template illustrates that goal but needs correction before use.
The reviewed upstream example needs correction before production use. The limitation below is present in the linked source; the imported code is preserved for comparison.

Source limitation

The template creates pre- and post-transaction fork identifiers, then calls twap() and price() directly. The identifiers are not passed into those reads. Its deviation calculation also divides to a whole percentage before comparison: a 5.9% deviation rounds down to 5% and passes the nominal 5% limit.

Adaptation requirements

Bind the spot and reference reads to explicit snapshots. Compare scaled products before division, with overflow-safe arithmetic, and define how a zero reference is handled. Validate the reference window, decimals, and independence from the operation being protected.

Scenarios

Use the oracle reduce-only pattern for a simpler pre-call comparison. That pattern uses the smaller price as its percentage denominator; it is not the same formula as deviation from a fixed TWAP.

Legacy source

Reviewed source. See running and adapting examples for the pinned library revision.