UNPKG

@elizaos/plugin-moonwell

Version:

Moonwell Protocol integration plugin for ElizaOS

722 lines (704 loc) 21.2 kB
import { Service, IAgentRuntime, Action, Provider, Plugin } from '@elizaos/core'; import { MorphoMarket as MorphoMarket$1, MorphoMarketUserPosition, UserBalance, MorphoVault as MorphoVault$1, MorphoVaultUserPosition as MorphoVaultUserPosition$1, MorphoVaultSnapshot as MorphoVaultSnapshot$1 } from '@moonwell-fi/moonwell-sdk'; interface MorphoMarket { id: string; chainId: number; loanToken: { address: string; symbol: string; decimals: number; }; collateralToken: { address: string; symbol: string; decimals: number; }; oracle: string; irm: string; lltv: BigNumber; supplyAPY: number; borrowAPY: number; totalSupplyAssets: BigNumber; totalBorrowAssets: BigNumber; totalSupplyShares: BigNumber; totalBorrowShares: BigNumber; fee: BigNumber; utilization: number; priceInUSD?: number; } interface MorphoUserPosition { marketId: string; supplyShares: BigNumber; supplyAssets: BigNumber; borrowShares: BigNumber; borrowAssets: BigNumber; collateral: BigNumber; healthFactor: number; supplyAPY: number; borrowAPY: number; isCollateralEnabled: boolean; } interface MorphoReward { token: string; symbol: string; amount: BigNumber; valueInUSD: BigNumber; marketId?: string; } interface MorphoUserRewards { rewards: MorphoReward[]; totalValueInUSD: BigNumber; } interface MorphoSupplyParams { marketId: string; amount: BigNumber; enableAsCollateral?: boolean; } interface MorphoBorrowParams { marketId: string; amount: BigNumber; } interface MorphoRepayParams { marketId: string; amount: BigNumber; isMax?: boolean; } interface MorphoWithdrawParams { marketId: string; amount: BigNumber; isMax?: boolean; } interface MorphoSupplyResult { transactionHash: string; suppliedAmount: BigNumber; newSupplyShares: BigNumber; newSupplyAssets: BigNumber; currentAPY: number; collateralEnabled: boolean; } interface MorphoBorrowResult { transactionHash: string; borrowedAmount: BigNumber; newBorrowShares: BigNumber; newBorrowAssets: BigNumber; interestRate: number; healthFactor: number; } interface MorphoRepayResult { transactionHash: string; repaidAmount: BigNumber; remainingBorrowShares: BigNumber; remainingBorrowAssets: BigNumber; healthFactor: number; } interface MorphoWithdrawResult { transactionHash: string; withdrawnAmount: BigNumber; remainingSupplyShares: BigNumber; remainingSupplyAssets: BigNumber; healthFactor: number; } interface MorphoMarketInfo { id: string; name: string; loanToken: string; collateralToken: string; supplyAPY: number; borrowAPY: number; utilization: number; totalSuppliedUSD: BigNumber; totalBorrowedUSD: BigNumber; availableLiquidity: BigNumber; ltv: number; } interface MorphoPortfolio { totalSuppliedUSD: BigNumber; totalBorrowedUSD: BigNumber; netWorth: BigNumber; totalRewardsUSD: BigNumber; avgSupplyAPY: number; avgBorrowAPY: number; positions: MorphoUserPosition[]; rewards: MorphoUserRewards; } interface MorphoMarketFilters { loanToken?: string; collateralToken?: string; minSupplyAPY?: number; minBorrowAPY?: number; minLiquidity?: BigNumber; maxUtilization?: number; } interface MorphoVault { id: string; address: string; name: string; symbol: string; asset: { address: string; symbol: string; decimals: number; }; totalAssets: BigNumber; totalShares: BigNumber; sharePrice: BigNumber; apy: number; tvl: BigNumber; tvlInUSD: BigNumber; strategy: string; strategyDescription: string; curator: string; fee: BigNumber; performanceFee: BigNumber; capacity: BigNumber; available: BigNumber; utilizationRate: number; riskLevel: "LOW" | "MEDIUM" | "HIGH"; createdAt: number; lastUpdate: number; } interface MorphoVaultUserPosition { vaultId: string; vaultAddress: string; userAddress: string; shares: BigNumber; assets: BigNumber; assetsInUSD: BigNumber; entryPrice: BigNumber; currentPrice: BigNumber; unrealizedGain: BigNumber; unrealizedGainInUSD: BigNumber; unrealizedGainPercent: number; depositedAmount: BigNumber; depositedAmountInUSD: BigNumber; weightedAverageEntry: BigNumber; lastDepositTime: number; totalDeposits: number; totalWithdrawals: number; } interface MorphoVaultSnapshot { vaultId: string; timestamp: number; totalAssets: BigNumber; totalShares: BigNumber; sharePrice: BigNumber; apy: number; tvl: BigNumber; tvlInUSD: BigNumber; utilizationRate: number; performance1d: number; performance7d: number; performance30d: number; volume24h: BigNumber; uniqueDepositors: number; strategyAllocations: StrategyAllocation[]; } interface StrategyAllocation { strategy: string; allocation: BigNumber; percentage: number; apy: number; } interface MorphoVaultPerformance { vaultId: string; timeframe: "1d" | "7d" | "30d" | "90d" | "1y" | "all"; startPrice: BigNumber; endPrice: BigNumber; totalReturn: number; annualizedReturn: number; volatility: number; sharpeRatio: number; maxDrawdown: number; totalVolume: BigNumber; averageApy: number; snapshots: MorphoVaultSnapshot[]; } interface MorphoVaultDepositParams { vaultId: string; amount: BigNumber; minShares?: BigNumber; } interface MorphoVaultWithdrawParams { vaultId: string; shares?: BigNumber; amount?: BigNumber; maxShares?: BigNumber; isMaxWithdraw?: boolean; } interface MorphoVaultDepositResult { transactionHash: string; vaultId: string; depositedAmount: BigNumber; receivedShares: BigNumber; sharePrice: BigNumber; newTotalShares: BigNumber; newTotalAssets: BigNumber; } interface MorphoVaultWithdrawResult { transactionHash: string; vaultId: string; withdrawnAmount: BigNumber; burnedShares: BigNumber; sharePrice: BigNumber; newTotalShares: BigNumber; newTotalAssets: BigNumber; } interface MorphoVaultSummary { totalVaults: number; totalTVL: BigNumber; totalTVLInUSD: BigNumber; averageAPY: number; topPerformingVault: { id: string; name: string; apy: number; performance30d: number; }; riskDistribution: { low: number; medium: number; high: number; }; vaults: MorphoVault[]; } interface MorphoVaultPortfolio { userAddress: string; totalValueInUSD: BigNumber; totalUnrealizedGainInUSD: BigNumber; totalUnrealizedGainPercent: number; averageAPY: number; positions: MorphoVaultUserPosition[]; riskExposure: { low: BigNumber; medium: BigNumber; high: BigNumber; }; lastUpdated: number; } interface MorphoVaultFilters { asset?: string; minAPY?: number; maxRiskLevel?: "LOW" | "MEDIUM" | "HIGH"; minTVL?: BigNumber; strategy?: string; hasUserPosition?: boolean; } interface SupplyParams { asset: string; amount: BigNumber; enableAsCollateral: boolean; } interface SupplyResult { transactionHash: string; mTokenBalance: BigNumber; currentAPY: number; collateralEnabled: boolean; } interface BorrowParams { asset: string; amount: BigNumber; interestRateMode: "stable" | "variable"; } interface BorrowResult { transactionHash: string; borrowedAmount: BigNumber; interestRate: number; healthFactor: number; } interface RepayParams { asset: string; amount: BigNumber; isMax?: boolean; } interface RepayResult { transactionHash: string; repaidAmount: BigNumber; remainingDebt: BigNumber; healthFactor: number; } interface WithdrawParams { asset: string; amount: BigNumber; isMax?: boolean; } interface WithdrawResult { transactionHash: string; withdrawnAmount: BigNumber; remainingSupply: BigNumber; healthFactor: number; } interface UserPosition { totalSupplied: BigNumber; totalBorrowed: BigNumber; healthFactor: number; liquidationThreshold: number; availableToBorrow: BigNumber; supplies: AssetPosition[]; borrows: AssetPosition[]; } interface AssetPosition { asset: string; symbol: string; balance: BigNumber; balanceInUSD: BigNumber; apy: number; isCollateral?: boolean; liquidationThreshold?: number; } interface MarketData { asset: string; symbol: string; supplyAPY: number; borrowAPY: number; totalSupply: BigNumber; totalBorrow: BigNumber; utilizationRate: number; liquidityAvailable: BigNumber; collateralFactor: number; priceInUSD: number; } interface MoonwellError { code: MoonwellErrorCode; message: string; details?: any; suggestions?: string[]; healthFactor?: number; } declare enum MoonwellErrorCode { INVALID_AMOUNT = "INVALID_AMOUNT", UNSUPPORTED_ASSET = "UNSUPPORTED_ASSET", INVALID_PARAMETERS = "INVALID_PARAMETERS", INSUFFICIENT_COLLATERAL = "INSUFFICIENT_COLLATERAL", LIQUIDATION_RISK = "LIQUIDATION_RISK", EXCEEDS_BORROW_CAPACITY = "EXCEEDS_BORROW_CAPACITY", INSUFFICIENT_LIQUIDITY = "INSUFFICIENT_LIQUIDITY", MARKET_PAUSED = "MARKET_PAUSED", RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED", RPC_ERROR = "RPC_ERROR", TRANSACTION_FAILED = "TRANSACTION_FAILED", TIMEOUT = "TIMEOUT", WALLET_NOT_CONNECTED = "WALLET_NOT_CONNECTED", INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE", APPROVAL_REQUIRED = "APPROVAL_REQUIRED" } interface MoonwellConfig { network: "base" | "base-sepolia"; rpcUrl: string; moonwellApiUrl?: string; moonwellApiKey?: string; healthFactorThreshold: number; maxGasPrice?: BigNumber; retryAttempts: number; monitoringInterval: number; } interface Transaction { to: string; from: string; data: string; value?: string; gasLimit?: string; gasPrice?: string; } interface SignedTransaction extends Transaction { signature: string; hash?: string; } interface TransactionReceipt { transactionHash: string; blockNumber: number; blockHash: string; gasUsed: string; status: "success" | "reverted"; logs: any[]; } interface MoonwellServiceState { isInitialized: boolean; network: "base" | "base-sepolia"; userAddress?: string; positionCache?: UserPosition; marketDataCache?: MarketData[]; lastUpdate?: number; } interface MoonwellSDKConfig { network: "base" | "base-sepolia"; rpcUrl: string; apiKey?: string; } interface MoonwellMarket { address: string; symbol: string; underlyingAsset: string; supplyRate: BigNumber; borrowRate: BigNumber; totalSupply: BigNumber; totalBorrows: BigNumber; exchangeRate: BigNumber; collateralFactor: BigNumber; } interface UserReward { token: string; symbol: string; amount: BigNumber; valueInUSD: BigNumber; } interface UserRewards { rewards: UserReward[]; totalValueInUSD: BigNumber; } interface ClaimRewardsResult { transactionHash: string; rewardsClaimed: Array<{ token: string; amount: BigNumber; }>; } interface EnhancedUserBalance { tokenAddress: string; symbol: string; balance: BigNumber; balanceInUSD: BigNumber; price: number; source: "wallet" | "core" | "morpho" | "vault"; apy?: number; isCollateral?: boolean; marketId?: string; vaultId?: string; } interface BalanceBreakdown { walletBalances: EnhancedUserBalance[]; corePositions: EnhancedUserBalance[]; morphoPositions: EnhancedUserBalance[]; vaultPositions: EnhancedUserBalance[]; totalBalanceInUSD: BigNumber; totalWalletValueInUSD: BigNumber; totalCoreValueInUSD: BigNumber; totalMorphoValueInUSD: BigNumber; totalVaultValueInUSD: BigNumber; } interface ComprehensiveUserData { userAddress: string; corePosition: UserPosition; coreRewards: UserRewards; morphoMarkets: any[]; morphoPositions: any[]; morphoRewards: any; morphoVaultPortfolio: any | null; balanceBreakdown: BalanceBreakdown; portfolioSummary: PortfolioSummary; lastUpdated: number; } interface PortfolioSummary { totalNetWorth: BigNumber; totalSupplied: BigNumber; totalBorrowed: BigNumber; totalRewardsValue: BigNumber; overallHealthFactor: number; weightedAverageSupplyAPY: number; weightedAverageBorrowAPY: number; riskDistribution: { safe: BigNumber; moderate: BigNumber; high: BigNumber; critical: BigNumber; }; marketDistribution: { core: BigNumber; morpho: BigNumber; vaults: BigNumber; }; } interface UserBalanceParams { includeWallet?: boolean; includeCore?: boolean; includeMorpho?: boolean; includeVaults?: boolean; minBalanceThreshold?: BigNumber; } interface MarketSnapshot { asset: string; symbol: string; timestamp: number; supplyAPY: number; borrowAPY: number; totalSupply: BigNumber; totalBorrow: BigNumber; utilizationRate: number; liquidityAvailable: BigNumber; priceInUSD: number; volume24h: BigNumber; uniqueUsers: number; } interface MarketSnapshotSummary { asset: string; symbol: string; currentPrice: number; priceChange24h: number; priceChange7d: number; apyTrend: { supply: { current: number; avg7d: number; avg30d: number; }; borrow: { current: number; avg7d: number; avg30d: number; }; }; utilizationTrend: { current: number; avg7d: number; avg30d: number; }; liquidityTrend: { current: BigNumber; avg7d: BigNumber; min7d: BigNumber; max7d: BigNumber; }; volumeTrend: { total24h: BigNumber; avg7d: BigNumber; total7d: BigNumber; }; snapshots: MarketSnapshot[]; } interface SnapshotFilters { asset?: string; timeframe?: "1d" | "7d" | "30d" | "90d"; includeVolume?: boolean; includeUserMetrics?: boolean; } declare class MoonwellService extends Service { protected runtime: IAgentRuntime; static serviceType: string; capabilityDescription: string; private state; private moonwellConfig; private provider?; private signer?; private comptroller?; private oracle?; private multiRewardDistributor?; private markets; private moonwellClient?; constructor(runtime: IAgentRuntime); static start(runtime: IAgentRuntime): Promise<MoonwellService>; static stop(runtime: IAgentRuntime): Promise<void>; initialize(): Promise<void>; private ensureInitialized; private ensureWallet; supply(params: SupplyParams): Promise<SupplyResult>; borrow(params: BorrowParams): Promise<BorrowResult>; repay(params: RepayParams): Promise<RepayResult>; withdraw(params: WithdrawParams): Promise<WithdrawResult>; getUserPosition(): Promise<UserPosition>; getMarketData(asset?: string): Promise<MarketData[]>; getCachedPosition(): UserPosition | null; updatePositionCache(): Promise<void>; private startPositionMonitoring; getUserRewards(): Promise<{ rewards: Array<{ token: string; symbol: string; amount: BigNumber; valueInUSD: BigNumber; }>; totalValueInUSD: BigNumber; }>; claimAllRewards(): Promise<{ transactionHash: string; rewardsClaimed: Array<{ token: string; amount: BigNumber; }>; }>; getMorphoMarkets(): Promise<MorphoMarket$1[]>; getMorphoUserPosition(marketId: string): Promise<MorphoMarketUserPosition | null>; getMorphoUserBalances(): Promise<UserBalance[]>; getMorphoUserRewards(): Promise<MorphoUserRewards>; getMorphoVaults(): Promise<MorphoVault$1[]>; getMorphoVaultUserPosition(vaultId: string): Promise<MorphoVaultUserPosition$1 | null>; getMorphoVaultSnapshots(vaultId: string, timeframe?: "7d" | "30d" | "90d"): Promise<MorphoVaultSnapshot$1[]>; getMorphoVaultSummary(): Promise<{ totalVaults: number; totalTVL: BigNumber; totalTVLInUSD: BigNumber; averageAPY: number; vaults: MorphoVault$1[]; }>; getMorphoVaultPortfolio(): Promise<{ userAddress: string; positions: MorphoVaultUserPosition$1[]; lastUpdated: number; } | null>; private applyVaultFilters; getAllUserBalances(params?: UserBalanceParams): Promise<BalanceBreakdown>; getComprehensiveUserData(): Promise<{ userAddress: string; corePosition: UserPosition; coreRewards: UserRewards; morphoMarkets: MorphoMarket$1[]; morphoPositions: MorphoMarketUserPosition[]; morphoRewards: MorphoUserRewards; morphoVaultPortfolio: { userAddress: string; positions: MorphoVaultUserPosition$1[]; lastUpdated: number; } | null; balanceBreakdown: BalanceBreakdown; portfolioSummary: PortfolioSummary; lastUpdated: number; }>; private getWalletBalances; private convertCorePositionsToEnhanced; private getMorphoBalances; private getVaultBalances; private calculatePortfolioSummary; private getEmptyUserPosition; private getEmptyBalanceBreakdown; getMarketSnapshots(filters?: SnapshotFilters): Promise<MarketSnapshot[]>; getMarketSnapshotSummary(asset: string, timeframe?: "7d" | "30d" | "90d"): Promise<MarketSnapshotSummary>; stop(): Promise<void>; } declare class WalletService extends Service { protected runtime: IAgentRuntime; static serviceType: string; capabilityDescription: string; private provider?; private signer?; private address?; private chainId?; constructor(runtime: IAgentRuntime); static start(runtime: IAgentRuntime): Promise<WalletService>; static stop(runtime: IAgentRuntime): Promise<void>; initialize(): Promise<void>; connect(privateKey?: string): Promise<void>; getAddress(): Promise<string>; signTransaction(tx: Transaction): Promise<SignedTransaction>; getBalance(tokenAddress?: string): Promise<BigNumber>; approveToken(tokenAddress: string, spenderAddress: string, amount: BigNumber): Promise<string>; waitForTransaction(hash: string): Promise<TransactionReceipt>; getTokenInfo(tokenAddress: string): Promise<{ name: string; symbol: string; decimals: number; }>; estimateGas(tx: Transaction): Promise<BigNumber>; getGasPrice(): Promise<BigNumber>; stop(): Promise<void>; } declare const marketDataAction: Action; declare const positionAction: Action; declare const claimRewardsAction: Action; declare const morphoMarketsAction: Action; declare const morphoVaultsAction: Action; declare const supplyAction: Action; declare const borrowAction: Action; declare const repayAction: Action; declare const withdrawAction: Action; declare const positionContextProvider: Provider; declare const marketDataProvider: Provider; declare const moonwellPlugin: Plugin; export { type AssetPosition, type BalanceBreakdown, type BorrowParams, type BorrowResult, type ClaimRewardsResult, type ComprehensiveUserData, type EnhancedUserBalance, type MarketData, type MarketSnapshot, type MarketSnapshotSummary, type MoonwellConfig, type MoonwellError, MoonwellErrorCode, type MoonwellMarket, type MoonwellSDKConfig, MoonwellService, type MoonwellServiceState, type MorphoBorrowParams, type MorphoBorrowResult, type MorphoMarket, type MorphoMarketFilters, type MorphoMarketInfo, type MorphoPortfolio, type MorphoRepayParams, type MorphoRepayResult, type MorphoReward, type MorphoSupplyParams, type MorphoSupplyResult, type MorphoUserPosition, type MorphoUserRewards, type MorphoVault, type MorphoVaultDepositParams, type MorphoVaultDepositResult, type MorphoVaultFilters, type MorphoVaultPerformance, type MorphoVaultPortfolio, type MorphoVaultSnapshot, type MorphoVaultSummary, type MorphoVaultUserPosition, type MorphoVaultWithdrawParams, type MorphoVaultWithdrawResult, type MorphoWithdrawParams, type MorphoWithdrawResult, type PortfolioSummary, type RepayParams, type RepayResult, type SignedTransaction, type SnapshotFilters, type StrategyAllocation, type SupplyParams, type SupplyResult, type Transaction, type TransactionReceipt, type UserBalanceParams, type UserPosition, type UserReward, type UserRewards, WalletService, type WithdrawParams, type WithdrawResult, borrowAction, claimRewardsAction, moonwellPlugin as default, marketDataAction, marketDataProvider, moonwellPlugin, morphoMarketsAction, morphoVaultsAction, positionAction, positionContextProvider, repayAction, supplyAction, withdrawAction };