According to recent reports, this is a write-up of how a set of static calculator pages computes the liquidation price of an isolated-margin USDT perpetual position for three exchanges (OKX, Bybit and MEXC), and how one function now produces both the numbers baked into the HTML at build time and the numbers the page script shows after a user types. The formulas are short. The bugs came from copying them.

Every exchange documents roughly the same idea: a position is liquidated when its remaining margin falls to the maintenance margin. The details differ, and they move the result by a few dollars on a large price:. (Related: Large Language Models: A New Moore's Law?...)

With entry price E, quantity q (notional / entry), leverage L, maintenance margin rate mmr, taker fee taker and extra margin extra, the long and short cases are:.

For a 10,000 USDT position at 74,000 with 10x leverage, a 0.5% maintenance rate and each venue's regular taker rate (0.05%, 0.055%, 0.04%), this gives:.

The spread is small, which is exactly why it went unnoticed.

Recent findings suggest that the site grew one page at a time. A liquidation calculator, a leverage calculator, an all-in-one futures calculator and a small widget on the home page each got their own copy of the formula. The home widget's copy implemented only the OKX version and used it for every venue.

Recent findings suggest that the result: the home page showed 66,971.69 for a Bybit long (the OKX formula with Bybit's 0.055% taker fee), while the dedicated calculator showed 66,934.67 for the same inputs. Nobody computes these by hand, so nothing looked wrong until a review compared the pages side by side.

A second problem sat next to it: the widget's HTML contained numbers written in by hand for the first render. Before the script ran, every domain demonstrated figures calculated for one venue, including domains that do not cover that venue at all.

The home widget now has a single function that returns display strings. The build script calls it to write the initial HTML, and the same function is injected into the inline page script with Function.prototype.toString():.

With no extra margin, the general formulas reduce to these forms (q cancels out), so the widget and the full calculators agree to the cent. After the change, all 15 combinations (three venues, five leverage and side presets) were checked against the dedicated calculators, and on each of the five domains the 29 output elements had the same content before and after the page script ran.

toString() has rules that are easy to break:.

Sources indicate that not every page uses the serialized function yet. The full futures calculator has a build-time fcCompute() (used for its example table) and a page script that repeats the same three formulas, now also selected by a style field instead of venue names:.

Those copies are kept in step by a comment in each file and by a reference value: 100,000 entry, 10x, 0.5% maintenance and 0.05% taker must give 90,497.74 on every page that uses the fee-in-denominator style. Moving the remaining pages to the serialized-function pattern is the obvious next step.

Sources indicate that A copy can also drift by venue rather than by math. One localized page computed a cross-versus-isolated comparison with the fee-in-denominator formula and cited that venue's help page, while every other calculator on the same domain used the linear formula of the venue that domain actually covers. The two pages disagreed on the same trade. The fix was the same idea: pick the formula from the domain's venue data, never from a hard-coded default.

According to recent reports, this post was written by an AI assistant (Claude) from the project's source code and deployment notes, and published without manual editing. The code and the figures are from the running project.

β†’ Read original article