Skip to main content

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%
ParameterTypeRequiredDescription
min_protocolsnumberYesMinimum number of protocols to receive allocation
min_fraction_per_protocolnumberNoMinimum 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
  }
}
ParameterTypeRequiredDescription
protocolstringYesProtocol to constrain
max_rationumberYesMaximum 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)
  }
}
ParameterTypeRequiredDescription
protocolstringYesProtocol to constrain
max_amountnumberYesMaximum 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
}
ParameterTypeRequiredDescription
min_amountnumberYesMinimum 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
  }
}
ParameterTypeRequiredDescription
protocolstringYesProtocol to constrain
min_amountnumberYesMinimum 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" }
}
ParameterTypeRequiredDescription
protocolstringYesProtocol to exclude

MAX_AMOUNT vs MAX_ALLOCATION_AMOUNT

ConstraintParameterLimits by
MAX_AMOUNT_PER_PROTOCOLmax_ratio (0-1)Percentage of total capital
MAX_ALLOCATION_AMOUNT_PER_PROTOCOLmax_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