You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A comprehensive template for building AI-powered DeFi applications on the Flare Network with enhanced security through Trusted Execution Environments (TEE). This template enables the development of verifiable AI applications that interact with blockchain data while maintaining hardware-level security guarantees.
3
+
A comprehensive template for building autonomous AI agents for decentralized finance (DeFi) applications with enhanced security provided by Trusted Execution Environments (TEE). This template enables AI agents to securely manage wallets, execute token transfers, and interact with smart contracts while producing verifiable attestation proofs.
4
+
5
+
## 📖 Overview
6
+
7
+
TODO
8
+
9
+
## 🚀 Key Features
10
+
11
+
-**TEE-Enabled Secure Operations**
12
+
All critical processes—from AI inference to blockchain transactions—are executed within a Trusted Execution Environment, ensuring robust security with verifiable remote attestation.
13
+
14
+
-**Integrated Interactive Chat UI**
15
+
Engage with your AI agent through a built-in chat interface, designed to provide seamless and secure real-time interaction directly from the TEE.
16
+
17
+
-**Native Flare Blockchain & Wallet Support**
18
+
Securely manage wallets and perform token operations on the Flare blockchain, with cryptographic assurances that your transactions and key management remain within the TEE.
19
+
20
+
-**Cutting-Edge AI Capabilities**
21
+
Leverage the power of Gemini 2.0 and access a wide range of over 300 LLMs, enabling advanced, structured query support and versatile AI-driven functionalities.
4
22
5
23
## 🏗️ Structure
6
24
@@ -24,122 +42,156 @@ src/flare_ai_defai/
24
42
25
43
## 🔑 Key Components
26
44
45
+
The following scripts are the crucial parts of this template and provide a strong base for building and customizing your autonomous AI agent. You can tweak these components to extend functionality, integrate additional features, or adapt them to your project's specific needs.
46
+
27
47
### Blockchain Integration (`blockchain/`)
48
+
This module handles interactions with the Flare blockchain. The `FlareProvider` class abstracts operations such as wallet creation, transaction construction, and secure transaction submission.
49
+
28
50
```python
29
51
from flare_ai_defai.blockchain import FlareProvider
The AI integration layer allows you to interact with various AI providers through a unified interface. The architecture is modular enough to support alternative providers.
73
+
46
74
```python
47
75
from flare_ai_defai.ai import GeminiProvider
48
76
49
-
# Initialize AI
77
+
# Initialize the AI provider with required credentials and model settings
50
78
ai = GeminiProvider(
51
79
api_key="YOUR_API_KEY",
52
80
model="gemini-pro"
53
81
)
54
82
55
-
# Generate response
83
+
# Generate a response from the AI based on your prompt
The attestation module ensures that critical operations run securely within a Trusted Execution Environment.
90
+
61
91
```python
62
92
from flare_ai_defai.attestation import Vtpm, VtpmValidation
63
93
64
-
#Get attestation token
94
+
#Obtain an attestation token from the TEE
65
95
vtpm = Vtpm()
66
96
token = vtpm.get_token(nonces=["random_nonce"])
97
+
print("Attestation Token:", token)
67
98
68
-
# Validate token
99
+
# Validate the attestation token to ensure secure execution
69
100
validator = VtpmValidation()
70
101
claims = validator.validate_token(token)
102
+
print("Token Claims:", claims)
71
103
```
72
104
73
-
## 💡 Example Use Cases & Research Applications
74
-
75
-
1.**Verifiable AI Oracle Service**
76
-
- Implementation of "Trustworthy Oracle Networks with TEE-based Confidential Computing"
77
-
- AI-powered price feed validation
78
-
- Cross-chain data verification with attestation proofs
79
-
- Manipulation-resistant market data feeds
80
-
81
-
2.**Privacy-Preserving DeFi Analytics**
82
-
- Based on "Privacy-Preserving Analytics for DeFi with Homomorphic Encryption"
83
-
- Zero-knowledge portfolio analysis
84
-
- Confidential trading strategy execution
85
-
- Secure multi-party computation for pooled investments
86
-
87
-
3.**Autonomous Market Making**
88
-
- Implementation of "AI-Driven Automated Market Making with Privacy Guarantees"
89
-
- Dynamic liquidity provision
90
-
- TEE-protected strategy parameters
91
-
- Real-time market efficiency optimization
92
-
93
-
4.**Cross-Chain Arbitrage Bot**
94
-
- Builds on "Secure Cross-Chain Arbitrage with TEEs"
95
-
- Multi-chain price analysis
96
-
- Protected execution environment for strategies
97
-
- Verifiable profit calculations
98
-
99
-
5.**Secure On-Chain AI Models**
100
-
- Based on "Deploying Neural Networks on Smart Contract Platforms"
101
-
- Model weight protection in TEE
102
-
- Verifiable inference results
103
-
- Dynamic model updates with attestation
104
-
105
-
6.**Risk Assessment System**
106
-
- Implementation of ["AI-Based Risk Scoring in DeFi Lending"](https://doi.org/10.1145/3567647.3567649) (Smith et al., ACM AFT 2024)
107
-
- Real-time protocol risk analysis
108
-
- Secure credit scoring models
109
-
- Attestable risk calculations
105
+
106
+
## 💡 Example Use Cases & Project Ideas
107
+
108
+
Below are several detailed project ideas demonstrating how the template can be used to build autonomous AI agents for Flare's DeFi ecosystem. Each idea outlines the practical use of the template's components and usability.
109
+
110
+
### Autonomous Wallet Manager
111
+
112
+
**Idea**: An AI agent that automatically creates wallets, monitors balances, and manages keys securely.
113
+
114
+
**Usage Details**:
115
+
-**Wallet Creation & Backup**: Use the blockchain module to generate new wallet addresses while securely storing private keys within the TEE. The template allows you to integrate backup mechanisms with attestation proofs that confirm key security.
116
+
-**Real-time Monitoring**: Leverage the blockchain explorer integration to monitor wallet activity continuously. The AI agent can analyze transaction data and trigger alerts or automated security actions if anomalies are detected.
117
+
-**TEE Integration**: All sensitive wallet operations are executed within the TEE, ensuring keys remain isolated. The template's attestation mechanisms provide verifiable logs for every wallet creation and management operation.
118
+
119
+
### Token Transfer Optimizer
120
+
121
+
**Idea**: An agent that analyzes market conditions in real time to execute token transfers for liquidity optimization or arbitrage.
122
+
123
+
**Usage Details**:
124
+
-**Market Analysis**: Integrate external data feeds into the AI provider module for real-time market insights. The agent can decide optimal moments for transfers based on analyzed market conditions.
125
+
-**Secure Transaction Execution**: Use the blockchain module to handle token transfers. With TEE-backed transaction signing, every transfer is secured and accompanied by attestation proofs for independent verification.
126
+
-**Verifiable Operations**: The template ensures that all transfers are logged with cryptographic proofs, enabling third-party verification of the autonomous decision-making process.
127
+
128
+
### Smart Contract Interaction Bot
129
+
130
+
**Idea**: An AI agent that interacts with smart contracts for activities like yield farming, staking, or decentralized lending.
131
+
132
+
**Usage Details**:
133
+
-**Automated Contract Calls**: Extend the blockchain integration with methods for interacting with smart contracts. The agent can autonomously call functions like deposit, withdraw, or claim rewards based on market signals.
134
+
-**Secure and Verifiable Interactions**: Execute all contract calls within the TEE, generating attestation proofs that validate each interaction. This ensures that the operations are secure and can be audited independently.
135
+
-**Real-time Feedback**: Incorporate a verification layer to monitor the outcomes of smart contract interactions and adjust the agent's behavior accordingly.
136
+
137
+
### DeFi Risk Management Agent
138
+
139
+
**Idea**: An autonomous agent that continuously assesses risk across multiple DeFi protocols and initiates risk mitigation strategies.
140
+
141
+
**Usage Details**:
142
+
-**Risk Analytics**: Utilize the AI provider module to integrate risk scoring algorithms and gather on-chain data from multiple protocols. The agent can calculate real-time risk scores and identify potential vulnerabilities.
143
+
-**Automated Portfolio Rebalancing**: Use the blockchain module to trigger asset rebalancing operations when predefined risk thresholds are met. These actions are executed within the TEE for enhanced security.
144
+
-**Transparent Reporting**: Generate verifiable attestation reports that detail the risk assessments and the agent's corresponding actions, building trust in the autonomous risk management process.
145
+
146
+
### Cross-Protocol Aggregator
147
+
148
+
**Idea**: An AI agent that aggregates data from various DeFi protocols, compares yields, and executes cross-chain asset management strategies.
149
+
150
+
**Usage Details**:
151
+
-**Data Aggregation**: Modify the AI provider layer to fetch data from multiple blockchain networks. The agent can compare performance metrics and yield information across different protocols.
152
+
-**Cross-Chain Operations**: Extend the blockchain module to support multi-chain interactions. Secure cross-chain transfers are managed within the TEE, with each operation generating an attestation proof.
153
+
-**Verifiable Cross-Chain Actions**: The template's design allows you to implement audit trails for every cross-chain action, ensuring that asset management decisions are both secure and transparent.
154
+
155
+
### Autonomous Investment Advisor
156
+
157
+
**Idea**: An AI-driven advisor that monitors market trends, suggests asset allocations, and executes trades autonomously.
158
+
159
+
**Usage Details**:
160
+
-**Market Trend Analysis**: Integrate additional AI models or external data feeds to analyze market trends. The agent can use these insights to recommend strategic asset reallocations.
161
+
-**Automated Trade Execution**: Leverage the wallet management and token transfer modules to execute trades automatically. All trade executions occur within the TEE, ensuring secure and attested transactions.
162
+
-**Transparency & Verification**: Each trade recommendation and execution is accompanied by an attestation proof, providing a verifiable record of the decision-making process.
110
163
111
164
## 🔒 Security Features
112
165
113
-
-**TEE Protection**: All sensitive operations run in a Trusted Execution Environment
-**Secure Key Management**: Private keys never leave the TEE
116
-
-**Transaction Validation**: Multi-level verification of all blockchain operations
117
-
-**Model Protection**: AI model weights and parameters secured within TEE
118
-
-**Verifiable Execution**: All AI inferences produce attestation proofs
166
+
***TEE Protection**: All sensitive operations—including key management and transaction signing—are executed within a Trusted Execution Environment, ensuring that critical data remains isolated.
167
+
***Remote Attestation**: vTPM-based attestation generates verifiable proofs for each operation, allowing for independent audits and trust verification.
168
+
***Certificate-Based Validation**: Robust validation mechanisms check the integrity of certificates and fingerprints to guard against tampering.
169
+
***Secure Key Management**: Private keys and sensitive data are confined within the TEE, preventing exposure to insecure environments.
170
+
***Verifiable Execution**: Every autonomous operation produces an attestation log, offering a transparent audit trail for all critical actions.
119
171
120
172
## 📚 Core APIs
121
173
122
174
### FlareProvider
123
-
Handles all Flare Network interactions:
124
-
- Account generation and management
125
-
- Transaction processing and validation
126
-
- Real-time balance monitoring
127
-
- Smart contract deployment and interaction
128
-
- Cross-chain asset bridging
175
+
Manages all Flare Network operations:
176
+
-**Account Generation & Management**: Create and manage secure wallet addresses.
177
+
-**Transaction Processing & Validation**: Build, sign, and submit transactions with built-in verification.
0 commit comments