Overview
The optimizer provides stateless capital allocation optimization across DeFi protocols. It computes optimal allocations, generates action plans, and returns execution-ready calldata. Optimizer methods are on theGiza client, not on the Agent instance. They operate at the chain level and do not require a specific smart account.
optimize()
Compute the optimal allocation of capital across a set of protocols, given the current allocations and constraints. Returns the target allocations, an action plan describing the required moves, and execution-ready calldata.Signature
Parameters
Optimization input parameters.
Token address to optimize for (e.g., USDC).
Total capital in the token’s smallest unit (e.g.,
'1000000000' for 1000 USDC). Must be a positive integer string.Current allocation per protocol, as a map of protocol name to amount in smallest units. Use
'0' for protocols with no current allocation.List of protocol names to consider for allocation. Must contain at least one entry.
Target chain. Defaults to the chain configured on the
Giza client.Allocation constraints to apply. See Constraints below.
Smart account address. When provided, the optimizer can use wallet-specific data for more accurate results.
Returns
Promise<OptimizeResponse>
Response Types
Examples
Constraints
Constraints control how the optimizer distributes capital. Pass them in theconstraints array of OptimizeOptions.
WalletConstraints Enum
ConstraintConfig (Optimizer)
The optimizer uses its own
ConstraintConfig type where kind is a WalletConstraints enum value. The agent’s ConstraintConfig uses a plain string for kind. Both are exported from the SDK — use OptimizerConstraintConfig for the optimizer variant if you need to distinguish them.Constraint Reference
| Constraint | Description | Example Params |
|---|---|---|
MIN_PROTOCOLS | Require allocation across at least N protocols | { min_protocols: 2 } |
MAX_ALLOCATION_AMOUNT_PER_PROTOCOL | Cap each protocol at N% of total capital | { max_allocation: 50 } |
MAX_AMOUNT_PER_PROTOCOL | Cap each protocol at an absolute amount | { max_amount: 500000000 } |
MIN_AMOUNT | Minimum total allocation amount | { min_amount: 100000000 } |
EXCLUDE_PROTOCOL | Exclude a specific protocol | { protocol: 'compound' } |
MIN_ALLOCATION_AMOUNT_PER_PROTOCOL | Minimum allocation per protocol | { min_allocation: 50000000 } |