Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BridgeWise provides cross-chain quotes, but fees can vary based on:
Network congestion
Liquidity pool depth
Gas price fluctuations (EVM)
Bridge-specific transaction costs
This issue introduces a Dynamic Fee Estimation Engine to provide accurate, real-time fee predictions per route.
Accurate fee estimates are critical for:
Smart ranking (Issue #5)
Slippage calculations (Issue #7)
Transparency for users
Reducing failed transactions due to insufficient funds
🎯 Problem
Static fee estimates are inaccurate during network congestion.
Users may be charged more than expected.
Ranking based purely on outdated fees can select suboptimal routes.
Lack of dynamic fees reduces trust in the SDK.
Without dynamic fee estimation, BridgeWise risks misleading quotes and poor UX.
💡 Proposed Solution
Build a Dynamic Fee Estimation Engine that:
Fetches real-time network fees for EVM chains
Estimates liquidity-based fees for AMM/bridge pools
Calculates total route cost including gas + bridge fees
Integrates with ranking, slippage, and status components
Exposes API and hooks for developers
🛠 Scope of Work
1️⃣ Define Fee Data Model
interface FeeEstimate {
bridgeName: string;
sourceChain: string;
destinationChain: string;
totalFee: number; // in native token
gasFee: number; // network-specific
bridgeFee: number; // provider-specific
lastUpdated: Date;
}
Include all components contributing to total cost
Normalized across chains for ranking
2️⃣ Implement Fee Fetching Logic
Fetch gas prices for EVM chains
Fetch bridge-specific fees
Estimate liquidity impact for AMM-based bridges
Update dynamically on quote requests
3️⃣ Integrate With Ranking Engine
Feed dynamic fees into Smart Bridge Ranking (Issue #5)
Ensure real-time adjustments influence route selection
Provide transparency in fee breakdown to UI components
4️⃣ Hooks and API Exposure
useFeeEstimate() hook for React developers
Optional REST endpoint for SDK integrators
Return normalized fee breakdown
SSR-compatible for Next.js
5️⃣ Error Handling & Fallbacks
Provide fallback static fee if dynamic fetch fails
Show warning for high network congestion
Ensure calculations never block UI rendering
📊 Expected Outcome
Accurate, real-time fee estimates for all routes
Improved route selection and ranking
Transparent cost breakdown for users
Reduced failed or underfunded transactions
✅ Acceptance Criteria
Fee data model implemented
Real-time EVM gas price fetching
Bridge-specific fee estimation implemented
Liquidity-based fee calculation included
Integrated with ranking engine
useFeeEstimate() hook available
SSR-safe implementation
Fallback fees provided if dynamic fetch fails
Unit tests for dynamic fee logic
Documentation updated with usage examples
📈 Measurable Impact
Reduced unexpected fees during cross-chain transfers
Increased user trust in BridgeWise quotes
Improved accuracy in Smart Bridge Ranking
Fewer failed or aborted transactions
🧪 Testing Requirements
Simulate varying network congestion
Validate fee breakdown for multiple bridges
Confirm fallback fees are correctly applied
Test hook and REST API outputs
Verify integration with ranking engine
Ensure SSR-safe behavior in Next.js
📚 Documentation Requirements
Add “Dynamic Fee Estimation” section to README
Provide usage examples with hook
Include breakdown explanation in UI
Document fallback behavior and error handling
Closes #62