Skip to main content
The core.numericInvariant guard asserts a numeric comparison against an op’s output port at simulation time, turning the observed value into an on-chain invariant. Use it when you need an explicit bound on a produced amount — for example, requiring that a deposit returns at least some minimum number of shares, or that a leftover balance is exactly zero. Unlike slippage, which expresses tolerance relative to the expected amount in basis points, core.numericInvariant compares against an absolute threshold you supply. It targets handle outputs only.

Config

FieldTypeDescription
portstringThe op output port (a handle) to assert against.
op'gte' | 'gt' | 'lte' | 'lt' | 'eq' | 'neq'The comparison operator applied as value <op> threshold.
thresholdstringThe bound to compare against, as a decimal-integer string (base-unit, no decimals).

Example

Require that a zap’s amountOut port produces at least 1000000 base units:
builder.lifi.zap('zap', {
  bind: { amountIn: builder.inputs.amountIn },
  config: {
    resourceOut: resources.erc20(A_ETH_USDC, 1),
  },
  guards: [
    guards.numericInvariant({
      port: 'amountOut',
      op: 'gte',
      threshold: '1000000',
    }),
  ],
});
See Build a Flow for attaching guards, interpreting failures, and choosing tolerances.