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
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.
{
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.
{
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) |
Requires a separate constraint for each protocol you want to limit. Uses max_ratio (0-1), not max_amount.
MAX_ALLOCATION_AMOUNT_PER_PROTOCOL
Cap a specific protocol to an absolute amount.
{
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.
{
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.
{
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.
{
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
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