@elizaos/plugin-aave 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.npmignore ADDED
@@ -0,0 +1,11 @@
1
+ src/
2
+ .env*
3
+ *.log
4
+ .DS_Store
5
+ .turbo/
6
+ coverage/
7
+ .nyc_output/
8
+ tsconfig.json
9
+ tsup.config.ts
10
+ *.test.ts
11
+ __tests__/
package/README.md ADDED
@@ -0,0 +1,443 @@
1
+ # @elizaos/plugin-aave
2
+
3
+ Aave V3 integration plugin for ElizaOS, enabling AI agents to interact with the Aave lending protocol on Base L2.
4
+
5
+ ## Overview
6
+
7
+ The Aave plugin provides comprehensive DeFi lending and borrowing capabilities through natural language interactions. It integrates with Aave V3 protocol on Base L2, allowing agents to:
8
+
9
+ - Supply assets to earn yield
10
+ - Borrow assets with flexible interest rates
11
+ - Manage collateral and health factors
12
+ - Execute flash loans
13
+ - Optimize interest rates and capital efficiency
14
+
15
+ ## Features
16
+
17
+ ### Core Lending Operations
18
+ - **Supply Assets**: Deposit tokens to earn interest with automatic APY tracking
19
+ - **Borrow Assets**: Take loans with stable or variable rates
20
+ - **Repay Debt**: Pay back borrowed assets partially or fully
21
+ - **Withdraw Assets**: Remove supplied tokens while maintaining safe positions
22
+
23
+ ### Advanced Features
24
+ - **Rate Switching**: Switch between stable and variable interest rates to optimize costs
25
+ - **Collateral Management**: Enable/disable assets as collateral with risk analysis
26
+ - **Efficiency Mode (eMode)**: Maximize capital efficiency for correlated assets (up to 97% LTV for stablecoins)
27
+ - **Flash Loans**: Execute complex DeFi strategies without upfront capital
28
+
29
+ ### Risk Management
30
+ - **Health Factor Monitoring**: Real-time position health tracking with alerts
31
+ - **Liquidation Prevention**: Proactive alerts and recommendations to avoid liquidation
32
+ - **Position Analysis**: Comprehensive view of supplies, borrows, and risk metrics
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ bun add @elizaos/plugin-aave
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ ### Required Environment Variables
43
+
44
+ ```env
45
+ # Network Configuration
46
+ AAVE_NETWORK=base # or 'base-sepolia' for testnet
47
+ BASE_RPC_URL=https://... # Base L2 RPC endpoint
48
+
49
+ # Wallet Configuration
50
+ WALLET_PRIVATE_KEY=0x... # Private key for transactions
51
+
52
+ # Optional Settings
53
+ HEALTH_FACTOR_ALERT=1.5 # Health factor threshold for alerts (default: 1.5)
54
+ FLASH_LOAN_MAX_FEE=0.1 # Maximum acceptable flash loan fee % (default: 0.1)
55
+ ```
56
+
57
+ ## Usage
58
+
59
+ ### Register the Plugin
60
+
61
+ ```typescript
62
+ import { aavePlugin } from '@elizaos/plugin-aave';
63
+ import { ElizaAgent } from '@elizaos/core';
64
+
65
+ const agent = new ElizaAgent({
66
+ plugins: [aavePlugin],
67
+ // ... other configuration
68
+ });
69
+ ```
70
+
71
+ ### Using Individual Actions
72
+
73
+ You can import and use individual actions:
74
+
75
+ ```typescript
76
+ import { supplyAction, borrowAction, repayAction } from '@elizaos/plugin-aave';
77
+
78
+ console.log(supplyAction.name); // "AAVE_SUPPLY"
79
+ console.log(supplyAction.description); // "Supply assets to Aave V3 lending protocol"
80
+
81
+ // Validate a message
82
+ const isValid = supplyAction.validate(runtime, message);
83
+
84
+ // Handle a message
85
+ const result = await supplyAction.handler(runtime, message, state, options, callback);
86
+ ```
87
+
88
+ ### Example Interactions
89
+
90
+ #### Supply Assets
91
+ ```
92
+ User: "I want to supply 1000 USDC to Aave"
93
+ Agent: "I'll help you supply 1000 USDC to Aave V3. Let me process this transaction for you."
94
+
95
+ ✅ Successfully supplied 1000 USDC to Aave V3!
96
+ Transaction hash: 0x123...
97
+ aToken balance: 1000.00 aUSDC
98
+ Current APY: 3.5%
99
+ Collateral enabled: Yes
100
+ Your USDC is now earning interest at 3.5% APY.
101
+ ```
102
+
103
+ #### Borrow Assets
104
+ ```
105
+ User: "Borrow 500 USDC with variable rate"
106
+ Agent: "I'll process your request to borrow 500 USDC with a variable interest rate."
107
+
108
+ ✅ Successfully borrowed 500 USDC from Aave V3!
109
+ Transaction hash: 0x456...
110
+ Interest rate mode: variable
111
+ Current rate: 5.2%
112
+ Health factor: 2.45 🟢 SAFE
113
+ ```
114
+
115
+ #### Check Position
116
+ ```
117
+ User: "What's my Aave position?"
118
+ Agent: Current Aave V3 Position:
119
+
120
+ Supplied assets:
121
+ - 1000.0000 USDC (APY: 3.50%) ✓ Collateral
122
+
123
+ Borrowed assets:
124
+ - 500.0000 USDC (Variable: 5.20%)
125
+
126
+ Position Metrics:
127
+ - Total Collateral: $1000.00
128
+ - Total Debt: $500.00
129
+ - Available to Borrow: $450.00
130
+ - Health Factor: 2.45 🟢 SAFE
131
+ - Current LTV: 50.0%
132
+ - Liquidation Threshold: 80.0%
133
+ - Efficiency Mode: Disabled
134
+ ```
135
+
136
+ #### Enable Efficiency Mode
137
+ ```
138
+ User: "Enable efficiency mode for stablecoins"
139
+ Agent: "I'll enable efficiency mode category 1 (stablecoins) to maximize your capital efficiency."
140
+
141
+ ✅ Successfully enabled efficiency mode!
142
+ Transaction hash: 0x789...
143
+ eMode Category: Stablecoins (ID: 1)
144
+
145
+ Improvements achieved:
146
+ - LTV: +17% (better borrowing power)
147
+ - Liquidation threshold: +3% (safer position)
148
+ ```
149
+
150
+ ## Actions
151
+
152
+ ### SupplyAction
153
+ Supplies assets to Aave V3 markets.
154
+ - **Triggers**: "supply", "deposit", "lend to aave"
155
+ - **Parameters**: asset, amount, enableCollateral (default: true)
156
+ - **Validation**: Balance check, market availability
157
+ - **Returns**: aToken balance, APY, collateral status
158
+
159
+ ### BorrowAction
160
+ Borrows assets from Aave V3.
161
+ - **Triggers**: "borrow", "take loan from aave"
162
+ - **Parameters**: asset, amount, rateMode (stable/variable)
163
+ - **Validation**: Health factor check, borrowing capacity
164
+ - **Returns**: Debt position, interest rate, health factor
165
+
166
+ ### RepayAction
167
+ Repays borrowed assets.
168
+ - **Triggers**: "repay", "pay back debt"
169
+ - **Parameters**: asset, amount (-1 for full), rateMode
170
+ - **Validation**: Balance check, debt verification
171
+ - **Returns**: Remaining debt, updated health factor
172
+
173
+ ### WithdrawAction
174
+ Withdraws supplied assets.
175
+ - **Triggers**: "withdraw from aave"
176
+ - **Parameters**: asset, amount (-1 for all)
177
+ - **Validation**: Collateral requirements, health factor impact
178
+ - **Returns**: Remaining supply, health factor
179
+
180
+ ### RateSwitchAction
181
+ Switches between stable and variable rates.
182
+ - **Triggers**: "switch rate", "change rate"
183
+ - **Parameters**: asset, targetRateMode
184
+ - **Analysis**: Rate comparison, projected savings
185
+ - **Returns**: New rate, savings projection
186
+
187
+ ### CollateralManagementAction
188
+ Manages collateral settings for supplied assets.
189
+ - **Triggers**: "enable/disable collateral"
190
+ - **Parameters**: asset, enable (true/false)
191
+ - **Analysis**: Health factor impact, borrowing capacity change
192
+ - **Returns**: Collateral status, position changes
193
+
194
+ ### eModeAction
195
+ Manages efficiency mode settings.
196
+ - **Triggers**: "enable/disable emode", "efficiency mode"
197
+ - **Categories**:
198
+ - 0: Disabled (standard mode)
199
+ - 1: Stablecoins (up to 97% LTV)
200
+ - 2: ETH-correlated (up to 90% LTV)
201
+ - **Validation**: Asset compatibility check
202
+ - **Returns**: LTV improvements, optimization benefits
203
+
204
+ ### FlashLoanAction
205
+ Prepares flash loan parameters.
206
+ - **Triggers**: "flash loan"
207
+ - **Parameters**: assets[], amounts[]
208
+ - **Fee**: 0.05% on Aave V3
209
+ - **Note**: Requires custom receiver contract implementation
210
+
211
+ ## Providers
212
+
213
+ ### PositionContextProvider
214
+ Provides comprehensive position data for agent context.
215
+ - Supplies with APY and collateral status
216
+ - Borrows with rate mode and current rates
217
+ - Health factor with risk assessment
218
+ - Total collateral and debt values
219
+ - eMode status
220
+
221
+ ### HealthFactorProvider
222
+ Provides detailed health factor analysis.
223
+ - Risk level assessment (CRITICAL/RISKY/MODERATE/SAFE/VERY SAFE)
224
+ - Liquidation risk calculation
225
+ - Safety recommendations
226
+ - LTV utilization metrics
227
+
228
+ ## Evaluators
229
+
230
+ ### EfficiencyModeEvaluator
231
+ Post-interaction analysis of efficiency mode effectiveness.
232
+ - Asset compatibility scoring
233
+ - LTV utilization assessment
234
+ - Optimization recommendations
235
+ - Learning from eMode changes
236
+
237
+ ### InterestOptimizationEvaluator
238
+ Analyzes interest rate optimization after rate-related actions.
239
+ - Supply APY evaluation
240
+ - Borrow rate analysis
241
+ - Rate switching effectiveness
242
+ - Interest optimization insights
243
+
244
+ ## Services
245
+
246
+ ### AaveService
247
+ Core service for Aave V3 protocol interactions.
248
+ - Protocol operation management
249
+ - Transaction execution with retries
250
+ - Position data caching
251
+ - Health factor monitoring
252
+ - Error handling and recovery
253
+
254
+ ### WalletService
255
+ Manages wallet operations and token approvals.
256
+ - Secure transaction signing
257
+ - Balance checking (native & ERC20)
258
+ - Automatic token approvals
259
+ - Gas estimation and management
260
+
261
+ ## Supported Assets on Base
262
+
263
+ - **ETH** - Ethereum
264
+ - **USDC** - USD Coin
265
+ - **USDbC** - USD Base Coin
266
+ - **DAI** - Dai Stablecoin
267
+ - **cbETH** - Coinbase Wrapped Staked ETH
268
+ - **wstETH** - Wrapped Liquid Staked Ether
269
+
270
+ ## Safety Features
271
+
272
+ 1. **Health Factor Monitoring**
273
+ - Continuous background monitoring
274
+ - Configurable alert thresholds
275
+ - Automatic warnings below 1.5
276
+
277
+ 2. **Transaction Validation**
278
+ - Pre-flight balance checks
279
+ - Gas estimation and validation
280
+ - Slippage protection
281
+
282
+ 3. **Error Recovery**
283
+ - Comprehensive error messages
284
+ - Actionable suggestions
285
+ - Transaction retry logic
286
+
287
+ 4. **Risk Analysis**
288
+ - Position health assessment
289
+ - Liquidation risk calculation
290
+ - Collateral optimization suggestions
291
+
292
+ ## Development
293
+
294
+ ### Building
295
+ ```bash
296
+ bun run build
297
+ ```
298
+
299
+ ### Testing
300
+ ```bash
301
+ bun test tests/
302
+ ```
303
+
304
+ Tests are located in the `tests/` directory at the package root:
305
+ ```
306
+ tests/
307
+ ├── actions/ # Action-specific tests
308
+ ├── services/ # Service tests
309
+ ├── providers/ # Provider tests
310
+ ├── evaluators/ # Evaluator tests
311
+ └── integration/ # Integration tests
312
+ ```
313
+
314
+ ### Linting
315
+ ```bash
316
+ bun run lint
317
+ bun run format
318
+ ```
319
+
320
+ ## Architecture
321
+
322
+ The plugin follows ElizaOS's architecture patterns:
323
+
324
+ ```
325
+ User Input → Action → Service → Aave V3 Protocol
326
+
327
+ Provider → Context for agent
328
+
329
+ Post-interaction → Evaluator → Learning
330
+ ```
331
+
332
+ ### Architecture Components
333
+
334
+ **Actions** handle user commands and validation:
335
+ ```typescript
336
+ export const supplyAction: Action = {
337
+ name: 'AAVE_SUPPLY',
338
+ description: 'Supply assets to Aave V3 lending protocol',
339
+ validate: (runtime: IAgentRuntime, message: Memory): boolean => {
340
+ // Check if message is about supplying to Aave
341
+ },
342
+ handler: async (runtime, message, state, options, callback) => {
343
+ // Execute supply transaction
344
+ },
345
+ examples: [
346
+ // User interaction examples
347
+ ]
348
+ };
349
+ ```
350
+
351
+ **Services** manage state and external integrations - AaveService handles protocol interactions, WalletService manages wallet operations.
352
+
353
+ **Providers** supply read-only context - PositionContextProvider gives current Aave positions, HealthFactorProvider analyzes liquidation risk.
354
+
355
+ **Evaluators** enable post-interaction learning - analyze efficiency and interest optimization decisions.
356
+
357
+ ## Security Considerations
358
+
359
+ 1. **Private Key Security**
360
+ - Never commit private keys
361
+ - Use environment variables
362
+ - Consider using hardware wallets for production
363
+
364
+ 2. **Transaction Safety**
365
+ - All transactions require explicit user commands
366
+ - Health factor checks prevent unsafe operations
367
+ - Automatic token approvals with exact amounts
368
+
369
+ 3. **Risk Management**
370
+ - Monitor health factor continuously
371
+ - Understand liquidation mechanics
372
+ - Test on testnet before mainnet
373
+
374
+ ## Troubleshooting
375
+
376
+ ### Common Issues
377
+
378
+ 1. **"Insufficient Balance"**
379
+ - Check wallet balance for the asset
380
+ - Ensure enough ETH for gas fees
381
+ - Verify token decimals
382
+
383
+ 2. **"Health Factor Too Low"**
384
+ - Current HF below threshold (1.2)
385
+ - Supply more collateral
386
+ - Repay some debt
387
+
388
+ 3. **"Asset Not Supported"**
389
+ - Asset not listed on Aave V3 Base
390
+ - Check supported assets list
391
+ - Use correct token symbol
392
+
393
+ 4. **"Rate Switch Failed"**
394
+ - Some assets only support variable rates
395
+ - Check if stable rate is available
396
+ - Verify cooldown period
397
+
398
+ 5. **"eMode Incompatible Assets"**
399
+ - Mix of incompatible asset types
400
+ - Category 1: Stablecoins only
401
+ - Category 2: ETH assets only
402
+
403
+ ## Resources
404
+
405
+ - [Aave V3 Documentation](https://docs.aave.com/developers/)
406
+ - [Base L2 Documentation](https://docs.base.org/)
407
+ - [ElizaOS Documentation](https://elizaos.ai/docs)
408
+ - [Aave Base Deployment](https://docs.aave.com/developers/deployed-contracts/v3-mainnet/base)
409
+
410
+ ## Contributing
411
+
412
+ Contributions are welcome! Please:
413
+
414
+ 1. Fork the repository
415
+ 2. Create a feature branch
416
+ 3. Write tests for new features
417
+ 4. Ensure all tests pass
418
+ 5. Submit a pull request
419
+
420
+ ## License
421
+
422
+ MIT License - see LICENSE file for details
423
+
424
+ ## Support
425
+
426
+ For issues and questions:
427
+ - **GitHub Issues**: [elizaos/eliza](https://github.com/elizaos/eliza/issues)
428
+ - **Discord**: [ElizaOS Community](https://discord.gg/elizaos)
429
+ - **Documentation**: [docs.elizaos.ai](https://docs.elizaos.ai)
430
+
431
+ ## Disclaimer
432
+
433
+ This plugin interacts with DeFi protocols which carry financial risks:
434
+ - Smart contract risk
435
+ - Liquidation risk
436
+ - Interest rate volatility
437
+ - Impermanent loss
438
+
439
+ Always:
440
+ - Do your own research
441
+ - Test on testnet first
442
+ - Never invest more than you can afford to lose
443
+ - Keep private keys secure