This standalone CRE project implements a confidential portfolio rebalancing workflow for crypto allocations.
Description
The workflow continuously tracks allocation drift and triggers rebalancing when policy thresholds are exceeded. It is designed to restore user-defined target weights while protecting sensitive operational inputs, including exchange credentials, model credentials, policy thresholds, and execution preferences inside confidential execution.
Target Customer
- Professional retail traders
- Developer shops
- Founders building trading products
Structure
project.yaml: project-level target settingssecrets.yaml: secret ID mappings used by the workflowmock-server.js: local deterministic API serverautomated-portfolio-rebalancing-ts/: TypeScript workflow implementationautomated-portfolio-rebalancing-go/: Go workflow implementation
Private Inputs
The following inputs are handled as confidential:
- Exchange API credentials used to read holdings, reserve data, and execution context, including stablecoin reserve depth and cash balance.
- LLM reasoning API credentials.
- Portfolio policy settings such as target allocation mix, minimum drift threshold, maximum trade size per execution, and required stablecoin reserve floor.
- Execution preferences such as venue priority, slippage limits, and trade chunking/ordering behavior.
Workflow Notes
- Monitor portfolio state. The workflow gathers market prices, current asset weights, drift from target allocations, reserve health, and volatility signals.
- Enforce user-defined portfolio constraints. Confidential reasoning validates weight constraints, drift triggers, rebalance sizing limits, reserve protection requirements, and slippage controls.
- Build a rebalance action plan. The plan can include buying underweight assets, selling overweight assets, enforcing reserve floors, capping per-trade notionals, and optimizing execution through chunking and smart venue routing.
- Execute rebalance actions across venues. Depending on route selection, the workflow can execute both on-chain operations (such as swaps) and off-chain operations (such as centralized exchange API trades).
Note: Reasoning stages can be implemented with deterministic rule-based logic instead of an LLM when a fully rules-driven execution model is preferred.
Required Environment Variables
Copy .env.example to .env and provide values for:
CRE_ETH_PRIVATE_KEY(optional for local simulate)MOCK_PORTMOCK_EXCHANGE_API_KEYMOCK_OPENAI_API_KEYMOCK_REBALANCING_TARGET_ALLOCATION_BTC_PCTMOCK_REBALANCING_TARGET_ALLOCATION_ETH_PCTMOCK_REBALANCING_TARGET_ALLOCATION_USDC_PCTMOCK_REBALANCING_DRIFT_THRESHOLD_PCTMOCK_REBALANCING_MAX_TRADE_USDMOCK_REBALANCING_RESERVE_FLOOR_USDCMOCK_REBALANCING_MAX_SLIPPAGE_BPSMOCK_REBALANCING_PREFERRED_VENUESMOCK_REBALANCING_ORDER_SEQUENCE_PREFERENCE
The local mock server for this project only exposes routes under /rebalancing/*.
Quick navigation:
TypeScript Quick Start
- Install dependencies
bun install
- Create environment file
cp .env.example .env
- Start mock server
bun run mock:server
- In another terminal, run checks
bun run typecheck
bun run test
- Simulate workflow
cre workflow simulate ./automated-portfolio-rebalancing-ts --target=staging-settings
Go Quick Start
- Create environment file (at the shared project root)
cp ../.env.example ../.env
- Start the mock server (requires Node or Bun)
bun mock-server.js
- In another terminal, run checks
go vet ./...
go test ./...
- Simulate workflow
cd .. && cre workflow simulate ./automated-portfolio-rebalancing-go --target=staging-settings
CREATED BY CHAINLINK LABS