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

# Constraints

> All constraint types for controlling agent and optimizer behavior

## Overview

Constraints control how agents and the optimizer allocate capital. Use them to enforce diversification, cap exposure, exclude protocols, and set minimum allocations.

Constraints apply to both the Agentic approach (passed during `agent.activate()`) and the IaaS approach (passed to `giza.optimize()`).

## Constraint Types

```typescript theme={null}
enum WalletConstraints {
  MIN_PROTOCOLS = 'min_protocols',
  MAX_AMOUNT_PER_PROTOCOL = 'max_amount_per_protocol',
  MAX_ALLOCATION_AMOUNT_PER_PROTOCOL = 'max_allocation_amount_per_protocol',
  MIN_AMOUNT = 'min_amount',
  MIN_ALLOCATION_AMOUNT_PER_PROTOCOL = 'min_allocation_amount_per_protocol',
  EXCLUDE_PROTOCOL = 'exclude_protocol',
}
```

## Reference

### MIN\_PROTOCOLS

Require diversification across a minimum number of protocols.

```typescript theme={null}
{
  kind: WalletConstraints.MIN_PROTOCOLS,
  params: {
    min_protocols: 2,
    min_fraction_per_protocol: 0.1  // Optional, default 0.05 (5%)
  }
}
// Always diversify across at least 2 protocols, each with at least 10%
```

| Parameter                   | Type   | Required | Description                                                      |
| --------------------------- | ------ | -------- | ---------------------------------------------------------------- |
| `min_protocols`             | number | Yes      | Minimum number of protocols to receive allocation                |
| `min_fraction_per_protocol` | number | No       | Minimum fraction each protocol must receive (0-1). Default: 0.05 |

### MAX\_AMOUNT\_PER\_PROTOCOL

Cap a specific protocol to a **percentage** of total capital.

```typescript theme={null}
{
  kind: WalletConstraints.MAX_AMOUNT_PER_PROTOCOL,
  params: {
    protocol: "aave",
    max_ratio: 0.5  // 50% of total capital
  }
}
```

| Parameter   | Type   | Required | Description                             |
| ----------- | ------ | -------- | --------------------------------------- |
| `protocol`  | string | Yes      | Protocol to constrain                   |
| `max_ratio` | number | Yes      | Maximum fraction of total capital (0-1) |

<Warning>
  Requires a separate constraint for **each protocol** you want to limit. Uses `max_ratio` (0-1), not `max_amount`.
</Warning>

### MAX\_ALLOCATION\_AMOUNT\_PER\_PROTOCOL

Cap a specific protocol to an **absolute amount**.

```typescript theme={null}
{
  kind: WalletConstraints.MAX_ALLOCATION_AMOUNT_PER_PROTOCOL,
  params: {
    protocol: "moonwell",
    max_amount: 2000000000  // 2000 USDC (6 decimals)
  }
}
```

| Parameter    | Type   | Required | Description                                      |
| ------------ | ------ | -------- | ------------------------------------------------ |
| `protocol`   | string | Yes      | Protocol to constrain                            |
| `max_amount` | number | Yes      | Maximum absolute amount in token's smallest unit |

### MIN\_AMOUNT

Set a minimum allocation for any protocol that receives funds. Prevents dust allocations.

```typescript theme={null}
{
  kind: WalletConstraints.MIN_AMOUNT,
  params: { min_amount: 100000000 }  // 100 USDC
}
```

| Parameter    | Type   | Required | Description                             |
| ------------ | ------ | -------- | --------------------------------------- |
| `min_amount` | number | Yes      | Minimum amount in token's smallest unit |

### MIN\_ALLOCATION\_AMOUNT\_PER\_PROTOCOL

Ensure a specific protocol receives at least a minimum amount if it's used.

```typescript theme={null}
{
  kind: WalletConstraints.MIN_ALLOCATION_AMOUNT_PER_PROTOCOL,
  params: {
    protocol: "aave",
    min_amount: 500000000  // 500 USDC
  }
}
```

| Parameter    | Type   | Required | Description                             |
| ------------ | ------ | -------- | --------------------------------------- |
| `protocol`   | string | Yes      | Protocol to constrain                   |
| `min_amount` | number | Yes      | Minimum amount in token's smallest unit |

### EXCLUDE\_PROTOCOL

Blacklist a protocol entirely. The optimizer will never allocate to it.

```typescript theme={null}
{
  kind: WalletConstraints.EXCLUDE_PROTOCOL,
  params: { protocol: "compound" }
}
```

| Parameter  | Type   | Required | Description         |
| ---------- | ------ | -------- | ------------------- |
| `protocol` | string | Yes      | Protocol to exclude |

## MAX\_AMOUNT vs MAX\_ALLOCATION\_AMOUNT

| Constraint                           | Parameter              | Limits by                          |
| ------------------------------------ | ---------------------- | ---------------------------------- |
| `MAX_AMOUNT_PER_PROTOCOL`            | `max_ratio` (0-1)      | **Percentage** of total capital    |
| `MAX_ALLOCATION_AMOUNT_PER_PROTOCOL` | `max_amount` (integer) | **Absolute amount** in token units |

Both require the `protocol` parameter.

## Combining Constraints

```typescript theme={null}
await agent.activate({
  owner: userWallet,
  token: USDC_ADDRESS,
  protocols: ['aave', 'compound', 'moonwell', 'fluid'],
  txHash: depositTxHash,
  constraints: [
    // Diversify across at least 3 protocols
    {
      kind: WalletConstraints.MIN_PROTOCOLS,
      params: { min_protocols: 3 }
    },
    // Cap each protocol at 40%
    {
      kind: WalletConstraints.MAX_AMOUNT_PER_PROTOCOL,
      params: { protocol: 'aave', max_ratio: 0.4 }
    },
    {
      kind: WalletConstraints.MAX_AMOUNT_PER_PROTOCOL,
      params: { protocol: 'compound', max_ratio: 0.4 }
    },
    {
      kind: WalletConstraints.MAX_AMOUNT_PER_PROTOCOL,
      params: { protocol: 'moonwell', max_ratio: 0.4 }
    },
    {
      kind: WalletConstraints.MAX_AMOUNT_PER_PROTOCOL,
      params: { protocol: 'fluid', max_ratio: 0.4 }
    },
    // Cap newer protocol at absolute 2000 USDC
    {
      kind: WalletConstraints.MAX_ALLOCATION_AMOUNT_PER_PROTOCOL,
      params: { protocol: 'fluid', max_amount: 2000000000 }
    },
    // No dust allocations
    {
      kind: WalletConstraints.MIN_AMOUNT,
      params: { min_amount: 500000000 }
    }
  ]
});
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Quickstart" icon="rocket" href="/developers/quickstart">
    See constraints in a full integration example
  </Card>

  <Card title="Optimizer" icon="chart-mixed" href="/developers/architecture/optimizer">
    How the optimizer uses constraints
  </Card>

  <Card title="SDK Reference" icon="code" href="/sdk-reference/agent/lifecycle">
    activate() method with constraint parameters
  </Card>
</CardGroup>
