Specification · 03
Synthetic model and formulas
The exact arithmetic behind Inventory Lab, and everything it omits.
Inventory Lab runs the formulas below deterministically in your browser. It is a teaching and design tool. It is not a quote, a backtest, or a simulation of deployed contracts.
Aggregate
gross = abs(deltaA) + abs(deltaB)
opposing = deltaA * deltaB < 0
matched = opposing ? min(abs(deltaA), abs(deltaB)) : 0
residual = gross - 2 * matched
activeOrders = number of nonzero instructions
independentCost = gross * price * externalFeeRate
+ activeOrders * gasPerOrder
batchCost = residual * price * externalFeeRate
+ matched * price * nettingFeeRate
+ totalBatchGasPer vault, when a match exists
residualForVault = abs(vaultDelta) - matched
independentVaultCost = abs(vaultDelta) * price * externalFeeRate
+ gasPerOrder
batchVaultCost = residualForVault * price * externalFeeRate
+ matched * price * nettingFeeRate / 2
+ totalBatchGas / 2In this simplified two-vault model the crossing price is identical to the external reference price, and matching fees and batch gas are split equally between the two vaults. That equal split is an assumption of the model, not a settlement rule.
The candidate batch is selected only when the mock constraints pass, neither vault is modeled worse off, and the modeled total improves. A positive aggregate difference never overrides a worse modeled result for a single participant.
This model omits slippage, price changes, adversarial execution and real liquidity-position gas. It does not establish production savings. All amounts are accounting units, a hypothetical USD-like illustration.
