- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control. - Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities. - Created .gitmodules to include OpenZeppelin contracts as a submodule. - Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment. - Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks. - Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring. - Created scripts for resource import and usage validation across non-US regions. - Added tests for CCIP error handling and integration to ensure robust functionality. - Included various new files and directories for the orchestration portal and deployment scripts.
3.7 KiB
3.7 KiB
CCIP Fees
Overview
CCIP messages require LINK tokens to pay for cross-chain message delivery. This document explains how fees are calculated and managed.
Fee Calculation
CCIP fees are calculated based on:
- Message Size: Larger messages cost more
- Target Chain: Different chains have different fee rates
- Gas Price: Current gas prices on target chain
- Token Type: Native tokens vs LINK tokens
Calculating Fees
Use the calculateFee() function to get the required fee:
CCIPSender sender = CCIPSender(senderAddress);
uint256 fee = sender.calculateFee(targetChainSelector, messageData);
Fee Payment
Fees are paid when sending the message:
sender.sendOracleUpdate{value: fee}(targetChainSelector, receiverAddress, messageData);
Fee Estimation
Typical Fees (as of 2024)
- Small message (< 100 bytes): ~0.01-0.05 LINK
- Medium message (100-500 bytes): ~0.05-0.2 LINK
- Large message (> 500 bytes): ~0.2-1.0 LINK
Note: Fees vary by chain and network conditions
Managing LINK Balance
Check Balance
IERC20 linkToken = IERC20(LINK_TOKEN_ADDRESS);
uint256 balance = linkToken.balanceOf(address(this));
Transfer LINK
# Transfer LINK to sender contract
cast send $LINK_TOKEN "transfer(address,uint256)" $SENDER_CONTRACT $AMOUNT \
--rpc-url $RPC_URL --private-key $PRIVATE_KEY
Approve Spending
IERC20 linkToken = IERC20(LINK_TOKEN_ADDRESS);
linkToken.approve(senderAddress, amount);
Fee Monitoring
Monitor fee consumption:
- Track total fees spent
- Monitor fee per message
- Alert on high fee usage
- Set fee budgets
Metrics
ccip_fees_total: Total LINK spent on feesccip_fees_per_message: Average fee per messageccip_fee_errors: Failed transactions due to insufficient fees
Cost Optimization
1. Minimize Message Size
- Use efficient encoding
- Remove unnecessary data
- Compress data when possible
2. Batch Updates
- Combine multiple updates into one message
- Reduce number of messages sent
- Lower total fee cost
3. Monitor Gas Prices
- Send during low gas price periods
- Use gas price oracles
- Schedule updates strategically
4. Use Native Tokens
- Some chains support native token payments
- May be cheaper than LINK in some cases
Fee Limits
Set maximum fee limits to prevent excessive spending:
uint256 constant MAX_FEE_PER_MESSAGE = 1 ether; // 1 LINK
require(fee <= MAX_FEE_PER_MESSAGE, "Fee too high");
Refunds
CCIP may refund unused fees if:
- Message fails to deliver
- Target chain is unavailable
- Message is rejected
Check refund status in transaction logs.
Troubleshooting
Insufficient LINK
Error: "Insufficient LINK balance"
Solution:
- Check LINK balance
- Transfer more LINK tokens
- Verify token address is correct
Fee Too High
Error: "Fee exceeds limit"
Solution:
- Reduce message size
- Wait for lower gas prices
- Increase fee limit (if appropriate)
Fee Calculation Failed
Error: "Failed to calculate fee"
Solution:
- Verify CCIP Router is accessible
- Check target chain selector is valid
- Ensure router is properly configured
Best Practices
- Maintain Buffer: Keep 2-3x expected fees in balance
- Monitor Regularly: Check fee consumption daily
- Set Alerts: Alert on low balance or high fees
- Budget Planning: Plan for fee costs in operations budget
- Test Fees: Test fee calculation in staging environment