> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phylax.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# ERC20 Cumulative Inflow Breaker

> Limit cumulative ERC20 inflows with a Reshiram circuit-breaker trigger

## When to Use This Pattern

Use this pattern when unexpected inflows can distort protocol accounting, prices, or risk controls. It applies to lending vault donations, AMM reserve stuffing, bridged-asset accounting, staking receipt-token systems, and other protocols where excessive token inflow over a short window is suspicious.

This is a V2 Reshiram circuit-breaker pattern. The rolling-window accounting is handled by the trigger/precompile machinery, not by assertion-authored storage.

## What This Pattern Checks

Registers a percentage-based cumulative inflow limit:

* `registerAssertionSpec(AssertionSpec.Reshiram)`: Registers the assertion as a Reshiram assertion.
* `watchCumulativeInflow(token, thresholdBps, windowDuration, assertFn)`: Watches ERC20 inflow over a rolling window.
* `ph.inflowContext()`: Reads the token context inside the triggered assertion.
* Reverts when cumulative inflow breaches the configured threshold.

The assertion does not manually store balances or rolling counters. The Reshiram circuit-breaker trigger is responsible for tracking the window and invoking the assertion when the limit is exceeded.

<Warning>
  As of May 6, 2026, the v2 Reshiram spec is not live on Linea mainnet. Treat this pattern as a local, development, or forward-looking example until Linea mainnet supports the spec.
</Warning>

For more information about cheatcodes, see the [Cheatcodes Documentation](/credible/cheatcodes-reference).

## Assertion Pattern

```solidity theme={null}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Assertion} from "credible-std/Assertion.sol";
import {AssertionSpec} from "credible-std/SpecRecorder.sol";
import {PhEvm} from "credible-std/PhEvm.sol";

contract ERC20CumulativeInflowBreakerAssertion is Assertion {
    address public immutable monitoredToken;
    uint256 public immutable inflowThresholdBps;
    uint256 public immutable inflowWindowDuration;

    constructor(address monitoredToken_, uint256 inflowThresholdBps_, uint256 inflowWindowDuration_) {
        registerAssertionSpec(AssertionSpec.Reshiram);

        monitoredToken = monitoredToken_;
        inflowThresholdBps = inflowThresholdBps_;
        inflowWindowDuration = inflowWindowDuration_;
    }

    function triggers() external view override {
        watchCumulativeInflow(
            monitoredToken,
            inflowThresholdBps,
            inflowWindowDuration,
            this.assertCumulativeInflow.selector
        );
    }

    /// @notice Reverts when cumulative token inflow breaches the rolling-window limit.
    /// @dev The Reshiram trigger tracks the window and calls this function only after breach.
    function assertCumulativeInflow() external view {
        PhEvm.InflowContext memory ctx = ph.inflowContext();
        require(ctx.token == monitoredToken, "ERC20Inflow: wrong token context");

        revert("ERC20Inflow: cumulative inflow breaker tripped");
    }
}
```

<Note>Full examples and mock protocol code are available in [credible-std](https://github.com/phylaxsystems/credible-std/tree/master/examples/assertions-book).</Note>

## Related Patterns

* [ERC20 Cumulative Outflow Breaker](/assertions-book/assertions/ass20-erc20-drain)
* [ERC4626 Assets to Shares](/assertions-book/assertions/ass12-erc4626-assets-to-shares)
* [Sum of All Positions](/assertions-book/assertions/ass08-sum-of-all-positions)
