An AI-Powered DeFi Vault managed by AI Agents created using ADK-TS by IQAI. This project combines a secure smart contract vault, a modern Next.js frontend, and intelligent agents to optimize DeFi strategies.
This is a monorepo containing the following packages:
packages/contracts: Hardhat project containing the smart contracts for the vault and strategies.packages/frontend: Next.js web application for users to interact with the vault.packages/agents: AI agents built with ADK-TS that monitor and manage the vault strategies.
This project is a showcase of the ADK-TS (Agent Development Kit) by IQAI, demonstrating how to build complex, autonomous DeFi agents using TypeScript.
How ADK-TS Powers MetaVault AI:
-
Conversation Orchestration Layer:
- Session Memory: Handles conversation memory for the session.
- Tool Management: Manages structured tool response formatting and guides the agent to use tools correctly.
- Frontend Simplicity: Reduces frontend logic complexity as the agent handles user interaction.
-
TypeScript Integration:
- Developer Experience: Tools, agent logic, and types are all written in TypeScript, making it developer-friendly and strongly typed.
- Seamless Integration: Easy to integrate with the Next.js/React frontend.
-
Context State Management: Built-in state management for storing context, such as caching the latest APY updates.
-
Modular Architecture: Uses
AgentBuilderto orchestrate specialized agents (StrategySentinel,YieldSimulator) for distinct responsibilities.
The vault is managed by a team of specialized AI agents:
Role: Guardian & Portfolio Manager
- Responsibilities:
- Continuously monitors strategy health (LTV, Liquidation Risk).
- Fetches real-time token prices (LINK/WETH) to make market-aware decisions.
- Risk Management: Automatically pauses strategies or reduces leverage during high volatility.
- Rebalancing: Adjusts portfolio weights between safe and leveraged strategies based on market conditions.
- Harvesting: Collects yields and compounds them back into the vault.
Role: User Assistant
- Responsibilities:
- Provides a natural language interface for users to interact with the vault.
- Checks user balances and vault statistics securely.
- Facilitates deposits and withdrawals via chat commands.
- Privacy: Strictly enforces security boundaries, ensuring it never exposes admin functions or other users' data.
Role: Yield Generator
- Responsibilities:
- Simulates yield accrual scenarios for testing and demonstration purposes.
- Helps validate the vault's profit distribution logic.
The MetaVault allocates user funds into multiple strategies to maximize yield while managing risk.
For development and testing purposes, all strategies currently run on mock contracts to simulate Aave mechanics, liquidity indices, borrowing flows, and interest behavior.
- Description: A low-risk strategy that supplies assets (LINK) to a mock Aave V3 lending pool used for testing.
- Mechanism: Earns simulated passive supply APY using a mocked liquidity index.
- Risk Profile: Low. In production, this maps to real Aave behavior, but in the current environment it operates on mock contracts for predictable testing.
- Mock Note: The entire interest accrual is driven by a mock liquidity index set to
1e18unless programmatically updated.
-
Description: A high-yield strategy that simulates leveraged looping by interacting with a mocked Aave pool and mock swap router.
-
Mechanism:
- Supplies LINK to mocked Aave.
- Borrows mock WETH against the LINK collateral.
- Swaps borrowed WETH for LINK using a mock swap contract.
- Resupplies the LINK.
- Repeats the loop for
maxDepthiterations.
-
Risk Profile: High. Reflects the risks of real leverage (e.g., liquidation), though all liquidation thresholds and LTV calculations are currently performed through mocked logic.
-
AI Management:
The Strategy Sentinel Agent monitors mock LTV values and real LINK/WETH prices and then performs simulated auto-deleveraging when the position approaches the configured danger zone.
-
Clone the repository:
git clone <repository-url> cd defi-portfolio
-
Install dependencies for all packages:
pnpm install
To run the full stack, you need to start the blockchain (or deploy to testnet), run the agent server, and start the frontend.
Navigate to the contracts directory:
cd packages/contracts-
Compile contracts:
pnpm hardhat compile
-
Run local node:
pnpm hardhat node
-
Deploy contracts:
pnpm hardhat run scripts/deploy_mocks.ts --network localhost
(Note: Update the deployment script path as necessary based on your specific modules)
Navigate to the agent directory:
cd packages/agents/defi-portfolio-
Setup Environment: Copy
.env.exampleto.envand configure your keys.cp .env.example .env
-
Run Agent Server:
pnpm run dev:server
-
Run Automation Cron:
pnpm run automate:cron
Navigate to the frontend directory:
cd packages/frontend-
Setup Environment: Create a
.env.localfile with the deployed contract addresses.cp .env.example .env.local
Update
NEXT_PUBLIC_VAULT_ADDRESSand other variables with addresses from the contract deployment step. -
Start Development Server:
pnpm dev
-
Open http://localhost:3000 in your browser.
- Smart Contracts: Solidity, Hardhat, OpenZeppelin
- Frontend: Next.js 14, TypeScript, Tailwind CSS, Wagmi, Viem
- AI Agents: ADK-TS (Agent Development Kit), Node.js, Express