# Payment lifecycle

## Payment Lifecycle and Reserve Management

Divigent is designed to sit around an agent's payment lifecycle without changing the payment itself.

The SDK and MCP layers use the router's primitives to keep enough USDC liquid for near-term payment activity and deploy excess float productively. The agent's payment logic, recipients, and amounts remain unchanged.

### The Loop

```mermaid
flowchart LR
    payment["Payment needed"] --> liquid["Check liquid USDC"]
    liquid -->|"Enough liquidity"| send["Send payment"]
    liquid -->|"Needs liquidity"| recall["Withdraw from Divigent"]
    recall --> send
    send --> settle["Payment settles"]
    settle --> reserve["Recalculate reserve"]
    reserve -->|"Idle USDC remains"| deposit["Deposit idle capital"]
    deposit --> yield["Earn yield through supported venues"]
```

#### Before A Payment

The integration checks whether the wallet has enough liquid USDC. If liquidity is short, it withdraws enough from Divigent to cover the payment plus a configurable reserve.

#### After Settlement

The integration recalculates how much USDC should remain liquid. Any amount above that reserve floor can be deposited back into Divigent.

### Reserve Floor

The appropriate liquid balance depends on the wallet's operating context:

* expected payment size;
* payment frequency;
* execution budget;
* required safety buffer;
* application-specific settlement timing;
* operator or agent policy.

The reserve floor is a configuration choice for each agent. Divigent provides the primitives (balances, withdrawal previews, deposit, withdraw) and the SDK applies the floor to decide how much to recall or redeploy.

### Wallets and Operators

Before using the integration, a wallet must be authorised on the router.

There are two registration paths:

1. `initialize()` registers `msg.sender` directly.
2. `initializeFor(wallet, deadline, sig)` allows gasless registration using an EIP-712 signature from the wallet.

After registration, a wallet can call `setOperator(operator, approved)` to let another address deposit or withdraw on its behalf.

Operators do not receive dvUSDC and do not own the wallet's position. They receive only the permission to call router functions for that wallet until revoked. This makes operator-led automation safe: the operator can recall and redeploy capital without ever gaining ownership of the receipt token.

### x402 Awareness

Divigent's SDK is designed to wrap x402 payment lifecycles. The integration can react to x402 hooks before payment construction and after settlement confirmation, giving the agent reserve-aware capital management without modifying x402 request or response handling.

### Contracts Versus SDK Responsibilities

| Concern                            | Enforced by contracts | Provided by SDK |
| ---------------------------------- | --------------------- | --------------- |
| Deposit and withdrawal mechanics   | Yes                   | No              |
| Cost basis and yield accounting    | Yes                   | No              |
| Routing gates and oracle freshness | Yes                   | No              |
| Fee calculation                    | Yes                   | No              |
| When to recall capital             | No                    | Yes             |
| Reserve floor logic                | No                    | Yes             |
| Payment-timing integration         | No                    | Yes             |

The contracts are the source of truth for state changes. The SDK adds operational awareness around them.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://divigent.gitbook.io/divigent-docs/quick-start/payment-lifecycle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
