Skip to content

Portfolio Rebalancer

LIVE ON STARKNET MAINNET

This is the MVP product. The portfolio rebalancer is running on Starknet mainnet at zkde.fi/portfolio — real capital, real transactions, real receipts. Currently tracking ~$75M across Starknet DeFi.

The rebalancer keeps your portfolio aligned with your target allocation across Starknet protocols. Markets move, positions drift, yields change — the system catches the drift, generates an AI-recommended rebalance plan, runs risk checks, and executes. It can run manually (you trigger each step) or autonomously (the agent handles it within session key bounds).

What /portfolio does

When you open /portfolio, you see:

  • Current balances across ETH, STRK, USDC, and WBTC
  • Target allocation — what your portfolio should look like
  • Drift indicator — how far your current state has deviated (aligned / watch / rebalance)
  • AI recommendation — the system's suggested rebalance plan, factoring in yields from Ekubo, Vesu, and staking
  • Risk assessment — policy-aware checks before execution

The rebalancer routes through mainnet protocols directly via your wallet:

ProtocolHow it's usedNetwork
EkuboSwap execution, LP positions, fee collectionMainnet (via Ekubo Router)
VesuPosition scanning, lending routesMainnet
StakingStaking position readsMainnet

MAINNET EXECUTION MODEL

On mainnet, the backend builds calldata targeting mainnet Ekubo Router, and your wallet signs+submits directly. This is different from the Sepolia proof-gated pipeline, where transactions route through VaultController → AllocationRouter → Adapter contracts. The Sepolia adapter contracts (EkuboLpAdapter, LendingAdapter, StakingAdapter) are not yet on mainnet.

The pipeline

Every rebalance — manual or autonomous — follows the same six-stage pipeline:

flowchart LR
  A["<b>Analyze</b><br/>How far has the<br/>portfolio drifted?"] --> B["<b>Propose</b><br/>What changes<br/>would fix it?"]
  B --> C["<b>Check</b><br/>Do the changes<br/>pass risk screening?"]
  C --> D["<b>Prepare</b><br/>Build execution<br/>context + calldata"]
  D --> E["<b>Execute</b><br/>Submit to chain"]
  E --> F["<b>Receipt</b><br/>Record result +<br/>update trust state"]

1. Analyze — the system looks at your current portfolio composition and compares it against your target allocation. It computes drift metrics: how much each position has deviated from its target weight, and whether the aggregate drift exceeds your tolerance threshold.

2. Propose — based on the analysis, the system generates a rebalance proposal. This includes specific trades: "sell X of token A, buy Y of token B, adjust LP range on pool C." The proposal is a plan, not an execution. On mainnet, the AI recommendation factors in current yields across Ekubo, Vesu, and staking.

3. Check — the proposal runs through risk screening. Risk score, anomaly detection, impermanent loss prediction, correlation risk — whatever applies to the proposed trades. If the screening flags the proposal, it gets caught here. There's also an advisory mode that returns risk signals without blocking.

4. Prepare — the approved proposal is converted into execution context: calldata for each trade, simulation results, adapter routing, gas estimates. At this point you have everything needed to execute, but nothing has been submitted yet.

5. Execute — calldata goes to chain. For manual mode, the user signs each tx in their wallet. For autonomous mode, the agent submits within session key bounds.

6. Receipt — results are recorded in ReceiptRegistry on mainnet. Trust state updates. The cycle closes.

Endpoints

All endpoints are under /api/v1/zkdefi/rebalancer/:

StageMethodPathWhat it does
AnalyzePOST/analyzeAssess portfolio drift against target allocation
ProposePOST/proposeGenerate a rebalance proposal with specific trades
CheckPOST/checkRun risk/anomaly screening against the proposal (blocking)
Advisory checkPOST/advisory-checkSame screening, but returns signals without blocking
PreparePOST/prepareBuild execution context — calldata, simulation, routing
ExecutePOST/executeSubmit the prepared rebalance to chain

Autonomous mode

If you've granted a session key with rebalancing permissions, the agent can run the pipeline automatically. It watches for drift, proposes adjustments, screens them, and executes — all within the bounds you set.

MethodPathAuthWhat it does
POST/autonomous/startX-Wallet-AddressStart autonomous rebalancing
POST/autonomous/stopX-Wallet-AddressStop it
GET/autonomous/status/{address}PublicCheck if autonomous mode is active
POST/autonomous/pause/{address}X-Wallet-AddressPause without fully stopping
POST/autonomous/resume/{address}X-Wallet-AddressResume after pause
GET/autonomous/allX-Admin-KeyFleet status — all users (admin only)

Autonomous mode respects your session key constraints. If the agent proposes a trade that exceeds your max position size or touches a protocol not in your allowed list, the session key validation rejects it before it goes to chain.

Check modes

The check stage supports two modes:

  • Strict mode — risk screening is a hard gate. If the circuits flag the proposal, execution can't proceed. Used for autonomous operations where the agent needs guardrails.
  • Advisory mode — risk screening returns signals, but the user decides. Used for manual rebalancing where the human is in the loop.

Mainnet contracts

The rebalancer on mainnet uses:

ContractRoleNetwork
ReceiptRegistryImmutable receipt per rebalance operationMainnet
ReceiptOS ArchivePermanent receipt archiveMainnet
Ekubo RouterSwap execution targetMainnet (third-party)
Ekubo CorePool state + pricingMainnet (third-party)

The backend reads your positions via mainnet RPC (position_scanner.py, ekubo_config.py), builds calldata for the Ekubo mainnet router, and returns it to the frontend. Your wallet signs and submits directly.

What about VaultController, AllocationRouter, adapters?

Those are on Starknet Sepolia — part of the proof-gated execution pipeline that's coming to mainnet. On Sepolia, the flow goes: proof → VaultController → AllocationRouter → Adapter → protocol. On mainnet today, the flow is simpler: recommendation → calldata → your wallet → Ekubo directly.

Server-side execution gates

Server-side mainnet execution is double-gated off by default. Both EXECUTOR_LIVE_SUBMIT_MAINNET and EXECUTION_GATE_ALLOW_MAINNET_LIVE must be true for the backend to submit transactions on your behalf. In practice, your wallet signs everything.

Full addresses: Contracts

Trying it out

Go to zkde.fi/portfolio. Connect your wallet (ArgentX or Braavos on Starknet mainnet). If you have ETH, STRK, or USDC, the system will show your current allocation and suggest a target. From there, the AI recommendation engine takes over.

For the deeper proof pipeline that the Sepolia version exercises (zkML circuits, five proof lanes, privacy rails), see Proof Pipeline.

Built by Obsqra Labs