@oobe-protocol-labs/synapse-client-sdk 1.0.0-beta
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/LICENSE +21 -0
- package/README.md +1393 -0
- package/dist/cjs/advanced/circuit-breaker.d.ts +111 -0
- package/dist/cjs/advanced/circuit-breaker.d.ts.map +1 -0
- package/dist/cjs/advanced/circuit-breaker.js +278 -0
- package/dist/cjs/advanced/circuit-breaker.js.map +1 -0
- package/dist/cjs/advanced/index.d.ts +8 -0
- package/dist/cjs/advanced/index.d.ts.map +1 -0
- package/dist/cjs/advanced/index.js +13 -0
- package/dist/cjs/advanced/index.js.map +1 -0
- package/dist/cjs/advanced/load-balancer.d.ts +114 -0
- package/dist/cjs/advanced/load-balancer.d.ts.map +1 -0
- package/dist/cjs/advanced/load-balancer.js +354 -0
- package/dist/cjs/advanced/load-balancer.js.map +1 -0
- package/dist/cjs/advanced/smart-caching.d.ts +113 -0
- package/dist/cjs/advanced/smart-caching.d.ts.map +1 -0
- package/dist/cjs/advanced/smart-caching.js +461 -0
- package/dist/cjs/advanced/smart-caching.js.map +1 -0
- package/dist/cjs/advanced/types.d.ts +228 -0
- package/dist/cjs/advanced/types.d.ts.map +1 -0
- package/dist/cjs/advanced/types.js +7 -0
- package/dist/cjs/advanced/types.js.map +1 -0
- package/dist/cjs/ai/index.d.ts +15 -0
- package/dist/cjs/ai/index.d.ts.map +1 -0
- package/dist/cjs/ai/index.js +20 -0
- package/dist/cjs/ai/index.js.map +1 -0
- package/dist/cjs/ai/merkle-operation.d.ts +245 -0
- package/dist/cjs/ai/merkle-operation.d.ts.map +1 -0
- package/dist/cjs/ai/merkle-operation.js +522 -0
- package/dist/cjs/ai/merkle-operation.js.map +1 -0
- package/dist/cjs/ai/pda-manager.d.ts +134 -0
- package/dist/cjs/ai/pda-manager.d.ts.map +1 -0
- package/dist/cjs/ai/pda-manager.js +250 -0
- package/dist/cjs/ai/pda-manager.js.map +1 -0
- package/dist/cjs/ai/types.ai.d.ts +172 -0
- package/dist/cjs/ai/types.ai.d.ts.map +1 -0
- package/dist/cjs/ai/types.ai.js +14 -0
- package/dist/cjs/ai/types.ai.js.map +1 -0
- package/dist/cjs/ai/zero-combine-fetcher.d.ts +171 -0
- package/dist/cjs/ai/zero-combine-fetcher.d.ts.map +1 -0
- package/dist/cjs/ai/zero-combine-fetcher.js +412 -0
- package/dist/cjs/ai/zero-combine-fetcher.js.map +1 -0
- package/dist/cjs/client.d.ts +83 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +287 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/defi/advanced-features.d.ts +207 -0
- package/dist/cjs/defi/advanced-features.d.ts.map +1 -0
- package/dist/cjs/defi/advanced-features.js +382 -0
- package/dist/cjs/defi/advanced-features.js.map +1 -0
- package/dist/cjs/defi/index.d.ts +29 -0
- package/dist/cjs/defi/index.d.ts.map +1 -0
- package/dist/cjs/defi/index.js +50 -0
- package/dist/cjs/defi/index.js.map +1 -0
- package/dist/cjs/defi/jito.d.ts +118 -0
- package/dist/cjs/defi/jito.d.ts.map +1 -0
- package/dist/cjs/defi/jito.js +291 -0
- package/dist/cjs/defi/jito.js.map +1 -0
- package/dist/cjs/defi/jupiter.d.ts +143 -0
- package/dist/cjs/defi/jupiter.d.ts.map +1 -0
- package/dist/cjs/defi/jupiter.js +219 -0
- package/dist/cjs/defi/jupiter.js.map +1 -0
- package/dist/cjs/defi/price-feed.d.ts +63 -0
- package/dist/cjs/defi/price-feed.d.ts.map +1 -0
- package/dist/cjs/defi/price-feed.js +153 -0
- package/dist/cjs/defi/price-feed.js.map +1 -0
- package/dist/cjs/defi/token-data.d.ts +83 -0
- package/dist/cjs/defi/token-data.d.ts.map +1 -0
- package/dist/cjs/defi/token-data.js +205 -0
- package/dist/cjs/defi/token-data.js.map +1 -0
- package/dist/cjs/defi/unstable-features.d.ts +207 -0
- package/dist/cjs/defi/unstable-features.d.ts.map +1 -0
- package/dist/cjs/defi/unstable-features.js +382 -0
- package/dist/cjs/defi/unstable-features.js.map +1 -0
- package/dist/cjs/defi/utils.d.ts +265 -0
- package/dist/cjs/defi/utils.d.ts.map +1 -0
- package/dist/cjs/defi/utils.js +619 -0
- package/dist/cjs/defi/utils.js.map +1 -0
- package/dist/cjs/index.d.ts +31 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +71 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/methods/solana-rpc.d.ts +362 -0
- package/dist/cjs/methods/solana-rpc.d.ts.map +1 -0
- package/dist/cjs/methods/solana-rpc.js +584 -0
- package/dist/cjs/methods/solana-rpc.js.map +1 -0
- package/dist/cjs/nft/advanced-features.d.ts +205 -0
- package/dist/cjs/nft/advanced-features.d.ts.map +1 -0
- package/dist/cjs/nft/advanced-features.js +529 -0
- package/dist/cjs/nft/advanced-features.js.map +1 -0
- package/dist/cjs/nft/clients/index.d.ts +8 -0
- package/dist/cjs/nft/clients/index.d.ts.map +1 -0
- package/dist/cjs/nft/clients/index.js +14 -0
- package/dist/cjs/nft/clients/index.js.map +1 -0
- package/dist/cjs/nft/clients/magic-eden-client.d.ts +101 -0
- package/dist/cjs/nft/clients/magic-eden-client.d.ts.map +1 -0
- package/dist/cjs/nft/clients/magic-eden-client.js +263 -0
- package/dist/cjs/nft/clients/magic-eden-client.js.map +1 -0
- package/dist/cjs/nft/clients/metaplex-onchain-client.d.ts +154 -0
- package/dist/cjs/nft/clients/metaplex-onchain-client.d.ts.map +1 -0
- package/dist/cjs/nft/clients/metaplex-onchain-client.js +408 -0
- package/dist/cjs/nft/clients/metaplex-onchain-client.js.map +1 -0
- package/dist/cjs/nft/clients/tensor-client.d.ts +79 -0
- package/dist/cjs/nft/clients/tensor-client.d.ts.map +1 -0
- package/dist/cjs/nft/clients/tensor-client.js +222 -0
- package/dist/cjs/nft/clients/tensor-client.js.map +1 -0
- package/dist/cjs/nft/index.d.ts +13 -0
- package/dist/cjs/nft/index.d.ts.map +1 -0
- package/dist/cjs/nft/index.js +37 -0
- package/dist/cjs/nft/index.js.map +1 -0
- package/dist/cjs/nft/types.nft.d.ts +342 -0
- package/dist/cjs/nft/types.nft.d.ts.map +1 -0
- package/dist/cjs/nft/types.nft.js +3 -0
- package/dist/cjs/nft/types.nft.js.map +1 -0
- package/dist/cjs/nft/utils.d.ts +46 -0
- package/dist/cjs/nft/utils.d.ts.map +1 -0
- package/dist/cjs/nft/utils.js +281 -0
- package/dist/cjs/nft/utils.js.map +1 -0
- package/dist/cjs/types.d.ts +525 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +192 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/constant.d.ts +8 -0
- package/dist/cjs/utils/constant.d.ts.map +1 -0
- package/dist/cjs/utils/constant.js +12 -0
- package/dist/cjs/utils/constant.js.map +1 -0
- package/dist/cjs/utils/helpers.d.ts +92 -0
- package/dist/cjs/utils/helpers.d.ts.map +1 -0
- package/dist/cjs/utils/helpers.js +248 -0
- package/dist/cjs/utils/helpers.js.map +1 -0
- package/dist/cjs/websocket/client.d.ts +182 -0
- package/dist/cjs/websocket/client.d.ts.map +1 -0
- package/dist/cjs/websocket/client.js +465 -0
- package/dist/cjs/websocket/client.js.map +1 -0
- package/dist/cjs/websocket/index.d.ts +6 -0
- package/dist/cjs/websocket/index.d.ts.map +1 -0
- package/dist/cjs/websocket/index.js +9 -0
- package/dist/cjs/websocket/index.js.map +1 -0
- package/dist/docs/.nojekyll +1 -0
- package/dist/docs/assets/highlight.css +113 -0
- package/dist/docs/assets/icons.js +18 -0
- package/dist/docs/assets/icons.svg +1 -0
- package/dist/docs/assets/main.js +60 -0
- package/dist/docs/assets/navigation.js +1 -0
- package/dist/docs/assets/search.js +1 -0
- package/dist/docs/assets/style.css +1493 -0
- package/dist/docs/classes/AIError.html +40 -0
- package/dist/docs/classes/AIInvestmentAdvisor.html +26 -0
- package/dist/docs/classes/AIRarityCalculator.html +28 -0
- package/dist/docs/classes/ArbitrageDetector.html +30 -0
- package/dist/docs/classes/BatchingError.html +40 -0
- package/dist/docs/classes/CacheError.html +40 -0
- package/dist/docs/classes/CircuitBreaker.html +38 -0
- package/dist/docs/classes/CircuitBreakerError.html +40 -0
- package/dist/docs/classes/CollectionAnalytics.html +30 -0
- package/dist/docs/classes/DeFiError.html +40 -0
- package/dist/docs/classes/FlashLoanSimulator.html +26 -0
- package/dist/docs/classes/JitoIntegration.html +53 -0
- package/dist/docs/classes/JupiterIntegration.html +43 -0
- package/dist/docs/classes/Keypair.html +28 -0
- package/dist/docs/classes/LoadBalancer.html +34 -0
- package/dist/docs/classes/MEVProtection.html +28 -0
- package/dist/docs/classes/MarketplaceAggregator.html +28 -0
- package/dist/docs/classes/MerkleOperation.html +74 -0
- package/dist/docs/classes/NFTEngine.html +29 -0
- package/dist/docs/classes/NFTError.html +40 -0
- package/dist/docs/classes/NetworkError.html +40 -0
- package/dist/docs/classes/PDAManager.html +46 -0
- package/dist/docs/classes/PortfolioAnalytics.html +26 -0
- package/dist/docs/classes/PriceFeedIntegration.html +37 -0
- package/dist/docs/classes/PublicKey.html +46 -0
- package/dist/docs/classes/RateLimitError.html +39 -0
- package/dist/docs/classes/SmartCaching.html +42 -0
- package/dist/docs/classes/Synapse.html +6 -0
- package/dist/docs/classes/SynapseClient.html +55 -0
- package/dist/docs/classes/SynapseError.html +37 -0
- package/dist/docs/classes/SynapseSolanaEngine.html +49 -0
- package/dist/docs/classes/SynapseUtils.html +25 -0
- package/dist/docs/classes/TokenDataIntegration.html +41 -0
- package/dist/docs/classes/Transaction.html +87 -0
- package/dist/docs/classes/TransactionInstruction.html +10 -0
- package/dist/docs/classes/UpstreamError.html +39 -0
- package/dist/docs/classes/WebSocketClient.html +47 -0
- package/dist/docs/classes/WebSocketError.html +40 -0
- package/dist/docs/classes/YieldFarmingFinder.html +26 -0
- package/dist/docs/classes/ZeroCombineFetcher.html +25 -0
- package/dist/docs/functions/createSynapseClient.html +2 -0
- package/dist/docs/hierarchy.html +1 -0
- package/dist/docs/index.html +776 -0
- package/dist/docs/interfaces/AIAgentConfig.html +11 -0
- package/dist/docs/interfaces/AIAgentContext.html +7 -0
- package/dist/docs/interfaces/AIContext.html +6 -0
- package/dist/docs/interfaces/AIMethodResult.html +6 -0
- package/dist/docs/interfaces/AIRarityAnalysis.html +3 -0
- package/dist/docs/interfaces/AIResponse.html +5 -0
- package/dist/docs/interfaces/AccountInfo.html +8 -0
- package/dist/docs/interfaces/AdvancedClientConfig.html +7 -0
- package/dist/docs/interfaces/AdvancedEvents.html +9 -0
- package/dist/docs/interfaces/AdvancedMetricsData.html +5 -0
- package/dist/docs/interfaces/AdvancedPerformanceMetrics.html +6 -0
- package/dist/docs/interfaces/AgentAdapter.html +6 -0
- package/dist/docs/interfaces/AgentRiskReport.html +6 -0
- package/dist/docs/interfaces/AgentTradeSuggestion.html +10 -0
- package/dist/docs/interfaces/AggregatedCollectionStats.html +36 -0
- package/dist/docs/interfaces/ArbitrageOpportunity.html +8 -0
- package/dist/docs/interfaces/AutoTradingStrategy.html +13 -0
- package/dist/docs/interfaces/BatchResponse.html +4 -0
- package/dist/docs/interfaces/BatchResult.html +6 -0
- package/dist/docs/interfaces/BatcherConfig.html +5 -0
- package/dist/docs/interfaces/BirdeyeTokenPrice.html +4 -0
- package/dist/docs/interfaces/BlockhashInfo.html +5 -0
- package/dist/docs/interfaces/BuildSwapTxResult.html +7 -0
- package/dist/docs/interfaces/CacheStats.html +9 -0
- package/dist/docs/interfaces/ChunkInfo.html +10 -0
- package/dist/docs/interfaces/CircuitBreakerConfig.html +6 -0
- package/dist/docs/interfaces/ClientStats.html +14 -0
- package/dist/docs/interfaces/CollectionStats.html +17 -0
- package/dist/docs/interfaces/CollectionTrends.html +7 -0
- package/dist/docs/interfaces/CompressedNFTInfo.html +13 -0
- package/dist/docs/interfaces/ConfirmedTransaction.html +6 -0
- package/dist/docs/interfaces/ConnectionEvents.html +11 -0
- package/dist/docs/interfaces/DeFiConfig.html +16 -0
- package/dist/docs/interfaces/DiagnosticsResult.html +6 -0
- package/dist/docs/interfaces/EpochInfo.html +9 -0
- package/dist/docs/interfaces/ExecuteSwapParams.html +10 -0
- package/dist/docs/interfaces/FetchConfig.html +7 -0
- package/dist/docs/interfaces/FlashLoanAction.html +6 -0
- package/dist/docs/interfaces/FlashLoanSimulation.html +9 -0
- package/dist/docs/interfaces/GatewayStats.html +7 -0
- package/dist/docs/interfaces/InscriptionResult.html +18 -0
- package/dist/docs/interfaces/InvestmentRecommendation.html +10 -0
- package/dist/docs/interfaces/JitoBundleParams.html +4 -0
- package/dist/docs/interfaces/JitoBundleResult.html +6 -0
- package/dist/docs/interfaces/JitoBundleStatus.html +6 -0
- package/dist/docs/interfaces/JitoTipAccount.html +3 -0
- package/dist/docs/interfaces/JupiterQuoteParams.html +10 -0
- package/dist/docs/interfaces/JupiterQuoteRequest.html +17 -0
- package/dist/docs/interfaces/JupiterQuoteResponse.html +13 -0
- package/dist/docs/interfaces/JupiterSwapOptions.html +8 -0
- package/dist/docs/interfaces/JupiterSwapResponse.html +4 -0
- package/dist/docs/interfaces/JupiterTokenPrice.html +5 -0
- package/dist/docs/interfaces/LoadBalancerConfig.html +5 -0
- package/dist/docs/interfaces/MEVProtectionConfig.html +11 -0
- package/dist/docs/interfaces/MEVProtectionResult.html +6 -0
- package/dist/docs/interfaces/MagicEdenActivity.html +22 -0
- package/dist/docs/interfaces/MagicEdenCollection.html +22 -0
- package/dist/docs/interfaces/MagicEdenCollectionStats.html +17 -0
- package/dist/docs/interfaces/MagicEdenErrorResponse.html +4 -0
- package/dist/docs/interfaces/MagicEdenListing.html +24 -0
- package/dist/docs/interfaces/MarketplaceClientConfig.html +14 -0
- package/dist/docs/interfaces/MarketplaceFloorPrices.html +7 -0
- package/dist/docs/interfaces/MarketplaceListing.html +9 -0
- package/dist/docs/interfaces/MerkleLeaf.html +6 -0
- package/dist/docs/interfaces/MerkleProof.html +8 -0
- package/dist/docs/interfaces/MerkleValidationResult.html +10 -0
- package/dist/docs/interfaces/MultiChainSignal.html +8 -0
- package/dist/docs/interfaces/NFTAttribute.html +4 -0
- package/dist/docs/interfaces/NFTConfig.html +6 -0
- package/dist/docs/interfaces/NFTInfo.html +10 -0
- package/dist/docs/interfaces/NFTMetadata.html +9 -0
- package/dist/docs/interfaces/NormalizedMarketplaceListing.html +18 -0
- package/dist/docs/interfaces/OOBECompatibleAgent.html +8 -0
- package/dist/docs/interfaces/PDAConfig.html +10 -0
- package/dist/docs/interfaces/ParsedAccountInfo.html +8 -0
- package/dist/docs/interfaces/PerformanceMetrics.html +9 -0
- package/dist/docs/interfaces/PortfolioMetrics.html +10 -0
- package/dist/docs/interfaces/PriceData.html +8 -0
- package/dist/docs/interfaces/ProofRecord.html +12 -0
- package/dist/docs/interfaces/QuoteRequestCommon.html +11 -0
- package/dist/docs/interfaces/QuoteResponse.html +6 -0
- package/dist/docs/interfaces/RarityAlgorithmConfig.html +3 -0
- package/dist/docs/interfaces/RarityScore.html +8 -0
- package/dist/docs/interfaces/RaydiumBuildSwapParams.html +14 -0
- package/dist/docs/interfaces/RaydiumQuoteRequest.html +14 -0
- package/dist/docs/interfaces/RequestOptions.html +12 -0
- package/dist/docs/interfaces/RetryAttempt.html +5 -0
- package/dist/docs/interfaces/RpcError.html +5 -0
- package/dist/docs/interfaces/RpcRequest.html +6 -0
- package/dist/docs/interfaces/RpcResponse.html +6 -0
- package/dist/docs/interfaces/SecurityThreat.html +6 -0
- package/dist/docs/interfaces/SignatureInfo.html +8 -0
- package/dist/docs/interfaces/Signer.html +4 -0
- package/dist/docs/interfaces/SmartCacheConfig.html +7 -0
- package/dist/docs/interfaces/SmartQueryOptions.html +10 -0
- package/dist/docs/interfaces/StressTestOptions.html +8 -0
- package/dist/docs/interfaces/StressTestResult.html +9 -0
- package/dist/docs/interfaces/SubscriptionConfig.html +9 -0
- package/dist/docs/interfaces/SubscriptionOptions.html +7 -0
- package/dist/docs/interfaces/SubscriptionResult.html +7 -0
- package/dist/docs/interfaces/SynapseConfig.html +13 -0
- package/dist/docs/interfaces/SynapseLikeClient.html +4 -0
- package/dist/docs/interfaces/TensorCollectionStats.html +33 -0
- package/dist/docs/interfaces/TensorErrorResponse.html +5 -0
- package/dist/docs/interfaces/TensorListing.html +16 -0
- package/dist/docs/interfaces/TensorSale.html +16 -0
- package/dist/docs/interfaces/TokenAccount.html +7 -0
- package/dist/docs/interfaces/TokenAccountInfo.html +12 -0
- package/dist/docs/interfaces/TokenHolding.html +8 -0
- package/dist/docs/interfaces/TokenInfo.html +7 -0
- package/dist/docs/interfaces/TokenLargestAccount.html +5 -0
- package/dist/docs/interfaces/TokenSupply.html +5 -0
- package/dist/docs/interfaces/TradeExecution.html +14 -0
- package/dist/docs/interfaces/TransactionSignature.html +8 -0
- package/dist/docs/interfaces/UpstreamHealth.html +8 -0
- package/dist/docs/interfaces/UserPDAs.html +10 -0
- package/dist/docs/interfaces/WebSocketConfig.html +12 -0
- package/dist/docs/interfaces/WebSocketMessage.html +6 -0
- package/dist/docs/interfaces/YieldOpportunity.html +8 -0
- package/dist/docs/interfaces/ZeroChunk.html +8 -0
- package/dist/docs/interfaces/ZeroCombineResult.html +3 -0
- package/dist/docs/media/LICENSE +21 -0
- package/dist/docs/media/README-1.md +778 -0
- package/dist/docs/media/README-2.md +1050 -0
- package/dist/docs/media/README-3.md +1522 -0
- package/dist/docs/media/README-4.md +869 -0
- package/dist/docs/media/README-5.md +857 -0
- package/dist/docs/media/README-6.md +727 -0
- package/dist/docs/media/README.md +766 -0
- package/dist/docs/modules.html +168 -0
- package/dist/docs/types/BlockhashWithExpiryBlockHeight.html +1 -0
- package/dist/docs/types/Commitment.html +3 -0
- package/dist/docs/types/RiskTolerance.html +1 -0
- package/dist/docs/types/SimulatedTransactionResponse.html +1 -0
- package/dist/esm/advanced/circuit-breaker.d.ts +111 -0
- package/dist/esm/advanced/circuit-breaker.d.ts.map +1 -0
- package/dist/esm/advanced/circuit-breaker.js +274 -0
- package/dist/esm/advanced/circuit-breaker.js.map +1 -0
- package/dist/esm/advanced/index.d.ts +8 -0
- package/dist/esm/advanced/index.d.ts.map +1 -0
- package/dist/esm/advanced/index.js +7 -0
- package/dist/esm/advanced/index.js.map +1 -0
- package/dist/esm/advanced/load-balancer.d.ts +114 -0
- package/dist/esm/advanced/load-balancer.d.ts.map +1 -0
- package/dist/esm/advanced/load-balancer.js +350 -0
- package/dist/esm/advanced/load-balancer.js.map +1 -0
- package/dist/esm/advanced/smart-caching.d.ts +113 -0
- package/dist/esm/advanced/smart-caching.d.ts.map +1 -0
- package/dist/esm/advanced/smart-caching.js +457 -0
- package/dist/esm/advanced/smart-caching.js.map +1 -0
- package/dist/esm/advanced/types.d.ts +228 -0
- package/dist/esm/advanced/types.d.ts.map +1 -0
- package/dist/esm/advanced/types.js +6 -0
- package/dist/esm/advanced/types.js.map +1 -0
- package/dist/esm/ai/index.d.ts +15 -0
- package/dist/esm/ai/index.d.ts.map +1 -0
- package/dist/esm/ai/index.js +14 -0
- package/dist/esm/ai/index.js.map +1 -0
- package/dist/esm/ai/merkle-operation.d.ts +245 -0
- package/dist/esm/ai/merkle-operation.d.ts.map +1 -0
- package/dist/esm/ai/merkle-operation.js +485 -0
- package/dist/esm/ai/merkle-operation.js.map +1 -0
- package/dist/esm/ai/pda-manager.d.ts +134 -0
- package/dist/esm/ai/pda-manager.d.ts.map +1 -0
- package/dist/esm/ai/pda-manager.js +213 -0
- package/dist/esm/ai/pda-manager.js.map +1 -0
- package/dist/esm/ai/types.ai.d.ts +172 -0
- package/dist/esm/ai/types.ai.d.ts.map +1 -0
- package/dist/esm/ai/types.ai.js +13 -0
- package/dist/esm/ai/types.ai.js.map +1 -0
- package/dist/esm/ai/zero-combine-fetcher.d.ts +171 -0
- package/dist/esm/ai/zero-combine-fetcher.d.ts.map +1 -0
- package/dist/esm/ai/zero-combine-fetcher.js +408 -0
- package/dist/esm/ai/zero-combine-fetcher.js.map +1 -0
- package/dist/esm/client.d.ts +83 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +283 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/defi/advanced-features.d.ts +207 -0
- package/dist/esm/defi/advanced-features.d.ts.map +1 -0
- package/dist/esm/defi/advanced-features.js +374 -0
- package/dist/esm/defi/advanced-features.js.map +1 -0
- package/dist/esm/defi/index.d.ts +29 -0
- package/dist/esm/defi/index.d.ts.map +1 -0
- package/dist/esm/defi/index.js +37 -0
- package/dist/esm/defi/index.js.map +1 -0
- package/dist/esm/defi/jito.d.ts +118 -0
- package/dist/esm/defi/jito.d.ts.map +1 -0
- package/dist/esm/defi/jito.js +287 -0
- package/dist/esm/defi/jito.js.map +1 -0
- package/dist/esm/defi/jupiter.d.ts +143 -0
- package/dist/esm/defi/jupiter.d.ts.map +1 -0
- package/dist/esm/defi/jupiter.js +215 -0
- package/dist/esm/defi/jupiter.js.map +1 -0
- package/dist/esm/defi/price-feed.d.ts +63 -0
- package/dist/esm/defi/price-feed.d.ts.map +1 -0
- package/dist/esm/defi/price-feed.js +149 -0
- package/dist/esm/defi/price-feed.js.map +1 -0
- package/dist/esm/defi/token-data.d.ts +83 -0
- package/dist/esm/defi/token-data.d.ts.map +1 -0
- package/dist/esm/defi/token-data.js +201 -0
- package/dist/esm/defi/token-data.js.map +1 -0
- package/dist/esm/defi/unstable-features.d.ts +207 -0
- package/dist/esm/defi/unstable-features.d.ts.map +1 -0
- package/dist/esm/defi/unstable-features.js +374 -0
- package/dist/esm/defi/unstable-features.js.map +1 -0
- package/dist/esm/defi/utils.d.ts +265 -0
- package/dist/esm/defi/utils.d.ts.map +1 -0
- package/dist/esm/defi/utils.js +582 -0
- package/dist/esm/defi/utils.js.map +1 -0
- package/dist/esm/index.d.ts +31 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +47 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/methods/solana-rpc.d.ts +362 -0
- package/dist/esm/methods/solana-rpc.d.ts.map +1 -0
- package/dist/esm/methods/solana-rpc.js +532 -0
- package/dist/esm/methods/solana-rpc.js.map +1 -0
- package/dist/esm/nft/advanced-features.d.ts +205 -0
- package/dist/esm/nft/advanced-features.d.ts.map +1 -0
- package/dist/esm/nft/advanced-features.js +489 -0
- package/dist/esm/nft/advanced-features.js.map +1 -0
- package/dist/esm/nft/clients/index.d.ts +8 -0
- package/dist/esm/nft/clients/index.d.ts.map +1 -0
- package/dist/esm/nft/clients/index.js +8 -0
- package/dist/esm/nft/clients/index.js.map +1 -0
- package/dist/esm/nft/clients/magic-eden-client.d.ts +101 -0
- package/dist/esm/nft/clients/magic-eden-client.d.ts.map +1 -0
- package/dist/esm/nft/clients/magic-eden-client.js +259 -0
- package/dist/esm/nft/clients/magic-eden-client.js.map +1 -0
- package/dist/esm/nft/clients/metaplex-onchain-client.d.ts +154 -0
- package/dist/esm/nft/clients/metaplex-onchain-client.d.ts.map +1 -0
- package/dist/esm/nft/clients/metaplex-onchain-client.js +404 -0
- package/dist/esm/nft/clients/metaplex-onchain-client.js.map +1 -0
- package/dist/esm/nft/clients/tensor-client.d.ts +79 -0
- package/dist/esm/nft/clients/tensor-client.d.ts.map +1 -0
- package/dist/esm/nft/clients/tensor-client.js +218 -0
- package/dist/esm/nft/clients/tensor-client.js.map +1 -0
- package/dist/esm/nft/index.d.ts +13 -0
- package/dist/esm/nft/index.d.ts.map +1 -0
- package/dist/esm/nft/index.js +15 -0
- package/dist/esm/nft/index.js.map +1 -0
- package/dist/esm/nft/types.nft.d.ts +342 -0
- package/dist/esm/nft/types.nft.d.ts.map +1 -0
- package/dist/esm/nft/types.nft.js +2 -0
- package/dist/esm/nft/types.nft.js.map +1 -0
- package/dist/esm/nft/utils.d.ts +46 -0
- package/dist/esm/nft/utils.d.ts.map +1 -0
- package/dist/esm/nft/utils.js +276 -0
- package/dist/esm/nft/utils.js.map +1 -0
- package/dist/esm/types.d.ts +525 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +178 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/constant.d.ts +8 -0
- package/dist/esm/utils/constant.d.ts.map +1 -0
- package/dist/esm/utils/constant.js +8 -0
- package/dist/esm/utils/constant.js.map +1 -0
- package/dist/esm/utils/helpers.d.ts +92 -0
- package/dist/esm/utils/helpers.d.ts.map +1 -0
- package/dist/esm/utils/helpers.js +243 -0
- package/dist/esm/utils/helpers.js.map +1 -0
- package/dist/esm/websocket/client.d.ts +182 -0
- package/dist/esm/websocket/client.d.ts.map +1 -0
- package/dist/esm/websocket/client.js +458 -0
- package/dist/esm/websocket/client.js.map +1 -0
- package/dist/esm/websocket/index.d.ts +6 -0
- package/dist/esm/websocket/index.d.ts.map +1 -0
- package/dist/esm/websocket/index.js +5 -0
- package/dist/esm/websocket/index.js.map +1 -0
- package/package.json +160 -0
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
# DeFi Module - Synapse Client SDK
|
|
2
|
+
|
|
3
|
+
Enterprise-grade DeFi integration layer for Solana blockchain with production-ready implementations for Jupiter V6, Jito Block Engine, SPL token operations, and multi-source price aggregation.
|
|
4
|
+
|
|
5
|
+
## Architecture Overview
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
9
|
+
│ Synapse Client SDK - DeFi │
|
|
10
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
11
|
+
│ │
|
|
12
|
+
│ ┌────────────────┐ ┌────────────────┐ ┌─────────────────┐ │
|
|
13
|
+
│ │ Jupiter V6 │ │ Jito Bundles │ │ Token Data │ │
|
|
14
|
+
│ │ Integration │ │ MEV Shield │ │ SPL Accounts │ │
|
|
15
|
+
│ └────────────────┘ └────────────────┘ └─────────────────┘ │
|
|
16
|
+
│ │
|
|
17
|
+
│ ┌────────────────┐ ┌────────────────┐ ┌─────────────────┐ │
|
|
18
|
+
│ │ Price Feed │ │ MEV Protection │ │ Arbitrage │ │
|
|
19
|
+
│ │ Aggregation │ │ Engine │ │ Detection │ │
|
|
20
|
+
│ └────────────────┘ └────────────────┘ └─────────────────┘ │
|
|
21
|
+
│ │
|
|
22
|
+
│ ┌────────────────┐ ┌────────────────┐ ┌─────────────────┐ │
|
|
23
|
+
│ │ Portfolio │ │ Flash Loan │ │ Yield Farming │ │
|
|
24
|
+
│ │ Analytics │ │ Simulator │ │ Finder │ │
|
|
25
|
+
│ └────────────────┘ └────────────────┘ └─────────────────┘ │
|
|
26
|
+
│ │
|
|
27
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
28
|
+
│ Synapse RPC Client Layer │
|
|
29
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Module Capabilities
|
|
33
|
+
|
|
34
|
+
### Production Integrations
|
|
35
|
+
|
|
36
|
+
| Module | Protocol | Features | Status |
|
|
37
|
+
|--------|----------|----------|--------|
|
|
38
|
+
| **JupiterIntegration** | Jupiter V6 API | Route aggregation, best price discovery, swap execution, token listings | Production Ready |
|
|
39
|
+
| **JitoIntegration** | Jito Block Engine | MEV protection, bundle submission, tip optimization, 8 regional endpoints | Production Ready |
|
|
40
|
+
| **TokenDataIntegration** | Solana RPC | SPL token accounts, supply queries, holder distribution, balance tracking | Production Ready |
|
|
41
|
+
| **PriceFeedIntegration** | Jupiter + Birdeye | Multi-source aggregation, median price calculation, streaming updates | Production Ready |
|
|
42
|
+
|
|
43
|
+
### Advanced Feature Modules
|
|
44
|
+
|
|
45
|
+
| Module | Use Case | Complexity | Implementation |
|
|
46
|
+
|--------|----------|------------|----------------|
|
|
47
|
+
| **MEVProtection** | Sandwich attack prevention | High | Jito bundle integration + simulation |
|
|
48
|
+
| **ArbitrageDetector** | Cross-DEX opportunity scanning | High | Multi-source price comparison |
|
|
49
|
+
| **PortfolioAnalytics** | Risk assessment & diversification | Medium | Token analysis + scoring algorithms |
|
|
50
|
+
| **FlashLoanSimulator** | Profitability analysis | Medium | Transaction simulation engine |
|
|
51
|
+
| **YieldFarmingFinder** | APY discovery | Low | Protocol API aggregation |
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Technical Specifications
|
|
56
|
+
|
|
57
|
+
### Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install @synapse/client-sdk
|
|
61
|
+
# or
|
|
62
|
+
pnpm add @synapse/client-sdk
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Type System
|
|
66
|
+
|
|
67
|
+
All modules provide comprehensive TypeScript definitions with strict type checking:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import type {
|
|
71
|
+
JupiterQuoteParams,
|
|
72
|
+
JupiterQuoteResponse,
|
|
73
|
+
JitoBundle,
|
|
74
|
+
JitoBundleStatus,
|
|
75
|
+
TokenAccountInfo,
|
|
76
|
+
TokenSupply,
|
|
77
|
+
PriceData,
|
|
78
|
+
AggregatedPrice,
|
|
79
|
+
} from '@synapse/client-sdk/defi';
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Implementation Guide
|
|
85
|
+
|
|
86
|
+
### 1. Jupiter V6 Integration
|
|
87
|
+
|
|
88
|
+
#### API Endpoint Configuration
|
|
89
|
+
|
|
90
|
+
| Environment | Base URL | Rate Limit |
|
|
91
|
+
|-------------|----------|------------|
|
|
92
|
+
| Production | `https://quote-api.jup.ag/v6` | 100 req/min |
|
|
93
|
+
| Custom | User-defined | Varies |
|
|
94
|
+
|
|
95
|
+
#### Quote Parameters
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
interface JupiterQuoteParams {
|
|
99
|
+
inputMint: string; // Base58 encoded mint address
|
|
100
|
+
outputMint: string; // Base58 encoded mint address
|
|
101
|
+
amount: number; // Amount in smallest unit (lamports/decimals)
|
|
102
|
+
slippageBps?: number; // Slippage tolerance (basis points, default: 50)
|
|
103
|
+
swapMode?: 'ExactIn' | 'ExactOut';
|
|
104
|
+
onlyDirectRoutes?: boolean; // Skip multi-hop routes
|
|
105
|
+
asLegacyTransaction?: boolean;
|
|
106
|
+
maxAccounts?: number; // Limit for transaction size optimization
|
|
107
|
+
platformFeeBps?: number; // Platform fee in basis points
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Implementation Example
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { SynapseClient } from '@synapse/client-sdk';
|
|
115
|
+
import { JupiterIntegration } from '@synapse/client-sdk/defi';
|
|
116
|
+
import { Keypair, VersionedTransaction } from '@solana/web3.js';
|
|
117
|
+
|
|
118
|
+
// Initialize client
|
|
119
|
+
const client = new SynapseClient({
|
|
120
|
+
endpoint: 'https://your-synapse-gateway.com',
|
|
121
|
+
apiKey: process.env.SYNAPSE_API_KEY
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const jupiter = new JupiterIntegration(client);
|
|
125
|
+
|
|
126
|
+
// Step 1: Quote acquisition
|
|
127
|
+
const quote = await jupiter.getQuote({
|
|
128
|
+
inputMint: 'So11111111111111111111111111111111111111112', // SOL
|
|
129
|
+
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
|
|
130
|
+
amount: 1_000_000_000, // 1 SOL (9 decimals)
|
|
131
|
+
slippageBps: 50, // 0.5% slippage tolerance
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Step 2: Transaction construction
|
|
135
|
+
const wallet = Keypair.fromSecretKey(/* your secret key */);
|
|
136
|
+
|
|
137
|
+
const result = await jupiter.executeSwap(
|
|
138
|
+
{
|
|
139
|
+
inputMint: 'So11111111111111111111111111111111111111112',
|
|
140
|
+
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
141
|
+
amount: 1_000_000_000,
|
|
142
|
+
slippageBps: 50,
|
|
143
|
+
},
|
|
144
|
+
wallet.publicKey.toBase58(),
|
|
145
|
+
{
|
|
146
|
+
signTransaction: async (tx: VersionedTransaction) => {
|
|
147
|
+
tx.sign([wallet]);
|
|
148
|
+
return tx;
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
console.log('Transaction signature:', result.signature);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### Quote Response Structure
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
interface JupiterQuoteResponse {
|
|
160
|
+
inputMint: string;
|
|
161
|
+
inAmount: string;
|
|
162
|
+
outputMint: string;
|
|
163
|
+
outAmount: string;
|
|
164
|
+
otherAmountThreshold: string;
|
|
165
|
+
swapMode: string;
|
|
166
|
+
slippageBps: number;
|
|
167
|
+
priceImpactPct: string; // Price impact percentage
|
|
168
|
+
routePlan: Array<{ // Multi-hop route details
|
|
169
|
+
swapInfo: {
|
|
170
|
+
ammKey: string;
|
|
171
|
+
label: string;
|
|
172
|
+
inputMint: string;
|
|
173
|
+
outputMint: string;
|
|
174
|
+
inAmount: string;
|
|
175
|
+
outAmount: string;
|
|
176
|
+
feeAmount: string;
|
|
177
|
+
feeMint: string;
|
|
178
|
+
};
|
|
179
|
+
}>;
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### 2. Jito Block Engine Integration
|
|
186
|
+
|
|
187
|
+
#### Regional Endpoints
|
|
188
|
+
|
|
189
|
+
| Region | Tip Account | Latency (ms) | Recommended For |
|
|
190
|
+
|--------|-------------|--------------|-----------------|
|
|
191
|
+
| **Mainnet** | `96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5` | ~50 | Global fallback |
|
|
192
|
+
| **New York** | `HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe` | ~10 | US East Coast |
|
|
193
|
+
| **Amsterdam** | `Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY` | ~15 | Europe |
|
|
194
|
+
| **Frankfurt** | `ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49` | ~15 | Central Europe |
|
|
195
|
+
| **Tokyo** | `DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh` | ~20 | Asia-Pacific |
|
|
196
|
+
|
|
197
|
+
#### Bundle Submission Protocol
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { JitoIntegration } from '@synapse/client-sdk/defi';
|
|
201
|
+
import { SystemProgram, Transaction, Keypair } from '@solana/web3.js';
|
|
202
|
+
|
|
203
|
+
const jito = new JitoIntegration(client);
|
|
204
|
+
|
|
205
|
+
// Region-based tip account selection
|
|
206
|
+
const tipAccount = jito.getTipAccount('ny'); // Optimal for US East
|
|
207
|
+
|
|
208
|
+
// Transaction construction with tip
|
|
209
|
+
const wallet = Keypair.fromSecretKey(/* your secret key */);
|
|
210
|
+
const tx = new Transaction();
|
|
211
|
+
|
|
212
|
+
// Add swap instructions
|
|
213
|
+
// tx.add(...);
|
|
214
|
+
|
|
215
|
+
// Append Jito tip instruction
|
|
216
|
+
const tipInstruction = jito.createTipInstruction(
|
|
217
|
+
wallet.publicKey,
|
|
218
|
+
1_000_000, // 0.001 SOL tip
|
|
219
|
+
tipAccount
|
|
220
|
+
);
|
|
221
|
+
tx.add(tipInstruction);
|
|
222
|
+
|
|
223
|
+
// Serialize and submit bundle
|
|
224
|
+
const serializedTx = tx.serialize().toString('base64');
|
|
225
|
+
|
|
226
|
+
const bundle = await jito.submitBundle({
|
|
227
|
+
transactions: [serializedTx],
|
|
228
|
+
tipLamports: 1_000_000,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
console.log('Bundle ID:', bundle.bundleId);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Bundle Status Monitoring
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// Asynchronous status polling
|
|
238
|
+
const status = await jito.getBundleStatus(bundle.bundleId);
|
|
239
|
+
|
|
240
|
+
console.log('Bundle State:', {
|
|
241
|
+
bundleId: status.bundleId,
|
|
242
|
+
status: status.status, // 'pending' | 'processing' | 'landed' | 'failed'
|
|
243
|
+
slot: status.slot,
|
|
244
|
+
confirmations: status.confirmations,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// Automated confirmation waiting
|
|
248
|
+
try {
|
|
249
|
+
await jito.waitForBundleConfirmation(bundle.bundleId, {
|
|
250
|
+
maxWaitTime: 60000, // 60 seconds
|
|
251
|
+
pollingInterval: 2000, // 2 seconds
|
|
252
|
+
});
|
|
253
|
+
console.log('Bundle confirmed');
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error('Bundle failed or timeout');
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### 3. Token Data Integration
|
|
262
|
+
|
|
263
|
+
#### SPL Token Account Structure
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
interface TokenAccountInfo {
|
|
267
|
+
pubkey: string; // Token account address
|
|
268
|
+
mint: string; // Token mint address
|
|
269
|
+
owner: string; // Owner wallet address
|
|
270
|
+
amount: string; // Raw amount (smallest unit)
|
|
271
|
+
decimals: number; // Token decimals
|
|
272
|
+
uiAmount: number; // Human-readable amount
|
|
273
|
+
delegate?: string; // Delegate authority (optional)
|
|
274
|
+
delegatedAmount?: string; // Delegated amount (optional)
|
|
275
|
+
isNative: boolean; // Native SOL wrapper flag
|
|
276
|
+
rentExemptReserve?: string; // Rent reserve amount
|
|
277
|
+
closeAuthority?: string; // Close authority (optional)
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
#### Implementation
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import { TokenDataIntegration } from '@synapse/client-sdk/defi';
|
|
285
|
+
|
|
286
|
+
const tokenData = new TokenDataIntegration(client);
|
|
287
|
+
|
|
288
|
+
// Query all SPL token accounts
|
|
289
|
+
const tokens = await tokenData.getTokenAccountsByOwner(
|
|
290
|
+
'YourWalletAddressHere'
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
console.log(`Total token accounts: ${tokens.length}`);
|
|
294
|
+
|
|
295
|
+
// Process token holdings
|
|
296
|
+
tokens.forEach(token => {
|
|
297
|
+
console.log(`Mint: ${token.mint}`);
|
|
298
|
+
console.log(`Balance: ${token.uiAmount} (${token.amount} raw)`);
|
|
299
|
+
console.log(`Decimals: ${token.decimals}`);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// Query SOL balance (lamports → SOL conversion)
|
|
303
|
+
const balance = await tokenData.getBalance('YourWalletAddressHere');
|
|
304
|
+
console.log(`SOL Balance: ${balance} SOL`);
|
|
305
|
+
|
|
306
|
+
// Token supply information
|
|
307
|
+
const supply = await tokenData.getTokenSupply(
|
|
308
|
+
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' // USDC
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
console.log('Token Supply:', {
|
|
312
|
+
amount: supply.amount,
|
|
313
|
+
decimals: supply.decimals,
|
|
314
|
+
uiAmount: supply.uiAmount,
|
|
315
|
+
uiAmountString: supply.uiAmountString,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// Largest token holders
|
|
319
|
+
const largestAccounts = await tokenData.getTokenLargestAccounts(
|
|
320
|
+
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
321
|
+
20 // Top 20 holders
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
console.log('Top Holders:', largestAccounts.map(acc => ({
|
|
325
|
+
address: acc.address,
|
|
326
|
+
uiAmount: acc.uiAmount,
|
|
327
|
+
})));
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
### 4. Price Feed Aggregation
|
|
333
|
+
|
|
334
|
+
#### Multi-Source Architecture
|
|
335
|
+
|
|
336
|
+
```
|
|
337
|
+
┌─────────────────────────────────────────────┐
|
|
338
|
+
│ Price Feed Aggregation Layer │
|
|
339
|
+
├─────────────────────────────────────────────┤
|
|
340
|
+
│ │
|
|
341
|
+
│ ┌──────────────┐ ┌──────────────┐ │
|
|
342
|
+
│ │ Jupiter │ │ Birdeye │ │
|
|
343
|
+
│ │ Price API │ │ API v3 │ │
|
|
344
|
+
│ └──────────────┘ └──────────────┘ │
|
|
345
|
+
│ │ │ │
|
|
346
|
+
│ └──────────┬───────────┘ │
|
|
347
|
+
│ │ │
|
|
348
|
+
│ ┌───────▼────────┐ │
|
|
349
|
+
│ │ Median Calc. │ │
|
|
350
|
+
│ │ Outlier Filter │ │
|
|
351
|
+
│ └───────┬────────┘ │
|
|
352
|
+
│ │ │
|
|
353
|
+
│ ┌───────▼────────┐ │
|
|
354
|
+
│ │ Aggregated │ │
|
|
355
|
+
│ │ Price Output │ │
|
|
356
|
+
│ └────────────────┘ │
|
|
357
|
+
└─────────────────────────────────────────────┘
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### Implementation
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import { PriceFeedIntegration } from '@synapse/client-sdk/defi';
|
|
364
|
+
|
|
365
|
+
const priceFeed = new PriceFeedIntegration(client);
|
|
366
|
+
|
|
367
|
+
// Jupiter batch price query
|
|
368
|
+
const prices = await priceFeed.getJupiterPrices([
|
|
369
|
+
'So11111111111111111111111111111111111111112', // SOL
|
|
370
|
+
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
|
|
371
|
+
'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', // USDT
|
|
372
|
+
]);
|
|
373
|
+
|
|
374
|
+
prices.forEach((priceData, mint) => {
|
|
375
|
+
console.log(`${priceData.symbol}: $${priceData.price}`);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// Multi-source aggregation with median calculation
|
|
379
|
+
const solPrice = await priceFeed.getAggregatedPrice(
|
|
380
|
+
'So11111111111111111111111111111111111111112',
|
|
381
|
+
['jupiter', 'birdeye'] // Redundancy for accuracy
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
console.log('Aggregated Price Data:', {
|
|
385
|
+
price: solPrice.price,
|
|
386
|
+
sources: solPrice.sources,
|
|
387
|
+
confidence: solPrice.confidence,
|
|
388
|
+
timestamp: solPrice.timestamp,
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Real-time price streaming
|
|
392
|
+
priceFeed.startPriceStream(
|
|
393
|
+
['So11111111111111111111111111111111111111112'],
|
|
394
|
+
(updates) => {
|
|
395
|
+
updates.forEach(update => {
|
|
396
|
+
console.log(`${update.mint}: $${update.price}`);
|
|
397
|
+
});
|
|
398
|
+
},
|
|
399
|
+
5000 // 5-second polling interval
|
|
400
|
+
);
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
### 5. MEV Protection Engine
|
|
406
|
+
|
|
407
|
+
#### Protection Strategies
|
|
408
|
+
|
|
409
|
+
| Strategy | Method | Effectiveness | Gas Overhead |
|
|
410
|
+
|----------|--------|---------------|--------------|
|
|
411
|
+
| **Jito Bundles** | Private mempool | 95% | +0.001 SOL tip |
|
|
412
|
+
| **Transaction Simulation** | Pre-flight check | 70% | Negligible |
|
|
413
|
+
| **Slippage Optimization** | Dynamic adjustment | 60% | None |
|
|
414
|
+
| **Priority Fees** | Fee market bidding | 40% | Variable |
|
|
415
|
+
|
|
416
|
+
#### Configuration
|
|
417
|
+
|
|
418
|
+
#### Configuration
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
import { MEVProtection } from '@synapse/client-sdk/defi';
|
|
422
|
+
|
|
423
|
+
const mevProtection = new MEVProtection({
|
|
424
|
+
enableJitoBundle: true,
|
|
425
|
+
jitoBlockEngineUrl: 'https://mainnet.block-engine.jito.wtf',
|
|
426
|
+
maxTipLamports: 10_000_000, // 0.01 SOL maximum tip
|
|
427
|
+
enableSimulation: true,
|
|
428
|
+
slippageBps: 50, // 0.5% slippage tolerance
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// Transaction protection workflow
|
|
432
|
+
const txBase64 = '...'; // Serialized transaction (base64)
|
|
433
|
+
|
|
434
|
+
const result = await mevProtection.protectSwap(txBase64, {
|
|
435
|
+
tipLamports: 1_000_000, // 0.001 SOL tip
|
|
436
|
+
skipSimulation: false,
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
console.log('Protection Result:', {
|
|
440
|
+
protected: result.protected,
|
|
441
|
+
bundleId: result.bundleId,
|
|
442
|
+
estimatedMEVSaved: result.estimatedMEVSaved,
|
|
443
|
+
simulation: result.simulation,
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// Risk assessment
|
|
447
|
+
const risk = await mevProtection.estimateMEVRisk(
|
|
448
|
+
'So11111111111111111111111111111111111111112', // Input mint (SOL)
|
|
449
|
+
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // Output mint (USDC)
|
|
450
|
+
1_000_000_000 // Amount (1 SOL)
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
console.log('MEV Risk Assessment:', {
|
|
454
|
+
risk: risk.risk, // 'low' | 'medium' | 'high'
|
|
455
|
+
estimatedLoss: risk.estimatedLoss,
|
|
456
|
+
recommendation: risk.recommendation,
|
|
457
|
+
});
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
### 6. Arbitrage Detection
|
|
463
|
+
|
|
464
|
+
#### Detection Algorithm
|
|
465
|
+
|
|
466
|
+
```
|
|
467
|
+
1. Fetch prices from multiple DEXes (Jupiter, Raydium, Orca)
|
|
468
|
+
2. Calculate cross-DEX price differences
|
|
469
|
+
3. Identify profitable arbitrage paths (up to N hops)
|
|
470
|
+
4. Estimate gas costs and net profit
|
|
471
|
+
5. Filter by minimum profit threshold
|
|
472
|
+
6. Return ranked opportunities by profitability
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
#### Implementation
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
import { ArbitrageDetector } from '@synapse/client-sdk/defi';
|
|
479
|
+
|
|
480
|
+
const arbDetector = new ArbitrageDetector(client);
|
|
481
|
+
|
|
482
|
+
// Opportunity discovery
|
|
483
|
+
const opportunities = await arbDetector.findOpportunities({
|
|
484
|
+
minProfitPercent: 1.0, // Minimum 1% profit after gas
|
|
485
|
+
maxHops: 3, // Maximum path complexity
|
|
486
|
+
tokens: ['SOL', 'USDC', 'USDT'], // Token whitelist
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
console.log('Arbitrage Opportunities:', opportunities);
|
|
490
|
+
|
|
491
|
+
// Continuous scanning with event-driven architecture
|
|
492
|
+
arbDetector.on('arbitrage-found', (opportunities) => {
|
|
493
|
+
opportunities.forEach(opp => {
|
|
494
|
+
console.log(`Arbitrage Path: ${opp.path.join(' → ')}`);
|
|
495
|
+
console.log(`Profit: ${opp.netProfit} (${opp.profitPercent}%)`);
|
|
496
|
+
console.log(`Exchanges: ${opp.exchanges.join(' → ')}`);
|
|
497
|
+
console.log(`Confidence: ${(opp.confidence * 100).toFixed(1)}%`);
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
arbDetector.startScanning(30000); // 30-second interval
|
|
502
|
+
|
|
503
|
+
// Cleanup
|
|
504
|
+
process.on('SIGINT', () => {
|
|
505
|
+
arbDetector.stopScanning();
|
|
506
|
+
});
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
### 7. Portfolio Analytics
|
|
512
|
+
|
|
513
|
+
#### Metrics Calculation
|
|
514
|
+
|
|
515
|
+
| Metric | Formula | Range |
|
|
516
|
+
|--------|---------|-------|
|
|
517
|
+
| **Risk Score** | `concentration_risk + count_risk` | 0-100 |
|
|
518
|
+
| **Diversification** | `(count_score × 0.7) + (spread_score × 0.3)` | 0-100 |
|
|
519
|
+
| **PnL** | `current_value - initial_value` | -∞ to +∞ |
|
|
520
|
+
|
|
521
|
+
#### Implementation
|
|
522
|
+
|
|
523
|
+
```typescript
|
|
524
|
+
import { PortfolioAnalytics } from '@synapse/client-sdk/defi';
|
|
525
|
+
|
|
526
|
+
const portfolio = new PortfolioAnalytics(client);
|
|
527
|
+
|
|
528
|
+
// Comprehensive wallet analysis
|
|
529
|
+
const metrics = await portfolio.analyzeWallet('YourWalletAddressHere');
|
|
530
|
+
|
|
531
|
+
console.log('Portfolio Overview:', {
|
|
532
|
+
totalValue: `$${metrics.totalValue.toLocaleString()}`,
|
|
533
|
+
holdingsCount: metrics.holdings.length,
|
|
534
|
+
riskScore: `${metrics.riskScore}/100`,
|
|
535
|
+
diversificationScore: `${metrics.diversificationScore}/100`,
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
console.log('\nPerformance Metrics:');
|
|
539
|
+
console.log(`24h PnL: ${metrics.pnl24h >= 0 ? '+' : ''}$${metrics.pnl24h}`);
|
|
540
|
+
console.log(`7d PnL: ${metrics.pnl7d >= 0 ? '+' : ''}$${metrics.pnl7d}`);
|
|
541
|
+
console.log(`30d PnL: ${metrics.pnl30d >= 0 ? '+' : ''}$${metrics.pnl30d}`);
|
|
542
|
+
|
|
543
|
+
console.log('\nTop Holdings:');
|
|
544
|
+
metrics.topPerformers.forEach((holding, index) => {
|
|
545
|
+
console.log(`${index + 1}. ${holding.symbol || holding.mint.slice(0, 8)}`);
|
|
546
|
+
console.log(` Value: $${holding.usdValue.toFixed(2)}`);
|
|
547
|
+
console.log(` Allocation: ${holding.allocation.toFixed(2)}%`);
|
|
548
|
+
console.log(` 24h Change: ${holding.change24h}%`);
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
console.log('\nRecommendations:');
|
|
552
|
+
metrics.recommendations.forEach((rec, index) => {
|
|
553
|
+
console.log(`${index + 1}. ${rec}`);
|
|
554
|
+
});
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
---
|
|
558
|
+
|
|
559
|
+
### 8. Flash Loan Simulator
|
|
560
|
+
|
|
561
|
+
#### Simulation Engine
|
|
562
|
+
|
|
563
|
+
```
|
|
564
|
+
┌──────────────────────────────────────────┐
|
|
565
|
+
│ Flash Loan Simulation Engine │
|
|
566
|
+
├──────────────────────────────────────────┤
|
|
567
|
+
│ │
|
|
568
|
+
│ 1. Loan Acquisition (virtual) │
|
|
569
|
+
│ 2. Execute Action Chain: │
|
|
570
|
+
│ • Swap on DEX A │
|
|
571
|
+
│ • Arbitrage on DEX B │
|
|
572
|
+
│ • Liquidation (if applicable) │
|
|
573
|
+
│ 3. Loan Repayment + Fee (0.09%) │
|
|
574
|
+
│ 4. Calculate Net Profit/Loss │
|
|
575
|
+
│ 5. Generate Execution Log │
|
|
576
|
+
│ │
|
|
577
|
+
└──────────────────────────────────────────┘
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
#### Implementation
|
|
581
|
+
|
|
582
|
+
```typescript
|
|
583
|
+
import { FlashLoanSimulator } from '@synapse/client-sdk/defi';
|
|
584
|
+
|
|
585
|
+
const flashLoan = new FlashLoanSimulator(client);
|
|
586
|
+
|
|
587
|
+
// Arbitrage simulation
|
|
588
|
+
const simulation = await flashLoan.simulate({
|
|
589
|
+
loanAmount: 100_000, // 100k USDC loan
|
|
590
|
+
tokenMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
591
|
+
actions: [
|
|
592
|
+
{
|
|
593
|
+
type: 'swap',
|
|
594
|
+
description: 'Buy SOL on Jupiter (lower price)',
|
|
595
|
+
inputAmount: 100_000,
|
|
596
|
+
outputAmount: 500, // 500 SOL
|
|
597
|
+
exchange: 'Jupiter',
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
type: 'swap',
|
|
601
|
+
description: 'Sell SOL on Raydium (higher price)',
|
|
602
|
+
inputAmount: 500,
|
|
603
|
+
outputAmount: 102_000, // 102k USDC
|
|
604
|
+
exchange: 'Raydium',
|
|
605
|
+
},
|
|
606
|
+
],
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
console.log('Simulation Result:', {
|
|
610
|
+
success: simulation.success,
|
|
611
|
+
loanAmount: simulation.loanAmount,
|
|
612
|
+
finalAmount: simulation.loanAmount + simulation.netProfit,
|
|
613
|
+
estimatedProfit: simulation.estimatedProfit,
|
|
614
|
+
estimatedCost: simulation.estimatedCost,
|
|
615
|
+
netProfit: simulation.netProfit,
|
|
616
|
+
roi: ((simulation.netProfit / simulation.loanAmount) * 100).toFixed(2) + '%',
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
console.log('\nExecution Log:');
|
|
620
|
+
simulation.logs.forEach((log, index) => {
|
|
621
|
+
console.log(`${index + 1}. ${log}`);
|
|
622
|
+
});
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
### 9. Yield Farming Finder
|
|
628
|
+
|
|
629
|
+
#### Protocol Coverage
|
|
630
|
+
|
|
631
|
+
| Protocol | TVL | APY Range | Integration Status |
|
|
632
|
+
|----------|-----|-----------|-------------------|
|
|
633
|
+
| Marinade | $1.5B | 5-10% | Active |
|
|
634
|
+
| Orca | $500M | 10-50% | Active |
|
|
635
|
+
| Raydium | $300M | 15-80% | Active |
|
|
636
|
+
| Kamino | $200M | 20-100% | Planned |
|
|
637
|
+
| Drift | $150M | 10-60% | Planned |
|
|
638
|
+
|
|
639
|
+
#### Implementation
|
|
640
|
+
|
|
641
|
+
```typescript
|
|
642
|
+
import { YieldFarmingFinder } from '@synapse/client-sdk/defi';
|
|
643
|
+
|
|
644
|
+
const yieldFinder = new YieldFarmingFinder(client);
|
|
645
|
+
|
|
646
|
+
// Discover high-yield opportunities
|
|
647
|
+
const opportunities = await yieldFinder.findOpportunities({
|
|
648
|
+
minAPY: 15, // Minimum 15% annual percentage yield
|
|
649
|
+
maxRisk: 'medium', // Risk tolerance: 'low' | 'medium' | 'high'
|
|
650
|
+
protocols: ['Marinade', 'Orca', 'Raydium'], // Protocol filter
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
console.log(`Found ${opportunities.length} yield opportunities`);
|
|
654
|
+
|
|
655
|
+
// Display results in tabular format
|
|
656
|
+
console.table(opportunities.map(opp => ({
|
|
657
|
+
Protocol: opp.protocol,
|
|
658
|
+
Pool: opp.pool,
|
|
659
|
+
APY: `${opp.apy.toFixed(2)}%`,
|
|
660
|
+
TVL: `$${(opp.tvl / 1_000_000).toFixed(1)}M`,
|
|
661
|
+
Tokens: opp.tokens.join('/'),
|
|
662
|
+
Risk: opp.risk.toUpperCase(),
|
|
663
|
+
})));
|
|
664
|
+
|
|
665
|
+
// Detailed opportunity analysis
|
|
666
|
+
opportunities.forEach(opp => {
|
|
667
|
+
console.log(`\n${opp.protocol} - ${opp.pool}`);
|
|
668
|
+
console.log(` APY: ${opp.apy}%`);
|
|
669
|
+
console.log(` TVL: $${opp.tvl.toLocaleString()}`);
|
|
670
|
+
console.log(` Tokens: ${opp.tokens.join(' + ')}`);
|
|
671
|
+
console.log(` Risk Level: ${opp.risk}`);
|
|
672
|
+
console.log(` URL: ${opp.url}`);
|
|
673
|
+
});
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
---
|
|
677
|
+
|
|
678
|
+
## Event-Driven Architecture
|
|
679
|
+
|
|
680
|
+
All integration modules extend `EventEmitter` for real-time monitoring and observability.
|
|
681
|
+
|
|
682
|
+
### Event Types by Module
|
|
683
|
+
|
|
684
|
+
| Module | Events | Payload |
|
|
685
|
+
|--------|--------|---------|
|
|
686
|
+
| **Jupiter** | `jupiter-quote-start`, `jupiter-quote-complete`, `jupiter-quote-error` | Quote params/result |
|
|
687
|
+
| **Jito** | `jito-bundle-submit`, `jito-bundle-submitted`, `jito-bundle-error` | Bundle data |
|
|
688
|
+
| **TokenData** | `token-accounts-fetch-start`, `token-accounts-fetch-complete`, `token-accounts-fetch-error` | Account data |
|
|
689
|
+
| **PriceFeed** | `price-update`, `price-source-error` | Price data |
|
|
690
|
+
| **MEVProtection** | `mev-protection-start`, `mev-protection-complete`, `mev-protection-error` | Protection result |
|
|
691
|
+
| **ArbitrageDetector** | `arbitrage-scan-start`, `arbitrage-found`, `scanning-started`, `scanning-stopped` | Opportunities |
|
|
692
|
+
|
|
693
|
+
### Event Listener Implementation
|
|
694
|
+
|
|
695
|
+
```typescript
|
|
696
|
+
// Jupiter quote monitoring
|
|
697
|
+
jupiter.on('jupiter-quote-start', (params) => {
|
|
698
|
+
console.log('[Jupiter] Quote request:', params);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
jupiter.on('jupiter-quote-complete', (result) => {
|
|
702
|
+
console.log('[Jupiter] Quote received:', {
|
|
703
|
+
route: result.routePlan.length + ' hops',
|
|
704
|
+
priceImpact: result.priceImpactPct,
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
jupiter.on('jupiter-quote-error', (error) => {
|
|
709
|
+
console.error('[Jupiter] Quote failed:', error.message);
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
// Jito bundle tracking
|
|
713
|
+
jito.on('jito-bundle-submitted', (result) => {
|
|
714
|
+
console.log('[Jito] Bundle ID:', result.bundleId);
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
// Token account monitoring
|
|
718
|
+
tokenData.on('token-accounts-fetch-complete', (data) => {
|
|
719
|
+
console.log(`[TokenData] Fetched ${data.count} token accounts`);
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// Price feed updates
|
|
723
|
+
priceFeed.on('price-update', (update) => {
|
|
724
|
+
console.log(`[PriceFeed] ${update.symbol}: $${update.price}`);
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
// MEV protection events
|
|
728
|
+
mevProtection.on('mev-protection-complete', (result) => {
|
|
729
|
+
if (result.protected) {
|
|
730
|
+
console.log('[MEV] Transaction protected via Jito bundle');
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
---
|
|
736
|
+
|
|
737
|
+
## Error Handling
|
|
738
|
+
|
|
739
|
+
### DeFiError Type System
|
|
740
|
+
|
|
741
|
+
```typescript
|
|
742
|
+
class DeFiError extends Error {
|
|
743
|
+
constructor(
|
|
744
|
+
message: string,
|
|
745
|
+
public operation: string, // 'quote' | 'swap' | 'bundle' | etc.
|
|
746
|
+
public provider?: string, // 'jupiter' | 'jito' | etc.
|
|
747
|
+
public originalError?: Error // Underlying error
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
### Error Handling Pattern
|
|
753
|
+
|
|
754
|
+
```typescript
|
|
755
|
+
import { DeFiError } from '@synapse/client-sdk';
|
|
756
|
+
|
|
757
|
+
try {
|
|
758
|
+
const quote = await jupiter.getQuote(params);
|
|
759
|
+
} catch (error) {
|
|
760
|
+
if (error instanceof DeFiError) {
|
|
761
|
+
console.error('DeFi Operation Failed:', {
|
|
762
|
+
operation: error.operation,
|
|
763
|
+
provider: error.provider,
|
|
764
|
+
message: error.message,
|
|
765
|
+
originalError: error.originalError?.message,
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
// Operation-specific error handling
|
|
769
|
+
switch (error.operation) {
|
|
770
|
+
case 'quote':
|
|
771
|
+
// Handle quote failure (retry, fallback DEX, etc.)
|
|
772
|
+
break;
|
|
773
|
+
case 'swap':
|
|
774
|
+
// Handle swap failure (refund, revert, etc.)
|
|
775
|
+
break;
|
|
776
|
+
case 'bundle':
|
|
777
|
+
// Handle bundle failure (standard tx submission, etc.)
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
} else {
|
|
781
|
+
console.error('Unexpected error:', error);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
---
|
|
787
|
+
|
|
788
|
+
## Best Practices
|
|
789
|
+
|
|
790
|
+
### 1. MEV Protection Threshold
|
|
791
|
+
|
|
792
|
+
```typescript
|
|
793
|
+
// Apply MEV protection for transactions above threshold
|
|
794
|
+
const PROTECTION_THRESHOLD = 1_000_000_000; // 1 SOL
|
|
795
|
+
|
|
796
|
+
async function executeSwap(params) {
|
|
797
|
+
const quote = await jupiter.getQuote(params);
|
|
798
|
+
|
|
799
|
+
if (params.amount > PROTECTION_THRESHOLD) {
|
|
800
|
+
// Use Jito bundle for large swaps
|
|
801
|
+
const tx = await jupiter.getSwapTransaction(params, userAddress);
|
|
802
|
+
const result = await mevProtection.protectSwap(tx.swapTransaction);
|
|
803
|
+
return result;
|
|
804
|
+
} else {
|
|
805
|
+
// Standard execution for small swaps
|
|
806
|
+
return await jupiter.executeSwap(params, userAddress, signer);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
### 2. Price Impact Validation
|
|
812
|
+
|
|
813
|
+
```typescript
|
|
814
|
+
const MAX_PRICE_IMPACT = 5.0; // 5% maximum acceptable impact
|
|
815
|
+
|
|
816
|
+
const quote = await jupiter.getQuote(params);
|
|
817
|
+
|
|
818
|
+
if (parseFloat(quote.priceImpactPct) > MAX_PRICE_IMPACT) {
|
|
819
|
+
throw new Error(`Price impact too high: ${quote.priceImpactPct}%`);
|
|
820
|
+
}
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
### 3. Multi-Source Price Validation
|
|
824
|
+
|
|
825
|
+
```typescript
|
|
826
|
+
async function getValidatedPrice(mint: string): Promise<number> {
|
|
827
|
+
const sources: ('jupiter' | 'birdeye')[] = ['jupiter', 'birdeye'];
|
|
828
|
+
const aggregated = await priceFeed.getAggregatedPrice(mint, sources);
|
|
829
|
+
|
|
830
|
+
// Require minimum confidence threshold
|
|
831
|
+
if (aggregated.confidence < 0.8) {
|
|
832
|
+
throw new Error('Price confidence too low');
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
return aggregated.price;
|
|
836
|
+
}
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
### 4. Bundle Status Monitoring
|
|
840
|
+
|
|
841
|
+
```typescript
|
|
842
|
+
async function submitWithConfirmation(bundle: JitoBundle) {
|
|
843
|
+
const result = await jito.submitBundle(bundle);
|
|
844
|
+
|
|
845
|
+
// Poll for confirmation with exponential backoff
|
|
846
|
+
const confirmed = await jito.waitForBundleConfirmation(
|
|
847
|
+
result.bundleId,
|
|
848
|
+
{
|
|
849
|
+
maxWaitTime: 60000, // 60 seconds timeout
|
|
850
|
+
pollingInterval: 2000, // Initial 2-second interval
|
|
851
|
+
}
|
|
852
|
+
);
|
|
853
|
+
|
|
854
|
+
if (!confirmed) {
|
|
855
|
+
// Fallback to standard transaction submission
|
|
856
|
+
console.warn('Bundle failed, falling back to standard tx');
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
return confirmed;
|
|
860
|
+
}
|
|
861
|
+
```
|
|
862
|
+
|
|
863
|
+
### 5. Rate Limit Handling
|
|
864
|
+
|
|
865
|
+
```typescript
|
|
866
|
+
async function fetchWithRetry<T>(
|
|
867
|
+
fetchFn: () => Promise<T>,
|
|
868
|
+
maxRetries: number = 3,
|
|
869
|
+
baseDelay: number = 1000
|
|
870
|
+
): Promise<T> {
|
|
871
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
872
|
+
try {
|
|
873
|
+
return await fetchFn();
|
|
874
|
+
} catch (error) {
|
|
875
|
+
if (attempt === maxRetries - 1) throw error;
|
|
876
|
+
|
|
877
|
+
// Exponential backoff
|
|
878
|
+
const delay = baseDelay * Math.pow(2, attempt);
|
|
879
|
+
console.log(`Retry ${attempt + 1}/${maxRetries} after ${delay}ms`);
|
|
880
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
throw new Error('Max retries exceeded');
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// Usage
|
|
888
|
+
const prices = await fetchWithRetry(() =>
|
|
889
|
+
priceFeed.getJupiterPrices(mints)
|
|
890
|
+
);
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
---
|
|
894
|
+
|
|
895
|
+
## Performance Optimization
|
|
896
|
+
|
|
897
|
+
### Batch Operations
|
|
898
|
+
|
|
899
|
+
```typescript
|
|
900
|
+
// Inefficient: Multiple sequential calls
|
|
901
|
+
for (const mint of mints) {
|
|
902
|
+
const price = await priceFeed.getJupiterPrices([mint]);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// Efficient: Single batch call
|
|
906
|
+
const prices = await priceFeed.getJupiterPrices(mints);
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
### Connection Pooling
|
|
910
|
+
|
|
911
|
+
```typescript
|
|
912
|
+
// Reuse client instance across operations
|
|
913
|
+
const client = new SynapseClient({ endpoint, apiKey });
|
|
914
|
+
|
|
915
|
+
const jupiter = new JupiterIntegration(client);
|
|
916
|
+
const jito = new JitoIntegration(client);
|
|
917
|
+
const tokenData = new TokenDataIntegration(client);
|
|
918
|
+
const priceFeed = new PriceFeedIntegration(client);
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
### Caching Strategy
|
|
922
|
+
|
|
923
|
+
```typescript
|
|
924
|
+
class PriceCache {
|
|
925
|
+
private cache = new Map<string, { price: number; timestamp: number }>();
|
|
926
|
+
private TTL = 30000; // 30 seconds
|
|
927
|
+
|
|
928
|
+
async getPrice(mint: string, fetcher: () => Promise<number>): Promise<number> {
|
|
929
|
+
const cached = this.cache.get(mint);
|
|
930
|
+
|
|
931
|
+
if (cached && Date.now() - cached.timestamp < this.TTL) {
|
|
932
|
+
return cached.price;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const price = await fetcher();
|
|
936
|
+
this.cache.set(mint, { price, timestamp: Date.now() });
|
|
937
|
+
|
|
938
|
+
return price;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
---
|
|
944
|
+
|
|
945
|
+
## API Reference
|
|
946
|
+
|
|
947
|
+
### Type Exports
|
|
948
|
+
|
|
949
|
+
```typescript
|
|
950
|
+
export {
|
|
951
|
+
// Jupiter types
|
|
952
|
+
JupiterQuoteParams,
|
|
953
|
+
JupiterQuoteResponse,
|
|
954
|
+
JupiterSwapRequest,
|
|
955
|
+
JupiterSwapResult,
|
|
956
|
+
|
|
957
|
+
// Jito types
|
|
958
|
+
JitoBundle,
|
|
959
|
+
JitoBundleStatus,
|
|
960
|
+
JitoBundleResult,
|
|
961
|
+
|
|
962
|
+
// Token types
|
|
963
|
+
TokenAccountInfo,
|
|
964
|
+
TokenSupply,
|
|
965
|
+
TokenLargestAccount,
|
|
966
|
+
|
|
967
|
+
// Price types
|
|
968
|
+
PriceData,
|
|
969
|
+
AggregatedPrice,
|
|
970
|
+
|
|
971
|
+
// Advanced feature types
|
|
972
|
+
MEVProtectionConfig,
|
|
973
|
+
MEVProtectionResult,
|
|
974
|
+
ArbitrageOpportunity,
|
|
975
|
+
PortfolioMetrics,
|
|
976
|
+
FlashLoanSimulation,
|
|
977
|
+
YieldOpportunity,
|
|
978
|
+
};
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
### Class Exports
|
|
982
|
+
|
|
983
|
+
```typescript
|
|
984
|
+
export {
|
|
985
|
+
// Core integrations
|
|
986
|
+
JupiterIntegration,
|
|
987
|
+
JitoIntegration,
|
|
988
|
+
TokenDataIntegration,
|
|
989
|
+
PriceFeedIntegration,
|
|
990
|
+
|
|
991
|
+
// Advanced features
|
|
992
|
+
MEVProtection,
|
|
993
|
+
ArbitrageDetector,
|
|
994
|
+
PortfolioAnalytics,
|
|
995
|
+
FlashLoanSimulator,
|
|
996
|
+
YieldFarmingFinder,
|
|
997
|
+
|
|
998
|
+
// Errors
|
|
999
|
+
DeFiError,
|
|
1000
|
+
};
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
---
|
|
1004
|
+
|
|
1005
|
+
## System Requirements
|
|
1006
|
+
|
|
1007
|
+
### Dependencies
|
|
1008
|
+
|
|
1009
|
+
| Package | Version | Purpose |
|
|
1010
|
+
|---------|---------|---------|
|
|
1011
|
+
| `@solana/web3.js` | `^1.87.0` | Solana blockchain interaction |
|
|
1012
|
+
| `eventemitter3` | `^5.0.1` | Event-driven architecture |
|
|
1013
|
+
| `@synapse/client-sdk` | `latest` | Core SDK functionality |
|
|
1014
|
+
|
|
1015
|
+
### Runtime Requirements
|
|
1016
|
+
|
|
1017
|
+
- **Node.js**: `>=18.0.0`
|
|
1018
|
+
- **TypeScript**: `>=5.0.0` (for development)
|
|
1019
|
+
- **Network**: Stable internet connection for RPC calls
|
|
1020
|
+
- **Memory**: Minimum 512MB available RAM
|
|
1021
|
+
|
|
1022
|
+
---
|
|
1023
|
+
|
|
1024
|
+
## Related Documentation
|
|
1025
|
+
|
|
1026
|
+
- [Synapse Client SDK Core Documentation](../README.md)
|
|
1027
|
+
- [Jupiter V6 API Reference](https://station.jup.ag/docs/apis/swap-api)
|
|
1028
|
+
- [Jito Block Engine Documentation](https://docs.jito.wtf/)
|
|
1029
|
+
- [Solana Web3.js Documentation](https://solana-labs.github.io/solana-web3.js/)
|
|
1030
|
+
- [SPL Token Program Specification](https://spl.solana.com/token)
|
|
1031
|
+
|
|
1032
|
+
---
|
|
1033
|
+
|
|
1034
|
+
## License
|
|
1035
|
+
|
|
1036
|
+
MIT License - See [LICENSE](../LICENSE) for complete terms.
|
|
1037
|
+
|
|
1038
|
+
---
|
|
1039
|
+
|
|
1040
|
+
## Contributing
|
|
1041
|
+
|
|
1042
|
+
Contributions are welcome. Please refer to [CONTRIBUTING.md](../CONTRIBUTING.md) for guidelines on:
|
|
1043
|
+
- Code style and conventions
|
|
1044
|
+
- Testing requirements
|
|
1045
|
+
- Pull request process
|
|
1046
|
+
- Issue reporting
|
|
1047
|
+
|
|
1048
|
+
---
|
|
1049
|
+
|
|
1050
|
+
**Synapse DeFi Module** - Production-grade Solana DeFi integration layer
|