- 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.
4.9 KiB
CCIP Integration Guide
Overview
Chainlink Cross-Chain Interoperability Protocol (CCIP) enables secure cross-chain communication for oracle data updates. This guide explains how to integrate CCIP with the DeFi Oracle Meta Mainnet.
Architecture
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Source Chain │────────▶│ CCIP Router │────────▶│ Target Chain │
│ (ChainID 138) │ │ │ │ (Other Chain) │
└─────────────────┘ └──────────────┘ └─────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ CCIPSender │ │ CCIP Router │ │ CCIPReceiver │
│ Contract │ │ Service │ │ Contract │
└──────────────┘ └──────────────┘ └──────────────┘
Components
1. CCIP Router Interface
The IRouterClient interface defines the standard CCIP Router interface for sending and receiving cross-chain messages.
Location: contracts/ccip/IRouterClient.sol
2. CCIP Sender Contract
The CCIPSender contract sends oracle data to other chains via CCIP.
Location: contracts/ccip/CCIPSender.sol
Key Functions:
sendOracleUpdate(): Sends oracle price update to target chaincalculateFee(): Calculates CCIP message fee
3. CCIP Receiver Contract
The CCIPReceiver contract receives oracle data from other chains via CCIP.
Location: contracts/ccip/CCIPReceiver.sol
Key Functions:
ccipReceive(): Handles incoming CCIP messagesupdateOracle(): Updates oracle aggregator with received data
Integration Steps
Step 1: Deploy CCIP Router
- Deploy Chainlink CCIP Router on your chain
- Get the router address
- Configure router in your contracts
Step 2: Deploy CCIP Contracts
# Deploy CCIPSender
forge script script/DeployCCIPSender.s.sol --rpc-url $RPC_URL --broadcast
# Deploy CCIPReceiver
forge script script/DeployCCIPReceiver.s.sol --rpc-url $RPC_URL --broadcast
Step 3: Configure Contracts
- Set CCIP Router address in sender and receiver contracts
- Set target chain selector
- Configure oracle aggregator address
- Set transmitter role for receiver contract
Step 4: Send Cross-Chain Messages
// In your oracle update function
CCIPSender sender = CCIPSender(senderAddress);
uint256 fee = sender.calculateFee(targetChainSelector, messageData);
sender.sendOracleUpdate{value: fee}(targetChainSelector, receiverAddress, priceData);
Step 5: Receive Cross-Chain Messages
The CCIP Router automatically calls ccipReceive() on the receiver contract when a message arrives.
Message Format
CCIP messages contain encoded oracle data:
struct OracleMessage {
uint256 answer; // Oracle price/answer
uint256 roundId; // Round ID
uint256 timestamp; // Timestamp
}
Fee Calculation
CCIP fees are calculated based on:
- Message size
- Target chain
- Gas price on target chain
Use calculateFee() to get the required fee before sending.
Security Considerations
- Replay Protection: Messages are tracked by
messageIdto prevent replay attacks - Access Control: Only authorized transmitters can update oracles
- Message Validation: Validate message format and source chain
- Fee Management: Ensure sufficient LINK tokens for fees
Monitoring
Monitor CCIP message flow:
- Message send success/failure rates
- Message delivery latency
- Fee consumption
- Error rates
See monitoring/prometheus/alerts/ccip.yml for alerting rules.
Troubleshooting
Message Not Received
- Check CCIP Router is deployed and running
- Verify target chain selector is correct
- Check receiver contract address is correct
- Verify sufficient LINK tokens for fees
- Check message was sent successfully
High Fees
- Optimize message size
- Consider batching multiple updates
- Monitor gas prices on target chain
Replay Protection Errors
- Check
processedMessagesmapping - Verify message IDs are unique
- Check for duplicate message sends