This standalone CRE project implements a confidential liquidation-defense workflow for DeFi lending positions.
Description
The workflow continuously evaluates borrower risk and takes defensive action before a position becomes unsafe. During periods of high volatility, it can increase collateral, reduce debt, or combine both strategies based on policy constraints. Sensitive operational data remains protected in confidential execution, including exchange credentials, model credentials, and user-defined risk thresholds.
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-liquidation-protection-ts/: TypeScript workflow implementationautomated-liquidation-protection-go/: Go workflow implementation
Private Inputs
The following inputs are treated as confidential:
- Exchange API credentials used to fetch account context such as stablecoin reserves and available cash balance.
- LLM reasoning API credentials and policy parameters used to govern defense behavior, including minimum and target health factors, reserve deployment caps, minimum reserve balance, and collateral allocation limits.
- Execution preferences that define how defense actions should be sequenced.
Workflow Notes
- Observe liquidation risk signals. The workflow tracks collateral and debt asset pricing, health factor, liquidation proximity, LTV, liquidation threshold, and market volatility.
- Enforce user policy constraints. Confidential reasoning evaluates how much capital can be deployed, whether debt reduction should be prioritized, which reserve assets are eligible, and what execution sequence is preferred.
- Select defense actions. The workflow builds a response plan that may include collateral-focused moves (deposit, bridge, swap-then-deposit) and debt-focused moves (repay, swap-then-repay, partial payoff, full payoff).
- Execute the approved defense plan.
Note: Every reasoning stage can be implemented with deterministic rule-based logic instead of an LLM, if your deployment requires a fully rules-driven policy engine.
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_LIQUIDATION_WARNING_ACTION_THRESHOLDMOCK_LIQUIDATION_MINIMUM_HEALTH_FACTORMOCK_LIQUIDATION_TARGET_HEALTH_FACTORMOCK_LIQUIDATION_MAX_STABLECOIN_RESERVE_DEPLOYMENTMOCK_LIQUIDATION_MIN_STABLECOIN_RESERVE_BALANCEMOCK_LIQUIDATION_MAX_COLLATERAL_ALLOCATIONMOCK_LIQUIDATION_MAX_PARTIAL_DEBT_REPAYMENTMOCK_LIQUIDATION_DEFENSIVE_ACTION_SEQUENCING_PREFERENCEMOCK_LIQUIDATION_PREFERRED_VENUES
The local mock server for this project only exposes routes under /liquidation/*.
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-liquidation-protection-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-liquidation-protection-go --target=staging-settings
CREATED BY CHAINLINK LABS