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

# How Lerian Consignado — Dataprev works

> How Lerian Consignado works end to end: ICP-Brasil setup, Dataprev margin fetch, averbação, 24-hour loan-auction discovery, and CEF D+2 repasse reconciliation.

Lerian Consignado — Dataprev runs on event-driven flows of two kinds. A **command-driven** flow starts when the credit engine asks for a margin or an averbação. A **poller-driven** flow sweeps Dataprev on a cadence for auction discovery and settlement. Before any flow runs, a tenant registers its credentials.

## Credential setup

***

A tenant transacts only after it registers two credentials through the gateway's control plane:

* an **ICP-Brasil A1 client certificate** — a PEM certificate and key.
* an **OAuth2 client-credentials secret**.

The gateway validates the certificate before it stores the credential. The gateway holds both credentials in a managed secret store. No read ever returns the secret material. A status read reports three facts about the certificate: whether it is present, its fingerprint, and its expiry. The status read also reports whether the OAuth secret is present. When the store holds nothing, the read returns every flag as false, not an error.

## Margin fetch

***

When the credit engine needs a worker's payroll margin, it issues a **margin-request** command. The gateway queries Dataprev for the worker's available margin and disposable remuneration. It then emits a fact that carries the margin, keyed to the originating request.

## Averbação

***

To register a signed contract, the credit engine issues an **averbação-request** command. The gateway registers the contract with Dataprev and emits one of two facts:

* an **averbação-confirmed** fact that carries the rail's own success code. The gateway relays this code and never hardcodes it.
* an **averbação-rejected** fact that carries the rail's error code and message.

## Loan auction (leilão)

***

Each worker loan request (*solicitação*) opens a **24-hour auction**. A discovery poller lists these requests page by page.

The discovery flow does not submit proposals. It has no authorized producer for the mandatory proposal terms, so no bid can be selected or reach the rail.

## Reconciliation

***

On a configurable cadence, a reconciliation poller sweeps a sliding window of payroll *competências*. For each competência, it reads two always-on sources. The first source holds the per-contract **escrituração** records. The second source holds the **CEF D+2 repasse** records that settle paid installments.

The poller normalizes both sources and emits one reconciliation fact per record. The two legs are independent. A failure on one leg never blocks the other.
