@elizaos/plugin-aave 1.0.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.
@@ -0,0 +1,590 @@
1
+ import { Service, IAgentRuntime, Action, Provider, Plugin } from '@elizaos/core';
2
+
3
+ /**
4
+ * Aave V3 Interest Rate Mode enumeration
5
+ * Defines the type of interest rate for borrowing operations
6
+ */
7
+ declare enum InterestRateMode {
8
+ /** Stable interest rate mode */
9
+ STABLE = 1,
10
+ /** Variable interest rate mode */
11
+ VARIABLE = 2
12
+ }
13
+ /**
14
+ * Aave Error Code enumeration
15
+ * Standardized error codes for Aave operations
16
+ */
17
+ declare enum AaveErrorCode {
18
+ /** Unknown or unhandled error */
19
+ UNKNOWN = "UNKNOWN",
20
+ /** Insufficient balance for operation */
21
+ INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
22
+ /** Insufficient collateral for borrowing */
23
+ INSUFFICIENT_COLLATERAL = "INSUFFICIENT_COLLATERAL",
24
+ /** Asset not supported by Aave */
25
+ ASSET_NOT_SUPPORTED = "ASSET_NOT_SUPPORTED",
26
+ /** Borrowing not enabled for asset */
27
+ BORROWING_NOT_ENABLED = "BORROWING_NOT_ENABLED",
28
+ /** Stable borrowing not enabled for asset */
29
+ STABLE_BORROWING_NOT_ENABLED = "STABLE_BORROWING_NOT_ENABLED",
30
+ /** Position would be liquidated */
31
+ HEALTH_FACTOR_TOO_LOW = "HEALTH_FACTOR_TOO_LOW",
32
+ /** Contract interaction failed */
33
+ TRANSACTION_FAILED = "TRANSACTION_FAILED",
34
+ /** Invalid parameters provided */
35
+ INVALID_PARAMETERS = "INVALID_PARAMETERS",
36
+ /** User already has stable rate loan */
37
+ USER_HAS_STABLE_RATE_LOAN = "USER_HAS_STABLE_RATE_LOAN",
38
+ /** Amount exceeds maximum allowed */
39
+ AMOUNT_TOO_HIGH = "AMOUNT_TOO_HIGH",
40
+ /** Pool is paused */
41
+ POOL_PAUSED = "POOL_PAUSED",
42
+ /** Reserve is frozen */
43
+ RESERVE_FROZEN = "RESERVE_FROZEN",
44
+ /** Reserve is not active */
45
+ RESERVE_INACTIVE = "RESERVE_INACTIVE",
46
+ /** Service initialization failed */
47
+ INITIALIZATION_FAILED = "INITIALIZATION_FAILED",
48
+ /** Connection to protocol failed */
49
+ CONNECTION_FAILED = "CONNECTION_FAILED",
50
+ /** Service not initialized */
51
+ SERVICE_NOT_INITIALIZED = "SERVICE_NOT_INITIALIZED",
52
+ /** Wallet not connected */
53
+ WALLET_NOT_CONNECTED = "WALLET_NOT_CONNECTED",
54
+ /** Transaction generation failed */
55
+ TRANSACTION_GENERATION_FAILED = "TRANSACTION_GENERATION_FAILED",
56
+ /** Supply operation failed */
57
+ SUPPLY_FAILED = "SUPPLY_FAILED",
58
+ /** Withdraw operation failed */
59
+ WITHDRAW_FAILED = "WITHDRAW_FAILED",
60
+ /** Borrow operation failed */
61
+ BORROW_FAILED = "BORROW_FAILED",
62
+ /** Repay operation failed */
63
+ REPAY_FAILED = "REPAY_FAILED",
64
+ /** Data fetch operation failed */
65
+ DATA_FETCH_FAILED = "DATA_FETCH_FAILED",
66
+ /** Asset not found */
67
+ ASSET_NOT_FOUND = "ASSET_NOT_FOUND",
68
+ /** Unsupported asset */
69
+ UNSUPPORTED_ASSET = "UNSUPPORTED_ASSET",
70
+ /** No borrowing capacity */
71
+ NO_BORROW_CAPACITY = "NO_BORROW_CAPACITY",
72
+ /** Unsupported operation on this chain */
73
+ UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION"
74
+ }
75
+ /**
76
+ * Custom error class for Aave operations
77
+ */
78
+ declare class AaveError extends Error {
79
+ /** Error code for programmatic handling */
80
+ readonly code: AaveErrorCode;
81
+ /** Original error that caused this error */
82
+ readonly cause?: Error;
83
+ /** Additional context about the error */
84
+ readonly context?: Record<string, any>;
85
+ constructor(message: string, code?: AaveErrorCode, cause?: Error, context?: Record<string, any>);
86
+ }
87
+ /**
88
+ * Configuration for Aave V3 Protocol
89
+ */
90
+ interface AaveConfig {
91
+ /** Network name */
92
+ network: string;
93
+ /** RPC URL for blockchain connection */
94
+ rpcUrl: string;
95
+ /** Pool contract address */
96
+ poolAddress: string;
97
+ /** Pool data provider contract address */
98
+ poolDataProviderAddress: string;
99
+ /** UI Pool data provider contract address */
100
+ uiPoolDataProviderAddress: string;
101
+ /** WETH Gateway contract address */
102
+ wethGatewayAddress: string;
103
+ /** Chain ID for the network */
104
+ chainId?: number;
105
+ /** Optional private key for transactions */
106
+ privateKey?: string;
107
+ /** Gas limit multiplier (default: 1.2) */
108
+ gasLimitMultiplier?: number;
109
+ /** Max fee per gas in wei */
110
+ maxFeePerGas?: string;
111
+ /** Max priority fee per gas in wei */
112
+ maxPriorityFeePerGas?: string;
113
+ }
114
+ /**
115
+ * Parameters for supply operation
116
+ */
117
+ interface SupplyParams {
118
+ /** Asset address to supply */
119
+ asset: string;
120
+ /** Amount to supply (in asset decimals) */
121
+ amount: BigNumber;
122
+ /** User address performing the supply */
123
+ user: string;
124
+ /** Address to receive aTokens (usually same as user) */
125
+ onBehalfOf?: string;
126
+ /** Referral code for supply operation */
127
+ referralCode?: number;
128
+ }
129
+ /**
130
+ * Result of a supply operation
131
+ */
132
+ interface SupplyResult {
133
+ /** Whether the operation was successful */
134
+ success: boolean;
135
+ /** Transaction hash */
136
+ transactionHash?: string;
137
+ /** Amount supplied */
138
+ suppliedAmount: BigNumber;
139
+ /** aToken amount received */
140
+ aTokenAmount: BigNumber;
141
+ /** New aToken balance after supply */
142
+ newATokenBalance: BigNumber;
143
+ /** Gas used for the transaction */
144
+ gasUsed?: BigNumber;
145
+ /** Error information if operation failed */
146
+ error?: AaveError;
147
+ }
148
+ /**
149
+ * Parameters for withdraw operation
150
+ */
151
+ interface WithdrawParams {
152
+ /** Asset address to withdraw */
153
+ asset: string;
154
+ /** Amount to withdraw (in asset decimals, use MAX_UINT256 for max) */
155
+ amount: BigNumber;
156
+ /** User address performing the withdraw */
157
+ user: string;
158
+ /** Address to receive withdrawn assets */
159
+ to?: string;
160
+ }
161
+ /**
162
+ * Result of a withdraw operation
163
+ */
164
+ interface WithdrawResult {
165
+ /** Whether the operation was successful */
166
+ success: boolean;
167
+ /** Transaction hash */
168
+ transactionHash?: string;
169
+ /** Amount withdrawn */
170
+ amountWithdrawn: BigNumber;
171
+ /** Remaining aToken balance after withdraw */
172
+ remainingATokenBalance: BigNumber;
173
+ /** New health factor after withdrawal */
174
+ newHealthFactor?: number;
175
+ /** Gas used for the transaction */
176
+ gasUsed?: BigNumber;
177
+ /** Error information if operation failed */
178
+ error?: AaveError;
179
+ }
180
+ /**
181
+ * Parameters for borrow operation
182
+ */
183
+ interface BorrowParams {
184
+ /** Asset address to borrow */
185
+ asset: string;
186
+ /** Amount to borrow (in asset decimals) */
187
+ amount: BigNumber;
188
+ /** Interest rate mode (stable or variable) */
189
+ interestRateMode: InterestRateMode;
190
+ /** User address performing the borrow */
191
+ user: string;
192
+ /** Address to receive borrowed assets */
193
+ onBehalfOf?: string;
194
+ /** Referral code for borrow operation */
195
+ referralCode?: number;
196
+ }
197
+ /**
198
+ * Result of a borrow operation
199
+ */
200
+ interface BorrowResult {
201
+ /** Whether the operation was successful */
202
+ success: boolean;
203
+ /** Transaction hash */
204
+ transactionHash?: string;
205
+ /** Amount borrowed */
206
+ amountBorrowed: BigNumber;
207
+ /** Interest rate mode used */
208
+ interestRateMode: InterestRateMode;
209
+ /** Current borrow APY at time of borrowing */
210
+ currentBorrowAPY: number;
211
+ /** Health factor after borrowing */
212
+ newHealthFactor: number;
213
+ /** Gas used for the transaction */
214
+ gasUsed?: BigNumber;
215
+ /** Error information if operation failed */
216
+ error?: AaveError;
217
+ }
218
+ /**
219
+ * Parameters for repay operation
220
+ */
221
+ interface RepayParams {
222
+ /** Asset address to repay */
223
+ asset: string;
224
+ /** Amount to repay (in asset decimals, use MAX_UINT256 for full repay) */
225
+ amount: BigNumber;
226
+ /** Interest rate mode of the debt being repaid */
227
+ interestRateMode: InterestRateMode;
228
+ /** User address performing the repay */
229
+ user: string;
230
+ /** Address whose debt is being repaid */
231
+ onBehalfOf?: string;
232
+ }
233
+ /**
234
+ * Result of a repay operation
235
+ */
236
+ interface RepayResult {
237
+ /** Whether the operation was successful */
238
+ success: boolean;
239
+ /** Transaction hash */
240
+ transactionHash?: string;
241
+ /** Amount repaid */
242
+ amountRepaid: BigNumber;
243
+ /** Interest rate mode of repaid debt */
244
+ interestRateMode: InterestRateMode;
245
+ /** Remaining total debt balance */
246
+ remainingDebt: BigNumber;
247
+ /** Health factor after repaying */
248
+ newHealthFactor: number;
249
+ /** Gas used for the transaction */
250
+ gasUsed?: BigNumber;
251
+ /** Optional approval transaction hash */
252
+ approvalTransactionHash?: string;
253
+ /** Error information if operation failed */
254
+ error?: AaveError;
255
+ }
256
+ /**
257
+ * User's position in a specific asset
258
+ */
259
+ interface AssetPosition {
260
+ /** Asset address */
261
+ asset: string;
262
+ /** Asset symbol (e.g., USDC, ETH) */
263
+ symbol: string;
264
+ /** Asset name */
265
+ name: string;
266
+ /** Number of decimals for the asset */
267
+ decimals: number;
268
+ /** aToken address for this asset */
269
+ aTokenAddress: string;
270
+ /** Stable debt token address */
271
+ stableDebtTokenAddress: string;
272
+ /** Variable debt token address */
273
+ variableDebtTokenAddress: string;
274
+ /** Supply position */
275
+ supplied: {
276
+ /** Amount supplied (in asset decimals) */
277
+ amount: BigNumber;
278
+ /** aToken balance */
279
+ aTokenBalance: BigNumber;
280
+ /** Current supply APY */
281
+ supplyAPY: BigNumber;
282
+ /** Value in USD */
283
+ valueUSD: BigNumber;
284
+ };
285
+ /** Borrow position */
286
+ borrowed: {
287
+ /** Stable rate debt amount */
288
+ stableDebt: BigNumber;
289
+ /** Variable rate debt amount */
290
+ variableDebt: BigNumber;
291
+ /** Total debt amount */
292
+ totalDebt: BigNumber;
293
+ /** Current stable borrow APY */
294
+ stableBorrowAPY: BigNumber;
295
+ /** Current variable borrow APY */
296
+ variableBorrowAPY: BigNumber;
297
+ /** Value in USD */
298
+ valueUSD: BigNumber;
299
+ };
300
+ /** Collateral status */
301
+ isCollateral: boolean;
302
+ /** Can be used as collateral */
303
+ canBeCollateral: boolean;
304
+ /** Asset can be borrowed */
305
+ canBorrow: boolean;
306
+ /** Stable rate borrowing is enabled */
307
+ stableBorrowEnabled: boolean;
308
+ }
309
+ /**
310
+ * Simple asset position for getUserPosition
311
+ */
312
+ interface SimplePosition {
313
+ /** Asset symbol */
314
+ asset: string;
315
+ /** Amount supplied */
316
+ suppliedAmount: BigNumber;
317
+ /** Variable debt amount */
318
+ borrowedAmountVariable: BigNumber;
319
+ /** Stable debt amount */
320
+ borrowedAmountStable: BigNumber;
321
+ /** Supply APY */
322
+ supplyAPY: number;
323
+ /** Variable borrow APY */
324
+ variableBorrowAPY: number;
325
+ /** Stable borrow APY */
326
+ stableBorrowAPY: number;
327
+ /** Is used as collateral */
328
+ isCollateral: boolean;
329
+ /** Liquidation threshold */
330
+ liquidationThreshold: number;
331
+ /** Loan to value ratio */
332
+ ltv: number;
333
+ }
334
+ /**
335
+ * Complete user position across all assets
336
+ */
337
+ interface UserPosition {
338
+ /** User's wallet address */
339
+ userAddress: string;
340
+ /** Total collateral in ETH */
341
+ totalCollateralETH: BigNumber;
342
+ /** Total debt in ETH */
343
+ totalDebtETH: BigNumber;
344
+ /** Available to borrow in ETH */
345
+ availableBorrowsETH: BigNumber;
346
+ /** Current liquidation threshold */
347
+ currentLiquidationThreshold: number;
348
+ /** Loan to value ratio */
349
+ ltv: number;
350
+ /** Health factor */
351
+ healthFactor: BigNumber;
352
+ /** Individual asset positions */
353
+ positions: SimplePosition[];
354
+ /** Last updated timestamp */
355
+ lastUpdated: number;
356
+ }
357
+ /**
358
+ * Market data for a specific asset
359
+ */
360
+ interface MarketData {
361
+ /** Asset symbol */
362
+ asset: string;
363
+ /** aToken address */
364
+ aTokenAddress: string;
365
+ /** Stable debt token address */
366
+ stableDebtTokenAddress: string;
367
+ /** Variable debt token address */
368
+ variableDebtTokenAddress: string;
369
+ /** Underlying asset address */
370
+ underlyingAsset: string;
371
+ /** Asset decimals */
372
+ decimals: number;
373
+ /** Supply APY */
374
+ supplyAPY: number;
375
+ /** Variable borrow APY */
376
+ variableBorrowAPY: number;
377
+ /** Stable borrow APY */
378
+ stableBorrowAPY: number;
379
+ /** Total supply */
380
+ totalSupply: BigNumber;
381
+ /** Total borrowed */
382
+ totalBorrow: BigNumber;
383
+ /** Utilization rate */
384
+ utilizationRate: number;
385
+ /** Loan to value ratio */
386
+ ltv: number;
387
+ /** Liquidation threshold */
388
+ liquidationThreshold: number;
389
+ /** Liquidation bonus */
390
+ liquidationBonus: number;
391
+ /** Reserve factor */
392
+ reserveFactor: number;
393
+ /** Price in USD */
394
+ priceInUSD: BigNumber;
395
+ /** Is active */
396
+ isActive: boolean;
397
+ /** Is frozen */
398
+ isFrozen: boolean;
399
+ /** Is paused */
400
+ isPaused: boolean;
401
+ /** Supply cap */
402
+ supplyCap: BigNumber;
403
+ /** Borrow cap */
404
+ borrowCap: BigNumber;
405
+ /** Last updated timestamp */
406
+ lastUpdated: number;
407
+ }
408
+ /**
409
+ * Aave V3 reserve configuration data
410
+ */
411
+ interface ReserveConfigurationData {
412
+ /** Decimals of the underlying asset */
413
+ decimals: BigNumber;
414
+ /** Loan to value ratio */
415
+ ltv: BigNumber;
416
+ /** Liquidation threshold */
417
+ liquidationThreshold: BigNumber;
418
+ /** Liquidation bonus */
419
+ liquidationBonus: BigNumber;
420
+ /** Reserve factor */
421
+ reserveFactor: BigNumber;
422
+ /** Whether the reserve can be used as collateral */
423
+ usageAsCollateralEnabled: boolean;
424
+ /** Whether borrowing is enabled */
425
+ borrowingEnabled: boolean;
426
+ /** Whether stable rate borrowing is enabled */
427
+ stableBorrowRateEnabled: boolean;
428
+ /** Whether the reserve is active */
429
+ isActive: boolean;
430
+ /** Whether the reserve is frozen */
431
+ isFrozen: boolean;
432
+ }
433
+ /**
434
+ * Aave V3 reserve data from the protocol
435
+ */
436
+ interface ReserveData {
437
+ /** Configuration data */
438
+ configuration: ReserveConfigurationData;
439
+ /** Current liquidity rate */
440
+ liquidityRate: BigNumber;
441
+ /** Current stable borrow rate */
442
+ stableBorrowRate: BigNumber;
443
+ /** Current variable borrow rate */
444
+ variableBorrowRate: BigNumber;
445
+ /** Liquidity index */
446
+ liquidityIndex: BigNumber;
447
+ /** Variable borrow index */
448
+ variableBorrowIndex: BigNumber;
449
+ /** aToken address */
450
+ aTokenAddress: string;
451
+ /** Stable debt token address */
452
+ stableDebtTokenAddress: string;
453
+ /** Variable debt token address */
454
+ variableDebtTokenAddress: string;
455
+ /** Interest rate strategy address */
456
+ interestRateStrategyAddress: string;
457
+ /** Available liquidity */
458
+ availableLiquidity: BigNumber;
459
+ /** Total stable debt */
460
+ totalStableDebt: BigNumber;
461
+ /** Total variable debt */
462
+ totalVariableDebt: BigNumber;
463
+ /** Total principal stable debt */
464
+ principalStableDebt: BigNumber;
465
+ /** Average stable rate */
466
+ averageStableRate: BigNumber;
467
+ /** Last update timestamp */
468
+ lastUpdateTimestamp: BigNumber;
469
+ }
470
+ /**
471
+ * User account data from Aave
472
+ */
473
+ interface UserAccountData {
474
+ /** Total collateral in ETH */
475
+ totalCollateralETH: BigNumber;
476
+ /** Total debt in ETH */
477
+ totalDebtETH: BigNumber;
478
+ /** Available borrows in ETH */
479
+ availableBorrowsETH: BigNumber;
480
+ /** Current liquidation threshold */
481
+ currentLiquidationThreshold: number;
482
+ /** Loan to value ratio */
483
+ ltv: number;
484
+ /** Health factor */
485
+ healthFactor: BigNumber;
486
+ }
487
+ /**
488
+ * Transaction options for Aave operations
489
+ */
490
+ interface TransactionOptions {
491
+ /** Gas limit for the transaction */
492
+ gasLimit?: BigNumber;
493
+ /** Gas price in wei */
494
+ gasPrice?: BigNumber;
495
+ /** Max fee per gas for EIP-1559 */
496
+ maxFeePerGas?: BigNumber;
497
+ /** Max priority fee per gas for EIP-1559 */
498
+ maxPriorityFeePerGas?: BigNumber;
499
+ /** Transaction value in wei */
500
+ value?: BigNumber;
501
+ /** Nonce for the transaction */
502
+ nonce?: number;
503
+ }
504
+ /**
505
+ * Common constants used in Aave operations
506
+ */
507
+ declare const AAVE_CONSTANTS: {
508
+ /** Maximum uint256 value for unlimited approvals/withdrawals */
509
+ readonly MAX_UINT256: BigNumber;
510
+ /** Number of seconds in a year for APY calculations */
511
+ readonly SECONDS_PER_YEAR: BigNumber;
512
+ /** Number of ray units (1e27) used by Aave for rate calculations */
513
+ readonly RAY: BigNumber;
514
+ /** Number of wei units (1e18) */
515
+ readonly WAD: BigNumber;
516
+ /** Percentage multiplier (100 for percentage) */
517
+ readonly PERCENTAGE_FACTOR: BigNumber;
518
+ };
519
+ /**
520
+ * Helper type for operation parameters
521
+ */
522
+ type OperationParams = SupplyParams | WithdrawParams | BorrowParams | RepayParams;
523
+ /**
524
+ * Helper type for operation results
525
+ */
526
+ type OperationResult = SupplyResult | WithdrawResult | BorrowResult | RepayResult;
527
+ /**
528
+ * Type guard to check if error is AaveError
529
+ */
530
+ declare function isAaveError(error: any): error is AaveError;
531
+ /**
532
+ * Type guard to check if rate mode is valid
533
+ */
534
+ declare function isValidInterestRateMode(mode: any): mode is InterestRateMode;
535
+
536
+ declare class AaveService extends Service {
537
+ static serviceType: string;
538
+ private provider;
539
+ private signer?;
540
+ private poolService?;
541
+ private uiPoolDataProvider?;
542
+ private chainContext;
543
+ private isInitialized;
544
+ constructor(runtime?: IAgentRuntime);
545
+ get description(): string;
546
+ get capabilityDescription(): string;
547
+ initialize(runtime: IAgentRuntime): Promise<void>;
548
+ private verifyConnection;
549
+ private ensureInitialized;
550
+ private ensureSigner;
551
+ supply(params: SupplyParams): Promise<SupplyResult>;
552
+ withdraw(params: WithdrawParams): Promise<WithdrawResult>;
553
+ borrow(params: BorrowParams): Promise<BorrowResult>;
554
+ repay(params: RepayParams): Promise<RepayResult>;
555
+ getUserPosition(userAddress: string): Promise<UserPosition>;
556
+ getUserAccountData(userAddress: string): Promise<UserAccountData>;
557
+ getMarketData(): Promise<MarketData[]>;
558
+ private getReserveData;
559
+ stop(): Promise<void>;
560
+ }
561
+
562
+ declare const supplyAction: Action;
563
+
564
+ declare const withdrawAction: Action;
565
+
566
+ /**
567
+ * Action for borrowing assets from Aave V3
568
+ */
569
+ declare const borrowAction: Action;
570
+
571
+ /**
572
+ * Action for repaying debt to Aave V3
573
+ */
574
+ declare const repayAction: Action;
575
+
576
+ /**
577
+ * Provider for Aave V3 market data and lending rates
578
+ * Supplies current market conditions to inform user decisions
579
+ */
580
+ declare const marketDataProvider: Provider;
581
+
582
+ /**
583
+ * Provider for user's Aave V3 position data
584
+ * Shows current supply, borrow positions, and health metrics
585
+ */
586
+ declare const positionProvider: Provider;
587
+
588
+ declare const plugin: Plugin;
589
+
590
+ export { AAVE_CONSTANTS, type AaveConfig, AaveError, AaveErrorCode, AaveService, type AssetPosition, type BorrowParams, type BorrowResult, InterestRateMode, type MarketData, type OperationParams, type OperationResult, type RepayParams, type RepayResult, type ReserveConfigurationData, type ReserveData, type SimplePosition, type SupplyParams, type SupplyResult, type TransactionOptions, type UserAccountData, type UserPosition, type WithdrawParams, type WithdrawResult, borrowAction, plugin as default, isAaveError, isValidInterestRateMode, marketDataProvider, plugin, positionProvider, repayAction, supplyAction, withdrawAction };