estimate_bridge_fees
Calculate bridge transaction fees for transferring tokens between blockchain networks. Provide source and destination chain IDs with amount to estimate costs.
Instructions
Estimate fees for a bridge transaction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromChainId | Yes | Source chain ID | |
| toChainId | Yes | Destination chain ID | |
| amount | Yes | Amount to bridge | |
| tokenAddress | No | Token address (optional, defaults to USDC) |
Implementation Reference
- src/index.ts:460-476 (handler)Primary MCP tool handler for 'estimate_bridge_fees' that extracts arguments and delegates to QuoteService.estimateFees, handles errors and formats response.private async estimateBridgeFees(args: any): Promise<MCPToolResult> { try { const { fromChainId, toChainId, amount, tokenAddress } = args; const result = await this.quoteService.estimateFees( fromChainId, toChainId, amount, tokenAddress ); return createSuccessResponse(result); } catch (error) { return createErrorResponse( error instanceof Error ? error.message : String(error), 'FEE_ESTIMATION_ERROR' ); } }
- src/index.ts:291-323 (registration)Tool registration in ListTools handler, including name, description, and input schema.{ name: 'estimate_bridge_fees', description: 'Estimate fees for a bridge transaction', inputSchema: { type: 'object', properties: { fromChainId: { oneOf: [ { type: 'number' }, { type: 'string' }, ], description: 'Source chain ID', }, toChainId: { oneOf: [ { type: 'number' }, { type: 'string' }, ], description: 'Destination chain ID', }, amount: { type: 'string', description: 'Amount to bridge', }, tokenAddress: { type: 'string', description: 'Token address (optional, defaults to USDC)', }, }, required: ['fromChainId', 'toChainId', 'amount'], additionalProperties: false, }, },
- src/services/quote.ts:107-125 (handler)Core fee estimation logic called by the tool handler, computes bridge fee and gas fee, returns structured result.async estimateFees( fromChainId: SupportedChainId, toChainId: SupportedChainId, amount: string, tokenAddress?: string ): Promise<{ bridgeFee: string; gasFee: string; totalFee: string; }> { const bridgeFee = this.calculateBridgeFee(amount); const gasFee = await this.estimateGasFees(fromChainId, toChainId); return { bridgeFee, gasFee, totalFee: (BigInt(bridgeFee) + BigInt(gasFee)).toString(), }; }
- src/services/quote.ts:190-193 (helper)Helper function to calculate the bridge fee based on amount and FEE_CONFIG.BRIDGE_FEE_BPS.private calculateBridgeFee(amount: string): string { const bridgeFeeAmount = (BigInt(amount) * BigInt(FEE_CONFIG.BRIDGE_FEE_BPS)) / BigInt(10000); return bridgeFeeAmount.toString(); }
- src/services/quote.ts:195-207 (helper)Helper function to estimate gas fees based on source chain type with hardcoded values.private async estimateGasFees(fromChainId: SupportedChainId, toChainId: SupportedChainId): Promise<string> { if (isEVMChain(fromChainId)) { return ethers.utils.parseEther('0.01').toString(); // ~$20-30 on mainnet } else if (isSolanaChain(fromChainId)) { return '5000'; // ~0.000005 SOL } else if (isSuiChain(fromChainId)) { return '1000000'; // ~0.001 SUI } else if (isCosmosChain(fromChainId)) { return '5000'; // varies by chain } return '0'; }