keyring-agent-core 0.2.1 → 0.2.3
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/dist/index.d.ts +6692 -27
- package/dist/index.js +877 -70
- package/package.json +6 -4
- package/dist/agent/AgentCore.d.ts +0 -256
- package/dist/agent/AgentCore.d.ts.map +0 -1
- package/dist/agent/AgentCore.js +0 -1093
- package/dist/agent/AgentCore.js.map +0 -1
- package/dist/agent/QueryRewriter.d.ts +0 -84
- package/dist/agent/QueryRewriter.d.ts.map +0 -1
- package/dist/agent/QueryRewriter.js +0 -306
- package/dist/agent/QueryRewriter.js.map +0 -1
- package/dist/agent/Router.d.ts +0 -33
- package/dist/agent/Router.d.ts.map +0 -1
- package/dist/agent/Router.js +0 -229
- package/dist/agent/Router.js.map +0 -1
- package/dist/agent/Subagent.d.ts +0 -80
- package/dist/agent/Subagent.d.ts.map +0 -1
- package/dist/agent/Subagent.js +0 -272
- package/dist/agent/Subagent.js.map +0 -1
- package/dist/agent/Synthesizer.d.ts +0 -11
- package/dist/agent/Synthesizer.d.ts.map +0 -1
- package/dist/agent/Synthesizer.js +0 -86
- package/dist/agent/Synthesizer.js.map +0 -1
- package/dist/agent/chatGraph.d.ts +0 -364
- package/dist/agent/chatGraph.d.ts.map +0 -1
- package/dist/agent/chatGraph.js +0 -184
- package/dist/agent/chatGraph.js.map +0 -1
- package/dist/agent/index.d.ts +0 -10
- package/dist/agent/index.d.ts.map +0 -1
- package/dist/agent/index.js +0 -24
- package/dist/agent/index.js.map +0 -1
- package/dist/agent/subagents/AiAgent.d.ts +0 -6
- package/dist/agent/subagents/AiAgent.d.ts.map +0 -1
- package/dist/agent/subagents/AiAgent.js +0 -52
- package/dist/agent/subagents/AiAgent.js.map +0 -1
- package/dist/agent/subagents/NftAgent.d.ts +0 -6
- package/dist/agent/subagents/NftAgent.d.ts.map +0 -1
- package/dist/agent/subagents/NftAgent.js +0 -79
- package/dist/agent/subagents/NftAgent.js.map +0 -1
- package/dist/agent/subagents/PoolAgent.d.ts +0 -6
- package/dist/agent/subagents/PoolAgent.d.ts.map +0 -1
- package/dist/agent/subagents/PoolAgent.js +0 -184
- package/dist/agent/subagents/PoolAgent.js.map +0 -1
- package/dist/agent/subagents/PoolSubgraphAgent.d.ts +0 -6
- package/dist/agent/subagents/PoolSubgraphAgent.d.ts.map +0 -1
- package/dist/agent/subagents/PoolSubgraphAgent.js +0 -117
- package/dist/agent/subagents/PoolSubgraphAgent.js.map +0 -1
- package/dist/agent/subagents/TokenAgent.d.ts +0 -6
- package/dist/agent/subagents/TokenAgent.d.ts.map +0 -1
- package/dist/agent/subagents/TokenAgent.js +0 -76
- package/dist/agent/subagents/TokenAgent.js.map +0 -1
- package/dist/agent/subagents/WalletActionAgent.d.ts +0 -6
- package/dist/agent/subagents/WalletActionAgent.d.ts.map +0 -1
- package/dist/agent/subagents/WalletActionAgent.js +0 -55
- package/dist/agent/subagents/WalletActionAgent.js.map +0 -1
- package/dist/agent/subagents/WalletAgent.d.ts +0 -6
- package/dist/agent/subagents/WalletAgent.d.ts.map +0 -1
- package/dist/agent/subagents/WalletAgent.js +0 -93
- package/dist/agent/subagents/WalletAgent.js.map +0 -1
- package/dist/agent/subagents/index.d.ts +0 -34
- package/dist/agent/subagents/index.d.ts.map +0 -1
- package/dist/agent/subagents/index.js +0 -69
- package/dist/agent/subagents/index.js.map +0 -1
- package/dist/constants/abi.d.ts +0 -551
- package/dist/constants/abi.d.ts.map +0 -1
- package/dist/constants/abi.js +0 -690
- package/dist/constants/abi.js.map +0 -1
- package/dist/functions/pool.d.ts +0 -25
- package/dist/functions/pool.d.ts.map +0 -1
- package/dist/functions/pool.js +0 -151
- package/dist/functions/pool.js.map +0 -1
- package/dist/functions/web3.d.ts +0 -31
- package/dist/functions/web3.d.ts.map +0 -1
- package/dist/functions/web3.js +0 -232
- package/dist/functions/web3.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/llm/GeminiProvider.d.ts +0 -16
- package/dist/llm/GeminiProvider.d.ts.map +0 -1
- package/dist/llm/GeminiProvider.js +0 -329
- package/dist/llm/GeminiProvider.js.map +0 -1
- package/dist/llm/index.d.ts +0 -2
- package/dist/llm/index.d.ts.map +0 -1
- package/dist/llm/index.js +0 -6
- package/dist/llm/index.js.map +0 -1
- package/dist/memory/ChatHistory.d.ts +0 -83
- package/dist/memory/ChatHistory.d.ts.map +0 -1
- package/dist/memory/ChatHistory.js +0 -143
- package/dist/memory/ChatHistory.js.map +0 -1
- package/dist/memory/KnowledgeBase.d.ts +0 -38
- package/dist/memory/KnowledgeBase.d.ts.map +0 -1
- package/dist/memory/KnowledgeBase.js +0 -139
- package/dist/memory/KnowledgeBase.js.map +0 -1
- package/dist/memory/Summarizer.d.ts +0 -12
- package/dist/memory/Summarizer.d.ts.map +0 -1
- package/dist/memory/Summarizer.js +0 -39
- package/dist/memory/Summarizer.js.map +0 -1
- package/dist/memory/UpstashKnowledgeBase.d.ts +0 -124
- package/dist/memory/UpstashKnowledgeBase.d.ts.map +0 -1
- package/dist/memory/UpstashKnowledgeBase.js +0 -152
- package/dist/memory/UpstashKnowledgeBase.js.map +0 -1
- package/dist/memory/historyUtils.d.ts +0 -58
- package/dist/memory/historyUtils.d.ts.map +0 -1
- package/dist/memory/historyUtils.js +0 -190
- package/dist/memory/historyUtils.js.map +0 -1
- package/dist/memory/index.d.ts +0 -7
- package/dist/memory/index.d.ts.map +0 -1
- package/dist/memory/index.js +0 -12
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/ingestKnowledgeBase.d.ts +0 -17
- package/dist/memory/ingestKnowledgeBase.d.ts.map +0 -1
- package/dist/memory/ingestKnowledgeBase.js +0 -35
- package/dist/memory/ingestKnowledgeBase.js.map +0 -1
- package/dist/services/MoralisService.d.ts +0 -1328
- package/dist/services/MoralisService.d.ts.map +0 -1
- package/dist/services/MoralisService.js +0 -1239
- package/dist/services/MoralisService.js.map +0 -1
- package/dist/services/PantographService.d.ts +0 -98
- package/dist/services/PantographService.d.ts.map +0 -1
- package/dist/services/PantographService.js +0 -451
- package/dist/services/PantographService.js.map +0 -1
- package/dist/services/PoolService.d.ts +0 -238
- package/dist/services/PoolService.d.ts.map +0 -1
- package/dist/services/PoolService.js +0 -485
- package/dist/services/PoolService.js.map +0 -1
- package/dist/services/UniswapService.d.ts +0 -289
- package/dist/services/UniswapService.d.ts.map +0 -1
- package/dist/services/UniswapService.js +0 -585
- package/dist/services/UniswapService.js.map +0 -1
- package/dist/services/UniswapSubgraphService.d.ts +0 -144
- package/dist/services/UniswapSubgraphService.d.ts.map +0 -1
- package/dist/services/UniswapSubgraphService.js +0 -606
- package/dist/services/UniswapSubgraphService.js.map +0 -1
- package/dist/services/rpc.d.ts +0 -35
- package/dist/services/rpc.d.ts.map +0 -1
- package/dist/services/rpc.js +0 -110
- package/dist/services/rpc.js.map +0 -1
- package/dist/services/swap/BaseSwapService.d.ts +0 -17
- package/dist/services/swap/BaseSwapService.d.ts.map +0 -1
- package/dist/services/swap/BaseSwapService.js +0 -19
- package/dist/services/swap/BaseSwapService.js.map +0 -1
- package/dist/services/swap/DebridgeAdapter.d.ts +0 -37
- package/dist/services/swap/DebridgeAdapter.d.ts.map +0 -1
- package/dist/services/swap/DebridgeAdapter.js +0 -243
- package/dist/services/swap/DebridgeAdapter.js.map +0 -1
- package/dist/services/swap/RelayAdapter.d.ts +0 -19
- package/dist/services/swap/RelayAdapter.d.ts.map +0 -1
- package/dist/services/swap/RelayAdapter.js +0 -189
- package/dist/services/swap/RelayAdapter.js.map +0 -1
- package/dist/services/swap/SwapServiceFactory.d.ts +0 -25
- package/dist/services/swap/SwapServiceFactory.d.ts.map +0 -1
- package/dist/services/swap/SwapServiceFactory.js +0 -79
- package/dist/services/swap/SwapServiceFactory.js.map +0 -1
- package/dist/services/swap/addresses.d.ts +0 -3
- package/dist/services/swap/addresses.d.ts.map +0 -1
- package/dist/services/swap/addresses.js +0 -68
- package/dist/services/swap/addresses.js.map +0 -1
- package/dist/services/swap/affiliate.d.ts +0 -17
- package/dist/services/swap/affiliate.d.ts.map +0 -1
- package/dist/services/swap/affiliate.js +0 -126
- package/dist/services/swap/affiliate.js.map +0 -1
- package/dist/services/swap/config.d.ts +0 -9
- package/dist/services/swap/config.d.ts.map +0 -1
- package/dist/services/swap/config.js +0 -19
- package/dist/services/swap/config.js.map +0 -1
- package/dist/services/swap/index.d.ts +0 -10
- package/dist/services/swap/index.d.ts.map +0 -1
- package/dist/services/swap/index.js +0 -22
- package/dist/services/swap/index.js.map +0 -1
- package/dist/services/swap/types.d.ts +0 -89
- package/dist/services/swap/types.d.ts.map +0 -1
- package/dist/services/swap/types.js +0 -6
- package/dist/services/swap/types.js.map +0 -1
- package/dist/tools/BaseTool.d.ts +0 -15
- package/dist/tools/BaseTool.d.ts.map +0 -1
- package/dist/tools/BaseTool.js +0 -35
- package/dist/tools/BaseTool.js.map +0 -1
- package/dist/tools/ToolRegistry.d.ts +0 -27
- package/dist/tools/ToolRegistry.d.ts.map +0 -1
- package/dist/tools/ToolRegistry.js +0 -80
- package/dist/tools/ToolRegistry.js.map +0 -1
- package/dist/tools/builtin/ai/GeminiSearchAiTool.d.ts +0 -36
- package/dist/tools/builtin/ai/GeminiSearchAiTool.d.ts.map +0 -1
- package/dist/tools/builtin/ai/GeminiSearchAiTool.js +0 -91
- package/dist/tools/builtin/ai/GeminiSearchAiTool.js.map +0 -1
- package/dist/tools/builtin/ai/index.d.ts +0 -3
- package/dist/tools/builtin/ai/index.d.ts.map +0 -1
- package/dist/tools/builtin/ai/index.js +0 -6
- package/dist/tools/builtin/ai/index.js.map +0 -1
- package/dist/tools/builtin/index.d.ts +0 -8
- package/dist/tools/builtin/index.d.ts.map +0 -1
- package/dist/tools/builtin/index.js +0 -24
- package/dist/tools/builtin/index.js.map +0 -1
- package/dist/tools/builtin/nft/BaseNftMessageTool.d.ts +0 -35
- package/dist/tools/builtin/nft/BaseNftMessageTool.d.ts.map +0 -1
- package/dist/tools/builtin/nft/BaseNftMessageTool.js +0 -45
- package/dist/tools/builtin/nft/BaseNftMessageTool.js.map +0 -1
- package/dist/tools/builtin/nft/NFTContractInfoTool.d.ts +0 -15
- package/dist/tools/builtin/nft/NFTContractInfoTool.d.ts.map +0 -1
- package/dist/tools/builtin/nft/NFTContractInfoTool.js +0 -19
- package/dist/tools/builtin/nft/NFTContractInfoTool.js.map +0 -1
- package/dist/tools/builtin/nft/NFTMetadataTool.d.ts +0 -15
- package/dist/tools/builtin/nft/NFTMetadataTool.d.ts.map +0 -1
- package/dist/tools/builtin/nft/NFTMetadataTool.js +0 -20
- package/dist/tools/builtin/nft/NFTMetadataTool.js.map +0 -1
- package/dist/tools/builtin/nft/SendNftTool.d.ts +0 -14
- package/dist/tools/builtin/nft/SendNftTool.d.ts.map +0 -1
- package/dist/tools/builtin/nft/SendNftTool.js +0 -20
- package/dist/tools/builtin/nft/SendNftTool.js.map +0 -1
- package/dist/tools/builtin/nft/WalletNFTsTool.d.ts +0 -15
- package/dist/tools/builtin/nft/WalletNFTsTool.d.ts.map +0 -1
- package/dist/tools/builtin/nft/WalletNFTsTool.js +0 -20
- package/dist/tools/builtin/nft/WalletNFTsTool.js.map +0 -1
- package/dist/tools/builtin/nft/index.d.ts +0 -7
- package/dist/tools/builtin/nft/index.d.ts.map +0 -1
- package/dist/tools/builtin/nft/index.js +0 -10
- package/dist/tools/builtin/nft/index.js.map +0 -1
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.d.ts +0 -124
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.js +0 -236
- package/dist/tools/builtin/pool/EstimatePoolYieldTool.js.map +0 -1
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.d.ts +0 -128
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.js +0 -520
- package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.js.map +0 -1
- package/dist/tools/builtin/pool/PoolByAddressTool.d.ts +0 -127
- package/dist/tools/builtin/pool/PoolByAddressTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool/PoolByAddressTool.js +0 -238
- package/dist/tools/builtin/pool/PoolByAddressTool.js.map +0 -1
- package/dist/tools/builtin/pool/PoolDetailTool.d.ts +0 -127
- package/dist/tools/builtin/pool/PoolDetailTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool/PoolDetailTool.js +0 -273
- package/dist/tools/builtin/pool/PoolDetailTool.js.map +0 -1
- package/dist/tools/builtin/pool/PoolSearchTool.d.ts +0 -50
- package/dist/tools/builtin/pool/PoolSearchTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool/PoolSearchTool.js +0 -160
- package/dist/tools/builtin/pool/PoolSearchTool.js.map +0 -1
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.d.ts +0 -124
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.js +0 -382
- package/dist/tools/builtin/pool/PreviewAddLiquidityTool.js.map +0 -1
- package/dist/tools/builtin/pool/TopPoolsTool.d.ts +0 -68
- package/dist/tools/builtin/pool/TopPoolsTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool/TopPoolsTool.js +0 -159
- package/dist/tools/builtin/pool/TopPoolsTool.js.map +0 -1
- package/dist/tools/builtin/pool/index.d.ts +0 -15
- package/dist/tools/builtin/pool/index.d.ts.map +0 -1
- package/dist/tools/builtin/pool/index.js +0 -18
- package/dist/tools/builtin/pool/index.js.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.d.ts +0 -54
- package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.js +0 -98
- package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.js.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.d.ts +0 -63
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.js +0 -82
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.js.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.d.ts +0 -79
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.js +0 -97
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.js.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.d.ts +0 -77
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.js +0 -190
- package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.js.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.d.ts +0 -107
- package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.js +0 -92
- package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.js.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.d.ts +0 -56
- package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.d.ts.map +0 -1
- package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.js +0 -94
- package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.js.map +0 -1
- package/dist/tools/builtin/pool-subgraph/index.d.ts +0 -13
- package/dist/tools/builtin/pool-subgraph/index.d.ts.map +0 -1
- package/dist/tools/builtin/pool-subgraph/index.js +0 -18
- package/dist/tools/builtin/pool-subgraph/index.js.map +0 -1
- package/dist/tools/builtin/token/TokenAnalyticsTool.d.ts +0 -71
- package/dist/tools/builtin/token/TokenAnalyticsTool.d.ts.map +0 -1
- package/dist/tools/builtin/token/TokenAnalyticsTool.js +0 -147
- package/dist/tools/builtin/token/TokenAnalyticsTool.js.map +0 -1
- package/dist/tools/builtin/token/TokenHoldersTool.d.ts +0 -81
- package/dist/tools/builtin/token/TokenHoldersTool.d.ts.map +0 -1
- package/dist/tools/builtin/token/TokenHoldersTool.js +0 -139
- package/dist/tools/builtin/token/TokenHoldersTool.js.map +0 -1
- package/dist/tools/builtin/token/TokenInfoTool.d.ts +0 -40
- package/dist/tools/builtin/token/TokenInfoTool.d.ts.map +0 -1
- package/dist/tools/builtin/token/TokenInfoTool.js +0 -221
- package/dist/tools/builtin/token/TokenInfoTool.js.map +0 -1
- package/dist/tools/builtin/token/TokenScoreTool.d.ts +0 -63
- package/dist/tools/builtin/token/TokenScoreTool.d.ts.map +0 -1
- package/dist/tools/builtin/token/TokenScoreTool.js +0 -148
- package/dist/tools/builtin/token/TokenScoreTool.js.map +0 -1
- package/dist/tools/builtin/token/TopGainersTool.d.ts +0 -37
- package/dist/tools/builtin/token/TopGainersTool.d.ts.map +0 -1
- package/dist/tools/builtin/token/TopGainersTool.js +0 -100
- package/dist/tools/builtin/token/TopGainersTool.js.map +0 -1
- package/dist/tools/builtin/token/TopLosersTool.d.ts +0 -66
- package/dist/tools/builtin/token/TopLosersTool.d.ts.map +0 -1
- package/dist/tools/builtin/token/TopLosersTool.js +0 -129
- package/dist/tools/builtin/token/TopLosersTool.js.map +0 -1
- package/dist/tools/builtin/token/TrendingTokensTool.d.ts +0 -39
- package/dist/tools/builtin/token/TrendingTokensTool.d.ts.map +0 -1
- package/dist/tools/builtin/token/TrendingTokensTool.js +0 -83
- package/dist/tools/builtin/token/TrendingTokensTool.js.map +0 -1
- package/dist/tools/builtin/token/index.d.ts +0 -13
- package/dist/tools/builtin/token/index.d.ts.map +0 -1
- package/dist/tools/builtin/token/index.js +0 -16
- package/dist/tools/builtin/token/index.js.map +0 -1
- package/dist/tools/builtin/wallet/TransactionByHashTool.d.ts +0 -70
- package/dist/tools/builtin/wallet/TransactionByHashTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/TransactionByHashTool.js +0 -111
- package/dist/tools/builtin/wallet/TransactionByHashTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletApprovalsTool.d.ts +0 -107
- package/dist/tools/builtin/wallet/WalletApprovalsTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletApprovalsTool.js +0 -164
- package/dist/tools/builtin/wallet/WalletApprovalsTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.d.ts +0 -61
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.js +0 -100
- package/dist/tools/builtin/wallet/WalletDefiPositionsTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.d.ts +0 -68
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.js +0 -115
- package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.d.ts +0 -50
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.js +0 -80
- package/dist/tools/builtin/wallet/WalletDefiSummaryTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletHistoryTool.d.ts +0 -31
- package/dist/tools/builtin/wallet/WalletHistoryTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletHistoryTool.js +0 -154
- package/dist/tools/builtin/wallet/WalletHistoryTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletNetWorthTool.d.ts +0 -44
- package/dist/tools/builtin/wallet/WalletNetWorthTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletNetWorthTool.js +0 -122
- package/dist/tools/builtin/wallet/WalletNetWorthTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.d.ts +0 -86
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.js +0 -265
- package/dist/tools/builtin/wallet/WalletNftTransfersTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.d.ts +0 -43
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.js +0 -89
- package/dist/tools/builtin/wallet/WalletPnlSummaryTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletPnlTool.d.ts +0 -43
- package/dist/tools/builtin/wallet/WalletPnlTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletPnlTool.js +0 -175
- package/dist/tools/builtin/wallet/WalletPnlTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.d.ts +0 -35
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.js +0 -68
- package/dist/tools/builtin/wallet/WalletTokenBalancesTool.js.map +0 -1
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.d.ts +0 -109
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.js +0 -354
- package/dist/tools/builtin/wallet/WalletTokenTransfersTool.js.map +0 -1
- package/dist/tools/builtin/wallet/index.d.ts +0 -28
- package/dist/tools/builtin/wallet/index.d.ts.map +0 -1
- package/dist/tools/builtin/wallet/index.js +0 -32
- package/dist/tools/builtin/wallet/index.js.map +0 -1
- package/dist/tools/builtin/wallet-action/ApproveTokenTool.d.ts +0 -25
- package/dist/tools/builtin/wallet-action/ApproveTokenTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/ApproveTokenTool.js +0 -98
- package/dist/tools/builtin/wallet-action/ApproveTokenTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/BaseWalletActionTool.d.ts +0 -211
- package/dist/tools/builtin/wallet-action/BaseWalletActionTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/BaseWalletActionTool.js +0 -499
- package/dist/tools/builtin/wallet-action/BaseWalletActionTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/BuyTokenTool.d.ts +0 -240
- package/dist/tools/builtin/wallet-action/BuyTokenTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/BuyTokenTool.js +0 -1257
- package/dist/tools/builtin/wallet-action/BuyTokenTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/SendNativeTool.d.ts +0 -41
- package/dist/tools/builtin/wallet-action/SendNativeTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/SendNativeTool.js +0 -127
- package/dist/tools/builtin/wallet-action/SendNativeTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/SendTokenTool.d.ts +0 -63
- package/dist/tools/builtin/wallet-action/SendTokenTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/SendTokenTool.js +0 -294
- package/dist/tools/builtin/wallet-action/SendTokenTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/SwapTokenTool.d.ts +0 -247
- package/dist/tools/builtin/wallet-action/SwapTokenTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/SwapTokenTool.js +0 -1258
- package/dist/tools/builtin/wallet-action/SwapTokenTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/UnwrapNativeTool.d.ts +0 -20
- package/dist/tools/builtin/wallet-action/UnwrapNativeTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/UnwrapNativeTool.js +0 -36
- package/dist/tools/builtin/wallet-action/UnwrapNativeTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/WrapNativeTool.d.ts +0 -23
- package/dist/tools/builtin/wallet-action/WrapNativeTool.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/WrapNativeTool.js +0 -54
- package/dist/tools/builtin/wallet-action/WrapNativeTool.js.map +0 -1
- package/dist/tools/builtin/wallet-action/amountSpec.d.ts +0 -62
- package/dist/tools/builtin/wallet-action/amountSpec.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/amountSpec.js +0 -93
- package/dist/tools/builtin/wallet-action/amountSpec.js.map +0 -1
- package/dist/tools/builtin/wallet-action/gasReserve.d.ts +0 -42
- package/dist/tools/builtin/wallet-action/gasReserve.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/gasReserve.js +0 -103
- package/dist/tools/builtin/wallet-action/gasReserve.js.map +0 -1
- package/dist/tools/builtin/wallet-action/index.d.ts +0 -9
- package/dist/tools/builtin/wallet-action/index.d.ts.map +0 -1
- package/dist/tools/builtin/wallet-action/index.js +0 -20
- package/dist/tools/builtin/wallet-action/index.js.map +0 -1
- package/dist/tools/chainResolver.d.ts +0 -98
- package/dist/tools/chainResolver.d.ts.map +0 -1
- package/dist/tools/chainResolver.js +0 -302
- package/dist/tools/chainResolver.js.map +0 -1
- package/dist/tools/index.d.ts +0 -4
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -23
- package/dist/tools/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -777
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
|
@@ -1,1239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* MoralisService — Moralis Web3 API + Cortex AI proxy.
|
|
4
|
-
*
|
|
5
|
-
* Adapted from keyring-chatbot-agent-sdk moralis service.
|
|
6
|
-
* Uses native fetch — no SDK dependencies.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.MoralisService = void 0;
|
|
10
|
-
const web3_1 = require("../functions/web3");
|
|
11
|
-
const PantographService_1 = require("./PantographService");
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
// Constants
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
const DEFAULT_BASE_URL = 'https://nft.keyring.app';
|
|
16
|
-
const DEFAULT_V1_BASE_URL = 'https://nft-demo.keyring.app';
|
|
17
|
-
const MINIMUM_TOKEN_BALANCE_PRICE_USD = 0.01;
|
|
18
|
-
const MAX_RETRIES = 5;
|
|
19
|
-
const RETRY_DELAY_MS = 1000;
|
|
20
|
-
/** Moralis uses 0xEeee…EE for native ETH; we normalise to 0x000…000 */
|
|
21
|
-
const ETH_SENTINEL = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
22
|
-
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
// Helpers
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
/** AI always provides hex chain IDs; default to Base (0x2105). */
|
|
27
|
-
function toMoralisChain(chain) {
|
|
28
|
-
return chain || '0x2105';
|
|
29
|
-
}
|
|
30
|
-
function buildQueryString(params) {
|
|
31
|
-
const parts = [];
|
|
32
|
-
for (const [key, value] of Object.entries(params)) {
|
|
33
|
-
if (value == null)
|
|
34
|
-
continue;
|
|
35
|
-
if (Array.isArray(value)) {
|
|
36
|
-
for (const v of value) {
|
|
37
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return parts.join('&');
|
|
45
|
-
}
|
|
46
|
-
function delay(ms) {
|
|
47
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Coerce the `/wallets/{address}/defi/positions` payload into an array.
|
|
51
|
-
*
|
|
52
|
-
* The proxy sometimes serialises the Moralis response as a plain object with
|
|
53
|
-
* stringified numeric keys (`{"0": {...}, "1": {...}}`) instead of a real
|
|
54
|
-
* JSON array. We accept both shapes and drop anything that doesn't look like
|
|
55
|
-
* a position row.
|
|
56
|
-
*/
|
|
57
|
-
function normalizeDefiPositionsPayload(payload) {
|
|
58
|
-
if (Array.isArray(payload))
|
|
59
|
-
return payload;
|
|
60
|
-
if (payload && typeof payload === 'object') {
|
|
61
|
-
const obj = payload;
|
|
62
|
-
// v1 response shape: { meta, result: [...] }
|
|
63
|
-
if (Array.isArray(obj['result'])) {
|
|
64
|
-
return obj['result'].map((item) => ({
|
|
65
|
-
protocol_id: item.protocolId,
|
|
66
|
-
protocol_name: item.protocolName,
|
|
67
|
-
protocol_url: item.protocolUrl ?? '',
|
|
68
|
-
protocol_logo: item.protocolLogo ?? '',
|
|
69
|
-
position: {
|
|
70
|
-
label: item.position.label,
|
|
71
|
-
address: item.position.address,
|
|
72
|
-
balance_usd: item.position.balanceUsd ?? 0,
|
|
73
|
-
total_unclaimed_usd_value: item.position.unclaimedUsd ?? 0,
|
|
74
|
-
position_details: item.position.details,
|
|
75
|
-
tokens: item.position.tokens.map((t) => ({
|
|
76
|
-
token_type: t.tokenType,
|
|
77
|
-
address: t.address,
|
|
78
|
-
contract_address: t.address,
|
|
79
|
-
name: t.name ?? '',
|
|
80
|
-
symbol: t.symbol ?? '',
|
|
81
|
-
decimals: t.decimals ?? 18,
|
|
82
|
-
logo: t.logo,
|
|
83
|
-
balance: t.balance ?? '0',
|
|
84
|
-
balance_formatted: t.balanceFormatted ?? '0',
|
|
85
|
-
usd_price: t.usdPrice,
|
|
86
|
-
usd_value: t.usdValue,
|
|
87
|
-
})),
|
|
88
|
-
},
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
// Proxy response shape: { "0": {...}, "1": {...} }
|
|
92
|
-
return Object.keys(obj)
|
|
93
|
-
.filter((k) => /^\d+$/.test(k))
|
|
94
|
-
.sort((a, b) => Number(a) - Number(b))
|
|
95
|
-
.map((k) => obj[k])
|
|
96
|
-
.filter((row) => !!row && typeof row === 'object');
|
|
97
|
-
}
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Coerce a Moralis array response into a real array.
|
|
102
|
-
*
|
|
103
|
-
* Upstream returns a JSON array, but our proxy occasionally serialises it as
|
|
104
|
-
* `{ "0": {...}, "1": {...} }` (stringified numeric keys), or wraps it as
|
|
105
|
-
* `{ result: [...] }`. Accept all three shapes and drop anything that isn't a
|
|
106
|
-
* plain object row.
|
|
107
|
-
*/
|
|
108
|
-
function normalizeArrayLikePayload(payload) {
|
|
109
|
-
if (Array.isArray(payload))
|
|
110
|
-
return payload;
|
|
111
|
-
if (payload && typeof payload === 'object') {
|
|
112
|
-
const obj = payload;
|
|
113
|
-
if (Array.isArray(obj.result))
|
|
114
|
-
return obj.result;
|
|
115
|
-
return Object.keys(obj)
|
|
116
|
-
.filter((k) => /^\d+$/.test(k))
|
|
117
|
-
.sort((a, b) => Number(a) - Number(b))
|
|
118
|
-
.map((k) => obj[k])
|
|
119
|
-
.filter((row) => !!row && typeof row === 'object');
|
|
120
|
-
}
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
// ---------------------------------------------------------------------------
|
|
124
|
-
// Service class
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
class MoralisService {
|
|
127
|
-
baseUrl;
|
|
128
|
-
v1BaseUrl;
|
|
129
|
-
pantograph;
|
|
130
|
-
constructor(config) {
|
|
131
|
-
this.baseUrl = (config?.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
132
|
-
this.v1BaseUrl = (config?.v1BaseUrl ?? DEFAULT_V1_BASE_URL).replace(/\/+$/, '');
|
|
133
|
-
this.pantograph = new PantographService_1.PantographService({ baseUrl: config?.pantographUrl });
|
|
134
|
-
}
|
|
135
|
-
// =========================================================================
|
|
136
|
-
// Token Balances
|
|
137
|
-
// =========================================================================
|
|
138
|
-
/**
|
|
139
|
-
* Get token balances for a wallet.
|
|
140
|
-
* Automatically enriches prices via Pantograph and filters dust.
|
|
141
|
-
*/
|
|
142
|
-
async getWalletTokenBalances(params) {
|
|
143
|
-
const { address, chain, tokenAddresses, excludeSpam = false, excludeUnverifiedContracts = false } = params;
|
|
144
|
-
if (!address)
|
|
145
|
-
return { success: false, error: 'Address is required' };
|
|
146
|
-
const moralisChain = toMoralisChain(chain);
|
|
147
|
-
let lastError = 'Unknown error';
|
|
148
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
149
|
-
try {
|
|
150
|
-
const query = {
|
|
151
|
-
chain: moralisChain,
|
|
152
|
-
exclude_spam: excludeSpam,
|
|
153
|
-
exclude_unverified_contracts: excludeUnverifiedContracts,
|
|
154
|
-
limit: 100,
|
|
155
|
-
};
|
|
156
|
-
if (tokenAddresses)
|
|
157
|
-
query.token_addresses = tokenAddresses;
|
|
158
|
-
const allResults = [];
|
|
159
|
-
let cursor = null;
|
|
160
|
-
do {
|
|
161
|
-
if (cursor)
|
|
162
|
-
query.cursor = cursor;
|
|
163
|
-
const qs = buildQueryString(query);
|
|
164
|
-
const url = `${this.baseUrl}/api/moralis/proxy/wallets/${encodeURIComponent(address)}/tokens?${qs}`;
|
|
165
|
-
const res = await fetch(url);
|
|
166
|
-
if (!res.ok)
|
|
167
|
-
throw new Error(`HTTP ${res.status}`);
|
|
168
|
-
const json = (await res.json());
|
|
169
|
-
const page = (json?.data ?? json);
|
|
170
|
-
if (page?.result?.length > 0)
|
|
171
|
-
allResults.push(...page.result);
|
|
172
|
-
cursor = page?.cursor ?? null;
|
|
173
|
-
} while (cursor);
|
|
174
|
-
const data = { result: allResults };
|
|
175
|
-
if (data?.result?.length > 0) {
|
|
176
|
-
// Filter by positive balance
|
|
177
|
-
data.result = data.result.filter((t) => parseFloat(t.balance || '0') > 0);
|
|
178
|
-
// Normalise ETH sentinel → zero address
|
|
179
|
-
data.result = data.result.map((t) => ({
|
|
180
|
-
...t,
|
|
181
|
-
token_address: t.token_address.toLowerCase() === ETH_SENTINEL ? ZERO_ADDRESS : t.token_address,
|
|
182
|
-
}));
|
|
183
|
-
// Enrich prices from Pantograph
|
|
184
|
-
await this.enrichTokenPrices(data.result, moralisChain);
|
|
185
|
-
// Drop tokens whose value is known AND below minimum
|
|
186
|
-
data.result = data.result.filter((t) => t.usd_value == null || t.usd_value >= MINIMUM_TOKEN_BALANCE_PRICE_USD);
|
|
187
|
-
}
|
|
188
|
-
return { success: true, data };
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
192
|
-
if (attempt < MAX_RETRIES)
|
|
193
|
-
await delay(RETRY_DELAY_MS);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return { success: false, error: lastError };
|
|
197
|
-
}
|
|
198
|
-
// =========================================================================
|
|
199
|
-
// Token Metadata
|
|
200
|
-
// =========================================================================
|
|
201
|
-
/**
|
|
202
|
-
* Get metadata + price for a single token by contract address.
|
|
203
|
-
*/
|
|
204
|
-
async getTokenMetadata(params) {
|
|
205
|
-
const { address, chain } = params;
|
|
206
|
-
if (!address)
|
|
207
|
-
return { success: false, error: 'Token address is required' };
|
|
208
|
-
const moralisChain = toMoralisChain(chain);
|
|
209
|
-
let lastError = 'Unknown error';
|
|
210
|
-
// Try Pantograph first (single source for metadata + price)
|
|
211
|
-
const pantographMeta = await this.pantograph.getTokenMetadata(address, moralisChain);
|
|
212
|
-
if (pantographMeta)
|
|
213
|
-
return { success: true, data: pantographMeta };
|
|
214
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
215
|
-
try {
|
|
216
|
-
// Fallback to Moralis proxy
|
|
217
|
-
const [metaRes, priceRes] = await Promise.allSettled([
|
|
218
|
-
fetch(`${this.baseUrl}/api/moralis/proxy/erc20/metadata?${buildQueryString({ chain: moralisChain, addresses: [address] })}`),
|
|
219
|
-
fetch(`${this.baseUrl}/api/moralis/proxy/erc20/${encodeURIComponent(address)}/price?${buildQueryString({ chain: moralisChain, include: 'percent_change' })}`),
|
|
220
|
-
]);
|
|
221
|
-
let meta = null;
|
|
222
|
-
if (metaRes.status === 'fulfilled' && metaRes.value.ok) {
|
|
223
|
-
const metaJson = (await metaRes.value.json());
|
|
224
|
-
const metaList = Array.isArray(metaJson) ? metaJson : Array.isArray(metaJson?.data) ? metaJson.data : [];
|
|
225
|
-
meta = metaList[0] ?? null;
|
|
226
|
-
}
|
|
227
|
-
if (!meta) {
|
|
228
|
-
lastError = 'Token metadata not found';
|
|
229
|
-
if (attempt < MAX_RETRIES)
|
|
230
|
-
await delay(RETRY_DELAY_MS);
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
let priceData = null;
|
|
234
|
-
if (priceRes.status === 'fulfilled' && priceRes.value.ok) {
|
|
235
|
-
const priceJson = (await priceRes.value.json());
|
|
236
|
-
priceData = priceJson?.data ?? priceJson;
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
success: true,
|
|
240
|
-
data: {
|
|
241
|
-
...meta,
|
|
242
|
-
...(priceData?.usd_price ? { usd_price: priceData.usd_price } : {}),
|
|
243
|
-
...(priceData?.usd_price_change_percentage_24h
|
|
244
|
-
? { usd_price_change_percentage_24h: priceData.usd_price_change_percentage_24h }
|
|
245
|
-
: {}),
|
|
246
|
-
},
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
251
|
-
if (attempt < MAX_RETRIES)
|
|
252
|
-
await delay(RETRY_DELAY_MS);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return { success: false, error: lastError };
|
|
256
|
-
}
|
|
257
|
-
// =========================================================================
|
|
258
|
-
// Wallet NFTs
|
|
259
|
-
// =========================================================================
|
|
260
|
-
/**
|
|
261
|
-
* Get NFTs owned by a wallet.
|
|
262
|
-
*/
|
|
263
|
-
async getWalletNFTs(params) {
|
|
264
|
-
const { address, chain, limit = 10, excludeSpam = true, cursor, tokenAddresses, includePrices, format = 'decimal', } = params;
|
|
265
|
-
if (!address)
|
|
266
|
-
return { success: false, error: 'Address is required' };
|
|
267
|
-
const moralisChain = toMoralisChain(chain);
|
|
268
|
-
let lastError = 'Unknown error';
|
|
269
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
270
|
-
try {
|
|
271
|
-
const query = {
|
|
272
|
-
chain: moralisChain,
|
|
273
|
-
format,
|
|
274
|
-
limit,
|
|
275
|
-
exclude_spam: excludeSpam,
|
|
276
|
-
media_items: true,
|
|
277
|
-
normalizeMetadata: true,
|
|
278
|
-
};
|
|
279
|
-
if (cursor)
|
|
280
|
-
query.cursor = cursor;
|
|
281
|
-
if (includePrices)
|
|
282
|
-
query.include_prices = true;
|
|
283
|
-
if (tokenAddresses && tokenAddresses.length > 0) {
|
|
284
|
-
query['token_addresses'] = tokenAddresses;
|
|
285
|
-
}
|
|
286
|
-
const qs = buildQueryString(query);
|
|
287
|
-
const url = `${this.baseUrl}/api/moralis/proxy/${encodeURIComponent(address)}/nft?${qs}`;
|
|
288
|
-
const res = await fetch(url);
|
|
289
|
-
if (!res.ok)
|
|
290
|
-
throw new Error(`HTTP ${res.status}`);
|
|
291
|
-
const json = (await res.json());
|
|
292
|
-
const data = (json?.data ?? json);
|
|
293
|
-
return { success: true, data };
|
|
294
|
-
}
|
|
295
|
-
catch (error) {
|
|
296
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
297
|
-
if (attempt < MAX_RETRIES)
|
|
298
|
-
await delay(RETRY_DELAY_MS);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return { success: false, error: lastError };
|
|
302
|
-
}
|
|
303
|
-
// =========================================================================
|
|
304
|
-
// NFT Metadata (by contract + tokenId)
|
|
305
|
-
// =========================================================================
|
|
306
|
-
/**
|
|
307
|
-
* Get the full metadata for a single NFT identified by its contract address
|
|
308
|
-
* and token id via the Moralis `GET /nft/{address}/{token_id}` endpoint.
|
|
309
|
-
*
|
|
310
|
-
* Returns normalized metadata (name, description, image, attributes),
|
|
311
|
-
* media variants, floor-price, rarity, collection socials and sync
|
|
312
|
-
* timestamps. Only supported on EVM chains.
|
|
313
|
-
*
|
|
314
|
-
* Moralis docs: https://docs.moralis.com/data-api/evm/nft/metadata/nft-metadata
|
|
315
|
-
*/
|
|
316
|
-
async getNftMetadata(params) {
|
|
317
|
-
const { address, tokenId, chain, format = 'decimal', normalizeMetadata = true, mediaItems = true, include, } = params;
|
|
318
|
-
if (!address)
|
|
319
|
-
return { success: false, error: 'NFT contract address is required' };
|
|
320
|
-
if (tokenId == null || tokenId === '')
|
|
321
|
-
return { success: false, error: 'Token ID is required' };
|
|
322
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
323
|
-
return { success: false, error: 'NFT metadata lookup by token ID is only supported on EVM chains' };
|
|
324
|
-
}
|
|
325
|
-
const moralisChain = toMoralisChain(chain);
|
|
326
|
-
let lastError = 'Unknown error';
|
|
327
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
328
|
-
try {
|
|
329
|
-
const query = {
|
|
330
|
-
chain: moralisChain,
|
|
331
|
-
format,
|
|
332
|
-
normalizeMetadata,
|
|
333
|
-
media_items: mediaItems,
|
|
334
|
-
};
|
|
335
|
-
if (include)
|
|
336
|
-
query.include = include;
|
|
337
|
-
const qs = buildQueryString(query);
|
|
338
|
-
const url = `${this.baseUrl}/api/moralis/proxy/nft/${encodeURIComponent(address)}/${encodeURIComponent(tokenId)}?${qs}`;
|
|
339
|
-
const res = await fetch(url);
|
|
340
|
-
if (!res.ok)
|
|
341
|
-
throw new Error(`HTTP ${res.status}`);
|
|
342
|
-
const json = (await res.json());
|
|
343
|
-
const data = (json?.data ?? json);
|
|
344
|
-
return { success: true, data };
|
|
345
|
-
}
|
|
346
|
-
catch (error) {
|
|
347
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
348
|
-
if (attempt < MAX_RETRIES)
|
|
349
|
-
await delay(RETRY_DELAY_MS);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return { success: false, error: lastError };
|
|
353
|
-
}
|
|
354
|
-
// =========================================================================
|
|
355
|
-
// NFT Contract Metadata
|
|
356
|
-
// =========================================================================
|
|
357
|
-
/**
|
|
358
|
-
* Get metadata for an NFT contract (name, symbol, contract_type).
|
|
359
|
-
*
|
|
360
|
-
* For EVM addresses, queries the Moralis REST proxy directly.
|
|
361
|
-
* For non-EVM addresses, delegates to Cortex AI.
|
|
362
|
-
*/
|
|
363
|
-
async getNftContractMetadata(params) {
|
|
364
|
-
const { address, chain } = params;
|
|
365
|
-
if (!address)
|
|
366
|
-
return { success: false, error: 'Contract address is required' };
|
|
367
|
-
const moralisChain = toMoralisChain(chain);
|
|
368
|
-
let lastError = 'Unknown error';
|
|
369
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
370
|
-
try {
|
|
371
|
-
const qs = buildQueryString({ chain: moralisChain });
|
|
372
|
-
const url = `${this.baseUrl}/api/moralis/proxy/nft/${encodeURIComponent(address)}/metadata?${qs}`;
|
|
373
|
-
const res = await fetch(url);
|
|
374
|
-
if (!res.ok)
|
|
375
|
-
throw new Error(`HTTP ${res.status}`);
|
|
376
|
-
const json = (await res.json());
|
|
377
|
-
const data = (json?.data ?? json);
|
|
378
|
-
return { success: true, data };
|
|
379
|
-
}
|
|
380
|
-
catch (error) {
|
|
381
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
382
|
-
if (attempt < MAX_RETRIES)
|
|
383
|
-
await delay(RETRY_DELAY_MS);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return { success: false, error: lastError };
|
|
387
|
-
}
|
|
388
|
-
// =========================================================================
|
|
389
|
-
// Wallet Transaction History (Moralis REST)
|
|
390
|
-
// =========================================================================
|
|
391
|
-
/**
|
|
392
|
-
* Get a wallet's decoded on-chain transaction history via the Moralis
|
|
393
|
-
* `GET /wallets/{address}/history` endpoint.
|
|
394
|
-
*
|
|
395
|
-
* Moralis returns each transaction already categorised (send, token swap,
|
|
396
|
-
* nft purchase, airdrop, mint, contract interaction, …) with a human-readable
|
|
397
|
-
* summary and decoded native / ERC-20 / NFT transfer arrays attached.
|
|
398
|
-
*
|
|
399
|
-
* Pagination is supported via `cursor`. Pass the cursor from a previous
|
|
400
|
-
* response back in to fetch the next page.
|
|
401
|
-
*
|
|
402
|
-
* Non-EVM chains are not supported by this REST endpoint. Only EVM addresses are
|
|
403
|
-
* accepted.
|
|
404
|
-
*/
|
|
405
|
-
async getWalletHistory(params) {
|
|
406
|
-
const { address, chain, limit = 25, fromDate, toDate, fromBlock, toBlock, cursor, order = 'DESC', includeInternalTransactions, nftMetadata, } = params;
|
|
407
|
-
if (!address)
|
|
408
|
-
return { success: false, error: 'Address is required' };
|
|
409
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
410
|
-
return { success: false, error: 'Wallet history is only supported for EVM addresses' };
|
|
411
|
-
}
|
|
412
|
-
const moralisChain = toMoralisChain(chain);
|
|
413
|
-
const safeLimit = Math.max(1, Math.min(100, Math.floor(limit)));
|
|
414
|
-
let lastError = 'Unknown error';
|
|
415
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
416
|
-
try {
|
|
417
|
-
const query = {
|
|
418
|
-
chain: moralisChain,
|
|
419
|
-
limit: safeLimit,
|
|
420
|
-
order,
|
|
421
|
-
};
|
|
422
|
-
if (fromDate)
|
|
423
|
-
query.from_date = fromDate;
|
|
424
|
-
if (toDate)
|
|
425
|
-
query.to_date = toDate;
|
|
426
|
-
if (fromBlock != null)
|
|
427
|
-
query.from_block = fromBlock;
|
|
428
|
-
if (toBlock != null)
|
|
429
|
-
query.to_block = toBlock;
|
|
430
|
-
if (cursor)
|
|
431
|
-
query.cursor = cursor;
|
|
432
|
-
if (includeInternalTransactions != null) {
|
|
433
|
-
query.include_internal_transactions = includeInternalTransactions;
|
|
434
|
-
}
|
|
435
|
-
if (nftMetadata != null)
|
|
436
|
-
query.nft_metadata = nftMetadata;
|
|
437
|
-
const qs = buildQueryString(query);
|
|
438
|
-
const url = `${this.baseUrl}/api/moralis/proxy/wallets/${encodeURIComponent(address)}/history?${qs}`;
|
|
439
|
-
const res = await fetch(url);
|
|
440
|
-
if (!res.ok)
|
|
441
|
-
throw new Error(`HTTP ${res.status}`);
|
|
442
|
-
const json = (await res.json());
|
|
443
|
-
const payload = json?.data ?? json;
|
|
444
|
-
const data = payload;
|
|
445
|
-
return { success: true, data };
|
|
446
|
-
}
|
|
447
|
-
catch (error) {
|
|
448
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
449
|
-
if (attempt < MAX_RETRIES)
|
|
450
|
-
await delay(RETRY_DELAY_MS);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return { success: false, error: lastError };
|
|
454
|
-
}
|
|
455
|
-
// =========================================================================
|
|
456
|
-
// Wallet ERC-20 Transfers (GET /{address}/erc20/transfers)
|
|
457
|
-
// =========================================================================
|
|
458
|
-
/**
|
|
459
|
-
* Get every ERC-20 transfer involving a wallet, optionally filtered by one
|
|
460
|
-
* or more token contract addresses.
|
|
461
|
-
*
|
|
462
|
-
* Use this to answer questions like:
|
|
463
|
-
* - "When did I last send USDC and to whom?"
|
|
464
|
-
* - "Who have I sent token 0x… to?"
|
|
465
|
-
* - "Who sent me USDC?"
|
|
466
|
-
* - "Show all USDT transfers for my wallet"
|
|
467
|
-
*/
|
|
468
|
-
async getWalletTokenTransfers(params) {
|
|
469
|
-
const { address, chain, contractAddresses, limit = 25, fromDate, toDate, fromBlock, toBlock, cursor, order = 'DESC', } = params;
|
|
470
|
-
if (!address)
|
|
471
|
-
return { success: false, error: 'Address is required' };
|
|
472
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
473
|
-
return { success: false, error: 'ERC-20 transfers are only supported for EVM addresses' };
|
|
474
|
-
}
|
|
475
|
-
const moralisChain = toMoralisChain(chain);
|
|
476
|
-
const safeLimit = Math.max(1, Math.min(100, Math.floor(limit)));
|
|
477
|
-
let lastError = 'Unknown error';
|
|
478
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
479
|
-
try {
|
|
480
|
-
const query = {
|
|
481
|
-
chain: moralisChain,
|
|
482
|
-
limit: safeLimit,
|
|
483
|
-
order,
|
|
484
|
-
};
|
|
485
|
-
if (fromDate)
|
|
486
|
-
query.from_date = fromDate;
|
|
487
|
-
if (toDate)
|
|
488
|
-
query.to_date = toDate;
|
|
489
|
-
if (fromBlock != null)
|
|
490
|
-
query.from_block = fromBlock;
|
|
491
|
-
if (toBlock != null)
|
|
492
|
-
query.to_block = toBlock;
|
|
493
|
-
if (cursor)
|
|
494
|
-
query.cursor = cursor;
|
|
495
|
-
if (contractAddresses?.length)
|
|
496
|
-
query.contract_addresses = contractAddresses;
|
|
497
|
-
const qs = buildQueryString(query);
|
|
498
|
-
const url = `${this.baseUrl}/api/moralis/proxy/${encodeURIComponent(address)}/erc20/transfers?${qs}`;
|
|
499
|
-
const res = await fetch(url);
|
|
500
|
-
if (!res.ok)
|
|
501
|
-
throw new Error(`HTTP ${res.status}`);
|
|
502
|
-
const json = (await res.json());
|
|
503
|
-
const payload = json?.data ?? json;
|
|
504
|
-
const data = payload;
|
|
505
|
-
return { success: true, data };
|
|
506
|
-
}
|
|
507
|
-
catch (error) {
|
|
508
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
509
|
-
if (attempt < MAX_RETRIES)
|
|
510
|
-
await delay(RETRY_DELAY_MS);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
return { success: false, error: lastError };
|
|
514
|
-
}
|
|
515
|
-
// =========================================================================
|
|
516
|
-
// Wallet NFT Transfers (GET /{address}/nft/transfers)
|
|
517
|
-
// =========================================================================
|
|
518
|
-
/**
|
|
519
|
-
* Get every NFT transfer involving a wallet, optionally filtered by one
|
|
520
|
-
* or more NFT contract addresses.
|
|
521
|
-
*
|
|
522
|
-
* Use this to answer questions like:
|
|
523
|
-
* - "Which NFTs did I sell?"
|
|
524
|
-
* - "Who did I send my NFTs to?"
|
|
525
|
-
* - "Who sent me NFTs from collection 0x…?"
|
|
526
|
-
* - "Show all NFT transfers with last sale price"
|
|
527
|
-
*/
|
|
528
|
-
async getWalletNftTransfers(params) {
|
|
529
|
-
const { address, chain, contractAddresses, limit = 25, fromDate, toDate, fromBlock, toBlock, cursor, order = 'DESC', includePrices, format = 'decimal', } = params;
|
|
530
|
-
if (!address)
|
|
531
|
-
return { success: false, error: 'Address is required' };
|
|
532
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
533
|
-
return { success: false, error: 'NFT transfers are only supported for EVM addresses' };
|
|
534
|
-
}
|
|
535
|
-
const moralisChain = toMoralisChain(chain);
|
|
536
|
-
const safeLimit = Math.max(1, Math.min(100, Math.floor(limit)));
|
|
537
|
-
let lastError = 'Unknown error';
|
|
538
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
539
|
-
try {
|
|
540
|
-
const query = {
|
|
541
|
-
chain: moralisChain,
|
|
542
|
-
limit: safeLimit,
|
|
543
|
-
order,
|
|
544
|
-
format,
|
|
545
|
-
};
|
|
546
|
-
if (fromDate)
|
|
547
|
-
query.from_date = fromDate;
|
|
548
|
-
if (toDate)
|
|
549
|
-
query.to_date = toDate;
|
|
550
|
-
if (fromBlock != null)
|
|
551
|
-
query.from_block = fromBlock;
|
|
552
|
-
if (toBlock != null)
|
|
553
|
-
query.to_block = toBlock;
|
|
554
|
-
if (cursor)
|
|
555
|
-
query.cursor = cursor;
|
|
556
|
-
if (contractAddresses?.length)
|
|
557
|
-
query.contract_addresses = contractAddresses;
|
|
558
|
-
if (includePrices != null)
|
|
559
|
-
query.include_prices = includePrices;
|
|
560
|
-
const qs = buildQueryString(query);
|
|
561
|
-
const url = `${this.baseUrl}/api/moralis/proxy/${encodeURIComponent(address)}/nft/transfers?${qs}`;
|
|
562
|
-
const res = await fetch(url);
|
|
563
|
-
if (!res.ok)
|
|
564
|
-
throw new Error(`HTTP ${res.status}`);
|
|
565
|
-
const json = (await res.json());
|
|
566
|
-
const payload = json?.data ?? json;
|
|
567
|
-
const data = payload;
|
|
568
|
-
return { success: true, data };
|
|
569
|
-
}
|
|
570
|
-
catch (error) {
|
|
571
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
572
|
-
if (attempt < MAX_RETRIES)
|
|
573
|
-
await delay(RETRY_DELAY_MS);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
return { success: false, error: lastError };
|
|
577
|
-
}
|
|
578
|
-
// =========================================================================
|
|
579
|
-
// Token Holders (GET /erc20/{address}/holders)
|
|
580
|
-
// =========================================================================
|
|
581
|
-
/**
|
|
582
|
-
* Get the paginated list of holders for an ERC-20 token.
|
|
583
|
-
*
|
|
584
|
-
* URL: GET /api/moralis/proxy/erc20/{contractAddress}/holders
|
|
585
|
-
*
|
|
586
|
-
* Use to answer questions like:
|
|
587
|
-
* - "Who holds USDC?"
|
|
588
|
-
* - "Show top holders of 0x…"
|
|
589
|
-
* - "How many wallets hold this token?"
|
|
590
|
-
* - "What % does the biggest holder control?"
|
|
591
|
-
*/
|
|
592
|
-
async getTokenHolders(params) {
|
|
593
|
-
const { address, chain } = params;
|
|
594
|
-
if (!address)
|
|
595
|
-
return { success: false, error: 'Contract address is required' };
|
|
596
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
597
|
-
return { success: false, error: 'Token holders is only supported for EVM contract addresses' };
|
|
598
|
-
}
|
|
599
|
-
const moralisChain = toMoralisChain(chain);
|
|
600
|
-
let lastError = 'Unknown error';
|
|
601
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
602
|
-
try {
|
|
603
|
-
const qs = buildQueryString({ chain: moralisChain });
|
|
604
|
-
const url = `${this.baseUrl}/api/moralis/proxy/erc20/${encodeURIComponent(address)}/holders?${qs}`;
|
|
605
|
-
const res = await fetch(url);
|
|
606
|
-
if (!res.ok)
|
|
607
|
-
throw new Error(`HTTP ${res.status}`);
|
|
608
|
-
const json = (await res.json());
|
|
609
|
-
const payload = json?.data ?? json;
|
|
610
|
-
const data = payload;
|
|
611
|
-
return { success: true, data };
|
|
612
|
-
}
|
|
613
|
-
catch (error) {
|
|
614
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
615
|
-
if (attempt < MAX_RETRIES)
|
|
616
|
-
await delay(RETRY_DELAY_MS);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
return { success: false, error: lastError };
|
|
620
|
-
}
|
|
621
|
-
// =========================================================================
|
|
622
|
-
// Wallet Net Worth
|
|
623
|
-
// =========================================================================
|
|
624
|
-
/**
|
|
625
|
-
* Get a wallet's total net worth in USD, broken down per chain.
|
|
626
|
-
*
|
|
627
|
-
* URL: GET /api/moralis/proxy/wallets/{address}/net-worth
|
|
628
|
-
*
|
|
629
|
-
* Use to answer questions like:
|
|
630
|
-
* - "What's my total wallet value?"
|
|
631
|
-
* - "How much is my portfolio worth on each chain?"
|
|
632
|
-
*/
|
|
633
|
-
async getWalletNetWorth(params) {
|
|
634
|
-
const { address, chains, excludeSpam, excludeUnverifiedContracts, maxTokenInactivity, minPairSideLiquidityUsd } = params;
|
|
635
|
-
if (!address)
|
|
636
|
-
return { success: false, error: 'Address is required' };
|
|
637
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
638
|
-
return { success: false, error: 'Wallet net worth is only supported for EVM addresses' };
|
|
639
|
-
}
|
|
640
|
-
let lastError = 'Unknown error';
|
|
641
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
642
|
-
try {
|
|
643
|
-
const query = {};
|
|
644
|
-
if (chains && chains.length > 0)
|
|
645
|
-
query.chains = chains.map((c) => toMoralisChain(c));
|
|
646
|
-
if (excludeSpam != null)
|
|
647
|
-
query.exclude_spam = excludeSpam;
|
|
648
|
-
if (excludeUnverifiedContracts != null)
|
|
649
|
-
query.exclude_unverified_contracts = excludeUnverifiedContracts;
|
|
650
|
-
if (maxTokenInactivity != null)
|
|
651
|
-
query.max_token_inactivity = maxTokenInactivity;
|
|
652
|
-
if (minPairSideLiquidityUsd != null)
|
|
653
|
-
query.min_pair_side_liquidity_usd = minPairSideLiquidityUsd;
|
|
654
|
-
const qs = buildQueryString(query);
|
|
655
|
-
const url = `${this.baseUrl}/api/moralis/proxy/wallets/${encodeURIComponent(address)}/net-worth${qs ? `?${qs}` : ''}`;
|
|
656
|
-
const res = await fetch(url);
|
|
657
|
-
if (!res.ok)
|
|
658
|
-
throw new Error(`HTTP ${res.status}`);
|
|
659
|
-
const json = (await res.json());
|
|
660
|
-
const payload = json?.data ?? json;
|
|
661
|
-
const data = payload;
|
|
662
|
-
return { success: true, data };
|
|
663
|
-
}
|
|
664
|
-
catch (error) {
|
|
665
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
666
|
-
if (attempt < MAX_RETRIES)
|
|
667
|
-
await delay(RETRY_DELAY_MS);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return { success: false, error: lastError };
|
|
671
|
-
}
|
|
672
|
-
// =========================================================================
|
|
673
|
-
// Wallet PnL (Profitability)
|
|
674
|
-
// =========================================================================
|
|
675
|
-
/**
|
|
676
|
-
* Get aggregate profit-and-loss summary for a wallet.
|
|
677
|
-
*
|
|
678
|
-
* URL: GET /api/moralis/proxy/wallets/{address}/profitability/summary
|
|
679
|
-
*
|
|
680
|
-
* Mainnet only. Moralis supports: Ethereum (0x1), Base (0x2105), Polygon (0x89).
|
|
681
|
-
*/
|
|
682
|
-
async getWalletPnlSummary(params) {
|
|
683
|
-
const { address, chain, days } = params;
|
|
684
|
-
if (!address)
|
|
685
|
-
return { success: false, error: 'Address is required' };
|
|
686
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
687
|
-
return { success: false, error: 'Wallet PnL summary is only supported for EVM addresses' };
|
|
688
|
-
}
|
|
689
|
-
const moralisChain = toMoralisChain(chain);
|
|
690
|
-
let lastError = 'Unknown error';
|
|
691
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
692
|
-
try {
|
|
693
|
-
const query = { chain: moralisChain };
|
|
694
|
-
if (days)
|
|
695
|
-
query.days = days;
|
|
696
|
-
const qs = buildQueryString(query);
|
|
697
|
-
const url = `${this.baseUrl}/api/moralis/proxy/wallets/${encodeURIComponent(address)}/profitability/summary?${qs}`;
|
|
698
|
-
const res = await fetch(url);
|
|
699
|
-
if (!res.ok)
|
|
700
|
-
throw new Error(`HTTP ${res.status}`);
|
|
701
|
-
const json = (await res.json());
|
|
702
|
-
const payload = json?.data ?? json;
|
|
703
|
-
const data = payload;
|
|
704
|
-
return { success: true, data };
|
|
705
|
-
}
|
|
706
|
-
catch (error) {
|
|
707
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
708
|
-
if (attempt < MAX_RETRIES)
|
|
709
|
-
await delay(RETRY_DELAY_MS);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
return { success: false, error: lastError };
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* Get per-token profit-and-loss breakdown for a wallet.
|
|
716
|
-
*
|
|
717
|
-
* URL: GET /api/moralis/proxy/wallets/{address}/profitability
|
|
718
|
-
*
|
|
719
|
-
* Mainnet only. Moralis supports: Ethereum (0x1), Base (0x2105), Polygon (0x89).
|
|
720
|
-
* tokenAddresses supports up to 25 addresses.
|
|
721
|
-
*/
|
|
722
|
-
async getWalletPnl(params) {
|
|
723
|
-
const { address, chain, days, tokenAddresses } = params;
|
|
724
|
-
if (!address)
|
|
725
|
-
return { success: false, error: 'Address is required' };
|
|
726
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
727
|
-
return { success: false, error: 'Wallet PnL is only supported for EVM addresses' };
|
|
728
|
-
}
|
|
729
|
-
const moralisChain = toMoralisChain(chain);
|
|
730
|
-
let lastError = 'Unknown error';
|
|
731
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
732
|
-
try {
|
|
733
|
-
const query = { chain: moralisChain };
|
|
734
|
-
if (days)
|
|
735
|
-
query.days = days;
|
|
736
|
-
if (tokenAddresses && tokenAddresses.length > 0) {
|
|
737
|
-
query.token_addresses = tokenAddresses.slice(0, 25);
|
|
738
|
-
}
|
|
739
|
-
const qs = buildQueryString(query);
|
|
740
|
-
const url = `${this.baseUrl}/api/moralis/proxy/wallets/${encodeURIComponent(address)}/profitability?${qs}`;
|
|
741
|
-
const res = await fetch(url);
|
|
742
|
-
if (!res.ok)
|
|
743
|
-
throw new Error(`HTTP ${res.status}`);
|
|
744
|
-
const json = (await res.json());
|
|
745
|
-
const payload = json?.data ?? json;
|
|
746
|
-
const data = payload;
|
|
747
|
-
return { success: true, data };
|
|
748
|
-
}
|
|
749
|
-
catch (error) {
|
|
750
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
751
|
-
if (attempt < MAX_RETRIES)
|
|
752
|
-
await delay(RETRY_DELAY_MS);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
return { success: false, error: lastError };
|
|
756
|
-
}
|
|
757
|
-
// =========================================================================
|
|
758
|
-
// Transaction by Hash (GET /transaction/{hash}?decode=true)
|
|
759
|
-
// =========================================================================
|
|
760
|
-
/**
|
|
761
|
-
* Get a decoded transaction by its hash.
|
|
762
|
-
*
|
|
763
|
-
* URL: GET /api/moralis/proxy/transaction/{transactionHash}?chain=…&decode=true
|
|
764
|
-
*
|
|
765
|
-
* Returns full transaction details including decoded function call and
|
|
766
|
-
* decoded event logs, along with address labels and entity names.
|
|
767
|
-
*/
|
|
768
|
-
async getTransactionByHash(params) {
|
|
769
|
-
const { transactionHash, chain } = params;
|
|
770
|
-
if (!transactionHash)
|
|
771
|
-
return { success: false, error: 'Transaction hash is required' };
|
|
772
|
-
const moralisChain = toMoralisChain(chain);
|
|
773
|
-
let lastError = 'Unknown error';
|
|
774
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
775
|
-
try {
|
|
776
|
-
const qs = buildQueryString({ chain: moralisChain });
|
|
777
|
-
const url = `${this.baseUrl}/api/moralis/proxy/transaction/${encodeURIComponent(transactionHash)}/verbose?${qs}`;
|
|
778
|
-
const res = await fetch(url);
|
|
779
|
-
if (!res.ok)
|
|
780
|
-
throw new Error(`HTTP ${res.status}`);
|
|
781
|
-
const json = (await res.json());
|
|
782
|
-
const payload = json?.data ?? json;
|
|
783
|
-
const data = payload;
|
|
784
|
-
return { success: true, data };
|
|
785
|
-
}
|
|
786
|
-
catch (error) {
|
|
787
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
788
|
-
if (attempt < MAX_RETRIES)
|
|
789
|
-
await delay(RETRY_DELAY_MS);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return { success: false, error: lastError };
|
|
793
|
-
}
|
|
794
|
-
// =========================================================================
|
|
795
|
-
// Wallet Approvals — active ERC-20 token approvals
|
|
796
|
-
// =========================================================================
|
|
797
|
-
/**
|
|
798
|
-
* List every active ERC-20 token approval granted by a wallet, paginated.
|
|
799
|
-
*
|
|
800
|
-
* URL: GET /api/moralis/proxy/wallets/{address}/approvals?chain=…&limit=…&cursor=…
|
|
801
|
-
*
|
|
802
|
-
* Moralis docs: https://docs.moralis.com/data-api/evm/wallet/approvals
|
|
803
|
-
*
|
|
804
|
-
* Mainnet EVM only. Each row includes the approved token (with current
|
|
805
|
-
* balance, USD price, `usd_at_risk`) and the spender (address, label,
|
|
806
|
-
* entity).
|
|
807
|
-
*/
|
|
808
|
-
async getWalletApprovals(params) {
|
|
809
|
-
const { address, chain, limit, cursor } = params;
|
|
810
|
-
if (!address)
|
|
811
|
-
return { success: false, error: 'Address is required' };
|
|
812
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
813
|
-
return { success: false, error: 'Wallet approvals are only supported for EVM addresses' };
|
|
814
|
-
}
|
|
815
|
-
const moralisChain = toMoralisChain(chain);
|
|
816
|
-
let lastError = 'Unknown error';
|
|
817
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
818
|
-
try {
|
|
819
|
-
const query = { chain: moralisChain };
|
|
820
|
-
if (limit != null)
|
|
821
|
-
query.limit = limit;
|
|
822
|
-
if (cursor)
|
|
823
|
-
query.cursor = cursor;
|
|
824
|
-
const qs = buildQueryString(query);
|
|
825
|
-
const url = `${this.baseUrl}/api/moralis/proxy/wallets/${encodeURIComponent(address)}/approvals?${qs}`;
|
|
826
|
-
const res = await fetch(url);
|
|
827
|
-
if (!res.ok)
|
|
828
|
-
throw new Error(`HTTP ${res.status}`);
|
|
829
|
-
const json = (await res.json());
|
|
830
|
-
const payload = json?.data ?? json;
|
|
831
|
-
const data = payload;
|
|
832
|
-
return { success: true, data };
|
|
833
|
-
}
|
|
834
|
-
catch (error) {
|
|
835
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
836
|
-
if (attempt < MAX_RETRIES)
|
|
837
|
-
await delay(RETRY_DELAY_MS);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
return { success: false, error: lastError };
|
|
841
|
-
}
|
|
842
|
-
// =========================================================================
|
|
843
|
-
// Wallet DeFi — Protocols summary & positions
|
|
844
|
-
// =========================================================================
|
|
845
|
-
/**
|
|
846
|
-
* Get a DeFi summary for a wallet: aggregate USD value, unclaimed rewards
|
|
847
|
-
* and a per-protocol breakdown of where the wallet has positions.
|
|
848
|
-
*
|
|
849
|
-
* URL: GET /api/moralis/proxy/wallets/{address}/defi/summary?chain=…
|
|
850
|
-
*
|
|
851
|
-
* Moralis docs: https://docs.moralis.com/data-api/evm/wallet/wallet-protocols
|
|
852
|
-
*
|
|
853
|
-
* Mainnet EVM only.
|
|
854
|
-
*/
|
|
855
|
-
async getWalletDefiSummary(params) {
|
|
856
|
-
const { address, chain } = params;
|
|
857
|
-
if (!address)
|
|
858
|
-
return { success: false, error: 'Address is required' };
|
|
859
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
860
|
-
return { success: false, error: 'Wallet DeFi summary is only supported for EVM addresses' };
|
|
861
|
-
}
|
|
862
|
-
const moralisChain = toMoralisChain(chain);
|
|
863
|
-
let lastError = 'Unknown error';
|
|
864
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
865
|
-
try {
|
|
866
|
-
const qs = buildQueryString({ chains: moralisChain });
|
|
867
|
-
const url = `${this.v1BaseUrl}/api/moralis-v1/proxy/wallets/${encodeURIComponent(address)}/defi/summary?${qs}`;
|
|
868
|
-
const res = await fetch(url);
|
|
869
|
-
if (!res.ok)
|
|
870
|
-
throw new Error(`HTTP ${res.status}`);
|
|
871
|
-
const json = (await res.json());
|
|
872
|
-
const payload = json?.data ?? json;
|
|
873
|
-
const data = payload;
|
|
874
|
-
return { success: true, data };
|
|
875
|
-
}
|
|
876
|
-
catch (error) {
|
|
877
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
878
|
-
if (attempt < MAX_RETRIES)
|
|
879
|
-
await delay(RETRY_DELAY_MS);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
return { success: false, error: lastError };
|
|
883
|
-
}
|
|
884
|
-
/**
|
|
885
|
-
* Get every DeFi position a wallet holds across all supported protocols,
|
|
886
|
-
* each enriched with the owning protocol's identity.
|
|
887
|
-
*
|
|
888
|
-
* URL: GET /api/moralis/proxy/wallets/{address}/defi/positions?chain=…
|
|
889
|
-
*
|
|
890
|
-
* Moralis docs: https://docs.moralis.com/data-api/evm/wallet/wallet-positions
|
|
891
|
-
*/
|
|
892
|
-
async getWalletDefiPositions(params) {
|
|
893
|
-
const { address, chain } = params;
|
|
894
|
-
if (!address)
|
|
895
|
-
return { success: false, error: 'Address is required' };
|
|
896
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
897
|
-
return { success: false, error: 'Wallet DeFi positions are only supported for EVM addresses' };
|
|
898
|
-
}
|
|
899
|
-
const moralisChain = toMoralisChain(chain);
|
|
900
|
-
let lastError = 'Unknown error';
|
|
901
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
902
|
-
try {
|
|
903
|
-
const qs = buildQueryString({ chains: moralisChain });
|
|
904
|
-
const url = `${this.v1BaseUrl}/api/moralis-v1/proxy/wallets/${encodeURIComponent(address)}/defi/positions?${qs}`;
|
|
905
|
-
const res = await fetch(url);
|
|
906
|
-
if (!res.ok)
|
|
907
|
-
throw new Error(`HTTP ${res.status}`);
|
|
908
|
-
const json = (await res.json());
|
|
909
|
-
const payload = json?.data ?? json;
|
|
910
|
-
const data = normalizeDefiPositionsPayload(payload);
|
|
911
|
-
return { success: true, data };
|
|
912
|
-
}
|
|
913
|
-
catch (error) {
|
|
914
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
915
|
-
if (attempt < MAX_RETRIES)
|
|
916
|
-
await delay(RETRY_DELAY_MS);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
return { success: false, error: lastError };
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Get detailed positions a wallet holds inside a specific protocol
|
|
923
|
-
* (e.g. `uniswap-v3`, `aave-v3`, `lido`).
|
|
924
|
-
*
|
|
925
|
-
* URL: GET /api/moralis/proxy/wallets/{address}/defi/{protocol}/positions?chain=…
|
|
926
|
-
*
|
|
927
|
-
* Moralis docs: https://docs.moralis.com/data-api/evm/wallet/detailed-positions
|
|
928
|
-
*/
|
|
929
|
-
async getWalletDefiProtocolPositions(params) {
|
|
930
|
-
const { address, protocol, chain } = params;
|
|
931
|
-
if (!address)
|
|
932
|
-
return { success: false, error: 'Address is required' };
|
|
933
|
-
if (!protocol)
|
|
934
|
-
return { success: false, error: 'Protocol identifier is required' };
|
|
935
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
936
|
-
return { success: false, error: 'Wallet DeFi protocol positions are only supported for EVM addresses' };
|
|
937
|
-
}
|
|
938
|
-
const moralisChain = toMoralisChain(chain);
|
|
939
|
-
let lastError = 'Unknown error';
|
|
940
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
941
|
-
try {
|
|
942
|
-
const qs = buildQueryString({ chains: moralisChain });
|
|
943
|
-
const url = `${this.v1BaseUrl}/api/moralis-v1/proxy/wallets/${encodeURIComponent(address)}/defi/${encodeURIComponent(protocol)}/positions?${qs}`;
|
|
944
|
-
const res = await fetch(url);
|
|
945
|
-
if (!res.ok)
|
|
946
|
-
throw new Error(`HTTP ${res.status}`);
|
|
947
|
-
const json = (await res.json());
|
|
948
|
-
const raw = json;
|
|
949
|
-
const r = raw.result;
|
|
950
|
-
const data = {
|
|
951
|
-
protocol_id: r.protocolId,
|
|
952
|
-
protocol_name: r.protocolName,
|
|
953
|
-
protocol_url: r.protocolUrl ?? '',
|
|
954
|
-
protocol_logo: r.protocolLogo ?? '',
|
|
955
|
-
total_usd_value: r.totalUsd ?? 0,
|
|
956
|
-
total_unclaimed_usd_value: r.totalUnclaimedUsd ?? null,
|
|
957
|
-
positions: r.positions.map((p) => ({
|
|
958
|
-
label: p.label,
|
|
959
|
-
address: p.address,
|
|
960
|
-
balance_usd: p.balanceUsd ?? 0,
|
|
961
|
-
total_unclaimed_usd_value: p.unclaimedUsd ?? 0,
|
|
962
|
-
position_details: p.details,
|
|
963
|
-
tokens: p.tokens.map((t) => ({
|
|
964
|
-
token_type: t.tokenType,
|
|
965
|
-
address: t.address,
|
|
966
|
-
contract_address: t.address,
|
|
967
|
-
name: t.name ?? '',
|
|
968
|
-
symbol: t.symbol ?? '',
|
|
969
|
-
decimals: t.decimals ?? 18,
|
|
970
|
-
logo: t.logo,
|
|
971
|
-
balance: t.balance ?? '0',
|
|
972
|
-
balance_formatted: t.balanceFormatted ?? '0',
|
|
973
|
-
usd_price: t.usdPrice,
|
|
974
|
-
usd_value: t.usdValue,
|
|
975
|
-
})),
|
|
976
|
-
})),
|
|
977
|
-
};
|
|
978
|
-
return { success: true, data };
|
|
979
|
-
}
|
|
980
|
-
catch (error) {
|
|
981
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
982
|
-
if (attempt < MAX_RETRIES)
|
|
983
|
-
await delay(RETRY_DELAY_MS);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
return { success: false, error: lastError };
|
|
987
|
-
}
|
|
988
|
-
// =========================================================================
|
|
989
|
-
// Search Tokens by Key — delegates to PantographService
|
|
990
|
-
// =========================================================================
|
|
991
|
-
/** Search for tokens by symbol or name keyword on a specific chain. */
|
|
992
|
-
async searchTokensByKey(params) {
|
|
993
|
-
return this.pantograph.searchTokensByKey(params);
|
|
994
|
-
}
|
|
995
|
-
// =========================================================================
|
|
996
|
-
// Token Analytics
|
|
997
|
-
// =========================================================================
|
|
998
|
-
/**
|
|
999
|
-
* Detailed trading analytics for a single token: buy/sell volume, unique
|
|
1000
|
-
* buyers/sellers, transaction counts, unique wallets, price change,
|
|
1001
|
-
* current USD price, total liquidity and FDV — all broken down across
|
|
1002
|
-
* 5min / 1h / 6h / 24h windows.
|
|
1003
|
-
*
|
|
1004
|
-
* URL: GET /api/moralis/proxy/tokens/{tokenAddress}/analytics
|
|
1005
|
-
* Upstream: GET https://deep-index.moralis.io/api/v2.2/tokens/{tokenAddress}/analytics
|
|
1006
|
-
*
|
|
1007
|
-
* Use to answer questions like:
|
|
1008
|
-
* - "How is PEPE trading today?"
|
|
1009
|
-
* - "What's the 24h buy vs sell volume for USDC?"
|
|
1010
|
-
* - "How many unique wallets interacted with this token in the last hour?"
|
|
1011
|
-
* - "Is buying or selling pressure stronger for this token?"
|
|
1012
|
-
*/
|
|
1013
|
-
async getTokenAnalytics(params) {
|
|
1014
|
-
const { address, chain } = params;
|
|
1015
|
-
if (!address)
|
|
1016
|
-
return { success: false, error: 'Token contract address is required' };
|
|
1017
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
1018
|
-
return { success: false, error: 'Token analytics is only supported for EVM contract addresses' };
|
|
1019
|
-
}
|
|
1020
|
-
const moralisChain = toMoralisChain(chain);
|
|
1021
|
-
let lastError = 'Unknown error';
|
|
1022
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
1023
|
-
try {
|
|
1024
|
-
const qs = buildQueryString({ chain: moralisChain });
|
|
1025
|
-
const url = `${this.baseUrl}/api/moralis/proxy/tokens/${encodeURIComponent(address)}/analytics?${qs}`;
|
|
1026
|
-
const res = await fetch(url);
|
|
1027
|
-
if (!res.ok)
|
|
1028
|
-
throw new Error(`HTTP ${res.status}`);
|
|
1029
|
-
const json = (await res.json());
|
|
1030
|
-
const payload = json?.data ?? json;
|
|
1031
|
-
const data = payload;
|
|
1032
|
-
return { success: true, data };
|
|
1033
|
-
}
|
|
1034
|
-
catch (error) {
|
|
1035
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
1036
|
-
if (attempt < MAX_RETRIES)
|
|
1037
|
-
await delay(RETRY_DELAY_MS);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
return { success: false, error: lastError };
|
|
1041
|
-
}
|
|
1042
|
-
// =========================================================================
|
|
1043
|
-
// Token Score
|
|
1044
|
-
// =========================================================================
|
|
1045
|
-
/**
|
|
1046
|
-
* Composite 0–100 health/safety score for a single token, plus the
|
|
1047
|
-
* underlying metrics Moralis uses to compute it: current USD price, paired
|
|
1048
|
-
* liquidity, multi-timeframe volume and transaction counts (10m / 30m /
|
|
1049
|
-
* 1h / 4h / 12h / 1d / 7d / 30d), and supply concentration (total + % held
|
|
1050
|
-
* by the top 10 wallets).
|
|
1051
|
-
*
|
|
1052
|
-
* URL: GET /api/moralis/proxy/tokens/{tokenAddress}/score
|
|
1053
|
-
* Upstream: GET https://deep-index.moralis.io/api/v2.2/tokens/{tokenAddress}/score
|
|
1054
|
-
*
|
|
1055
|
-
* Use to answer questions like:
|
|
1056
|
-
* - "Is PEPE a safe token?" (→ score)
|
|
1057
|
-
* - "What's the health score of this token?"
|
|
1058
|
-
* - "How concentrated is X's supply among top holders?" (→ metrics.supply.top10Percent)
|
|
1059
|
-
* - "How much volume did this token do over the last 7 days?" (→ metrics.volumeUsd.7d)
|
|
1060
|
-
*/
|
|
1061
|
-
async getTokenScore(params) {
|
|
1062
|
-
const { address, chain } = params;
|
|
1063
|
-
if (!address)
|
|
1064
|
-
return { success: false, error: 'Token contract address is required' };
|
|
1065
|
-
if (!(0, web3_1.isAddressEVM)(address)) {
|
|
1066
|
-
return { success: false, error: 'Token score is only supported for EVM contract addresses' };
|
|
1067
|
-
}
|
|
1068
|
-
const moralisChain = toMoralisChain(chain);
|
|
1069
|
-
let lastError = 'Unknown error';
|
|
1070
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
1071
|
-
try {
|
|
1072
|
-
const qs = buildQueryString({ chain: moralisChain });
|
|
1073
|
-
const url = `${this.baseUrl}/api/moralis/proxy/tokens/${encodeURIComponent(address)}/score?${qs}`;
|
|
1074
|
-
const res = await fetch(url);
|
|
1075
|
-
if (!res.ok)
|
|
1076
|
-
throw new Error(`HTTP ${res.status}`);
|
|
1077
|
-
const json = (await res.json());
|
|
1078
|
-
const payload = json?.data ?? json;
|
|
1079
|
-
const data = payload;
|
|
1080
|
-
return { success: true, data };
|
|
1081
|
-
}
|
|
1082
|
-
catch (error) {
|
|
1083
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
1084
|
-
if (attempt < MAX_RETRIES)
|
|
1085
|
-
await delay(RETRY_DELAY_MS);
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
return { success: false, error: lastError };
|
|
1089
|
-
}
|
|
1090
|
-
// =========================================================================
|
|
1091
|
-
// Trending Tokens
|
|
1092
|
-
// =========================================================================
|
|
1093
|
-
/**
|
|
1094
|
-
* List tokens trending on-chain based on trading activity, volume, liquidity
|
|
1095
|
-
* and holder growth. Moralis returns cross-chain results by default; pass a
|
|
1096
|
-
* `chain` to scope to a single network.
|
|
1097
|
-
*
|
|
1098
|
-
* URL: GET /api/moralis/proxy/tokens/trending
|
|
1099
|
-
* Upstream: GET https://deep-index.moralis.io/api/v2.2/tokens/trending
|
|
1100
|
-
*
|
|
1101
|
-
* Use to answer questions like:
|
|
1102
|
-
* - "What tokens are trending right now?"
|
|
1103
|
-
* - "Show me the hottest tokens on Base"
|
|
1104
|
-
* - "Which tokens have the most trading activity today?"
|
|
1105
|
-
*/
|
|
1106
|
-
async getTrendingTokens(params) {
|
|
1107
|
-
const chain = params?.chain;
|
|
1108
|
-
const limit = params?.limit;
|
|
1109
|
-
let lastError = 'Unknown error';
|
|
1110
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
1111
|
-
try {
|
|
1112
|
-
const query = {};
|
|
1113
|
-
if (chain)
|
|
1114
|
-
query.chain = toMoralisChain(chain);
|
|
1115
|
-
if (limit != null)
|
|
1116
|
-
query.limit = limit;
|
|
1117
|
-
const qs = buildQueryString(query);
|
|
1118
|
-
const url = `${this.baseUrl}/api/moralis/proxy/tokens/trending${qs ? `?${qs}` : ''}`;
|
|
1119
|
-
const res = await fetch(url);
|
|
1120
|
-
if (!res.ok)
|
|
1121
|
-
throw new Error(`HTTP ${res.status}`);
|
|
1122
|
-
const json = (await res.json());
|
|
1123
|
-
const payload = json?.data ?? json;
|
|
1124
|
-
const data = normalizeArrayLikePayload(payload);
|
|
1125
|
-
return { success: true, data };
|
|
1126
|
-
}
|
|
1127
|
-
catch (error) {
|
|
1128
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
1129
|
-
if (attempt < MAX_RETRIES)
|
|
1130
|
-
await delay(RETRY_DELAY_MS);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
return { success: false, error: lastError };
|
|
1134
|
-
}
|
|
1135
|
-
// =========================================================================
|
|
1136
|
-
// Top Gainers (Discovery)
|
|
1137
|
-
// =========================================================================
|
|
1138
|
-
/**
|
|
1139
|
-
* List tokens with the highest USD price increase over a given timeframe.
|
|
1140
|
-
* Supports optional filters for minimum market cap and security score.
|
|
1141
|
-
*
|
|
1142
|
-
* URL: GET /api/moralis/proxy/discovery/tokens/top-gainers
|
|
1143
|
-
* Upstream: GET https://deep-index.moralis.io/api/v2.2/discovery/tokens/top-gainers
|
|
1144
|
-
*
|
|
1145
|
-
* Use to answer questions like:
|
|
1146
|
-
* - "What are today's top gainers?"
|
|
1147
|
-
* - "Which tokens pumped the most this week on Arbitrum?"
|
|
1148
|
-
* - "Show me safe tokens (security score ≥ 80) that gained in the last hour"
|
|
1149
|
-
*/
|
|
1150
|
-
async getTopGainers(params) {
|
|
1151
|
-
const { chain, timeFrame, minMarketCap, securityScore } = params ?? {};
|
|
1152
|
-
let lastError = 'Unknown error';
|
|
1153
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
1154
|
-
try {
|
|
1155
|
-
const query = {};
|
|
1156
|
-
if (chain)
|
|
1157
|
-
query.chain = toMoralisChain(chain);
|
|
1158
|
-
if (timeFrame)
|
|
1159
|
-
query.time_frame = timeFrame;
|
|
1160
|
-
if (minMarketCap != null)
|
|
1161
|
-
query.min_market_cap = minMarketCap;
|
|
1162
|
-
if (securityScore != null)
|
|
1163
|
-
query.security_score = securityScore;
|
|
1164
|
-
const qs = buildQueryString(query);
|
|
1165
|
-
const url = `${this.baseUrl}/api/moralis/proxy/discovery/tokens/top-gainers${qs ? `?${qs}` : ''}`;
|
|
1166
|
-
const res = await fetch(url);
|
|
1167
|
-
if (!res.ok)
|
|
1168
|
-
throw new Error(`HTTP ${res.status}`);
|
|
1169
|
-
const json = (await res.json());
|
|
1170
|
-
const payload = json?.data ?? json;
|
|
1171
|
-
const data = normalizeArrayLikePayload(payload);
|
|
1172
|
-
return { success: true, data };
|
|
1173
|
-
}
|
|
1174
|
-
catch (error) {
|
|
1175
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
1176
|
-
if (attempt < MAX_RETRIES)
|
|
1177
|
-
await delay(RETRY_DELAY_MS);
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
return { success: false, error: lastError };
|
|
1181
|
-
}
|
|
1182
|
-
// =========================================================================
|
|
1183
|
-
// Top Losers (Discovery)
|
|
1184
|
-
// =========================================================================
|
|
1185
|
-
/**
|
|
1186
|
-
* List tokens with the largest USD price decrease over a given timeframe.
|
|
1187
|
-
* Same filter set as top-gainers (min market cap, security score) and
|
|
1188
|
-
* identical response shape — only the ranking direction differs.
|
|
1189
|
-
*
|
|
1190
|
-
* URL: GET /api/moralis/proxy/discovery/tokens/top-losers
|
|
1191
|
-
* Upstream: GET https://deep-index.moralis.io/api/v2.2/discovery/tokens/top-losers
|
|
1192
|
-
*
|
|
1193
|
-
* Use to answer questions like:
|
|
1194
|
-
* - "What are today's biggest losers?"
|
|
1195
|
-
* - "Which tokens dumped the most this week on BSC?"
|
|
1196
|
-
* - "Worst performers in the last 24h with market cap over $50M"
|
|
1197
|
-
*/
|
|
1198
|
-
async getTopLosers(params) {
|
|
1199
|
-
const { chain, timeFrame, minMarketCap, securityScore } = params ?? {};
|
|
1200
|
-
let lastError = 'Unknown error';
|
|
1201
|
-
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
1202
|
-
try {
|
|
1203
|
-
const query = {};
|
|
1204
|
-
if (chain)
|
|
1205
|
-
query.chain = toMoralisChain(chain);
|
|
1206
|
-
if (timeFrame)
|
|
1207
|
-
query.time_frame = timeFrame;
|
|
1208
|
-
if (minMarketCap != null)
|
|
1209
|
-
query.min_market_cap = minMarketCap;
|
|
1210
|
-
if (securityScore != null)
|
|
1211
|
-
query.security_score = securityScore;
|
|
1212
|
-
const qs = buildQueryString(query);
|
|
1213
|
-
const url = `${this.baseUrl}/api/moralis/proxy/discovery/tokens/top-losers${qs ? `?${qs}` : ''}`;
|
|
1214
|
-
const res = await fetch(url);
|
|
1215
|
-
if (!res.ok)
|
|
1216
|
-
throw new Error(`HTTP ${res.status}`);
|
|
1217
|
-
const json = (await res.json());
|
|
1218
|
-
const payload = json?.data ?? json;
|
|
1219
|
-
const data = normalizeArrayLikePayload(payload);
|
|
1220
|
-
return { success: true, data };
|
|
1221
|
-
}
|
|
1222
|
-
catch (error) {
|
|
1223
|
-
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
1224
|
-
if (attempt < MAX_RETRIES)
|
|
1225
|
-
await delay(RETRY_DELAY_MS);
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
return { success: false, error: lastError };
|
|
1229
|
-
}
|
|
1230
|
-
// =========================================================================
|
|
1231
|
-
// Private helpers
|
|
1232
|
-
// =========================================================================
|
|
1233
|
-
/** Enrich token balances with price/logo data. Delegates to PantographService. */
|
|
1234
|
-
async enrichTokenPrices(tokens, moralisChain) {
|
|
1235
|
-
return this.pantograph.enrichTokenPrices(tokens, moralisChain);
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
exports.MoralisService = MoralisService;
|
|
1239
|
-
//# sourceMappingURL=MoralisService.js.map
|