Skip to main content

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 the Giza 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

OptimizeOptions
required
Optimization input parameters.
Address
required
Token address to optimize for (e.g., USDC).
string
required
Total capital in the token’s smallest unit (e.g., '1000000000' for 1000 USDC). Must be a positive integer string.
Record<string, string>
required
Current allocation per protocol, as a map of protocol name to amount in smallest units. Use '0' for protocols with no current allocation.
string[]
required
List of protocol names to consider for allocation. Must contain at least one entry.
Chain
Target chain. Defaults to the chain configured on the Giza client.
ConstraintConfig[]
Allocation constraints to apply. See Constraints below.
Address
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 the constraints 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 Example