297 lines
6.4 KiB
Markdown
297 lines
6.4 KiB
Markdown
# CCIP API Reference for ChainID 138
|
|
|
|
**Date**: 2025-01-27
|
|
**Network**: ChainID 138 (DeFi Oracle Meta Mainnet)
|
|
|
|
---
|
|
|
|
## Overview
|
|
|
|
This document provides API reference for CCIP contracts on ChainID 138.
|
|
|
|
---
|
|
|
|
## CCIP Router API
|
|
|
|
### Functions
|
|
|
|
#### `ccipSend(uint64 destinationChainSelector, EVM2AnyMessage memory message)`
|
|
|
|
Send a message to a destination chain.
|
|
|
|
**Parameters**:
|
|
- `destinationChainSelector`: Chain selector of destination chain
|
|
- `message`: CCIP message structure
|
|
|
|
**Returns**:
|
|
- `bytes32 messageId`: Unique message identifier
|
|
- `uint256 fees`: Fees paid for the message
|
|
|
|
**Example**:
|
|
```solidity
|
|
IRouterClient.EVM2AnyMessage memory message = IRouterClient.EVM2AnyMessage({
|
|
receiver: abi.encode(receiverAddress),
|
|
data: messageData,
|
|
tokenAmounts: new IRouterClient.TokenAmount[](0),
|
|
feeToken: address(0), // Native ETH
|
|
extraArgs: ""
|
|
});
|
|
|
|
(bytes32 messageId, uint256 fees) = router.ccipSend{value: fee}(
|
|
destinationSelector,
|
|
message
|
|
);
|
|
```
|
|
|
|
#### `getFee(uint64 destinationChainSelector, EVM2AnyMessage memory message)`
|
|
|
|
Calculate fee for sending a message.
|
|
|
|
**Parameters**:
|
|
- `destinationChainSelector`: Chain selector of destination chain
|
|
- `message`: CCIP message structure
|
|
|
|
**Returns**:
|
|
- `uint256 fee`: Required fee amount
|
|
|
|
**Example**:
|
|
```solidity
|
|
uint256 fee = router.getFee(destinationSelector, message);
|
|
```
|
|
|
|
#### `getSupportedTokens(uint64 destinationChainSelector)`
|
|
|
|
Get list of supported tokens for a destination chain.
|
|
|
|
**Parameters**:
|
|
- `destinationChainSelector`: Chain selector
|
|
|
|
**Returns**:
|
|
- `address[] tokens`: Array of supported token addresses
|
|
|
|
#### `addSupportedChain(uint64 chainSelector)` (Admin Only)
|
|
|
|
Add a supported destination chain.
|
|
|
|
**Parameters**:
|
|
- `chainSelector`: Chain selector to add
|
|
|
|
#### `removeSupportedChain(uint64 chainSelector)` (Admin Only)
|
|
|
|
Remove a supported destination chain.
|
|
|
|
#### `addSupportedToken(uint64 chainSelector, address token)` (Admin Only)
|
|
|
|
Add a supported token for a chain.
|
|
|
|
**Parameters**:
|
|
- `chainSelector`: Chain selector
|
|
- `token`: Token address
|
|
|
|
#### `updateFees(uint256 baseFee, uint256 dataFeePerByte)` (Admin Only)
|
|
|
|
Update fee configuration.
|
|
|
|
**Parameters**:
|
|
- `baseFee`: New base fee
|
|
- `dataFeePerByte`: New data fee per byte
|
|
|
|
---
|
|
|
|
## CCIPWETH9Bridge API
|
|
|
|
### Functions
|
|
|
|
#### `sendCrossChain(uint64 destinationChainSelector, address recipient, uint256 amount)`
|
|
|
|
Send WETH9 tokens to another chain.
|
|
|
|
**Parameters**:
|
|
- `destinationChainSelector`: Destination chain selector
|
|
- `recipient`: Recipient address on destination chain
|
|
- `amount`: Amount of WETH9 to send
|
|
|
|
**Returns**:
|
|
- `bytes32 messageId`: Message ID for tracking
|
|
|
|
**Example**:
|
|
```solidity
|
|
// Approve first
|
|
weth9.approve(address(bridge), amount);
|
|
|
|
// Send
|
|
bytes32 messageId = bridge.sendCrossChain(
|
|
5009297550715157269, // Ethereum Mainnet
|
|
recipientAddress,
|
|
amount
|
|
);
|
|
```
|
|
|
|
#### `ccipReceive(Any2EVMMessage calldata message)` (Router Only)
|
|
|
|
Receive WETH9 tokens from another chain. Called by router.
|
|
|
|
#### `calculateFee(uint64 destinationChainSelector, uint256 amount)`
|
|
|
|
Calculate fee for cross-chain transfer.
|
|
|
|
**Parameters**:
|
|
- `destinationChainSelector`: Destination chain selector
|
|
- `amount`: Transfer amount
|
|
|
|
**Returns**:
|
|
- `uint256 fee`: Required fee
|
|
|
|
#### `addDestination(uint64 chainSelector, address receiverBridge)` (Admin Only)
|
|
|
|
Add destination chain configuration.
|
|
|
|
#### `removeDestination(uint64 chainSelector)` (Admin Only)
|
|
|
|
Remove destination chain.
|
|
|
|
#### `updateDestination(uint64 chainSelector, address receiverBridge)` (Admin Only)
|
|
|
|
Update destination receiver bridge address.
|
|
|
|
#### `getDestinationChains()`
|
|
|
|
Get list of configured destination chains.
|
|
|
|
**Returns**:
|
|
- `uint64[]`: Array of chain selectors
|
|
|
|
#### `getUserNonce(address user)`
|
|
|
|
Get user's current nonce.
|
|
|
|
**Returns**:
|
|
- `uint256`: User nonce
|
|
|
|
---
|
|
|
|
## CCIPWETH10Bridge API
|
|
|
|
Same as CCIPWETH9Bridge, but for WETH10 tokens.
|
|
|
|
---
|
|
|
|
## Events
|
|
|
|
### Router Events
|
|
|
|
```solidity
|
|
event MessageSent(
|
|
bytes32 indexed messageId,
|
|
uint64 indexed destinationChainSelector,
|
|
address indexed sender,
|
|
bytes receiver,
|
|
bytes data,
|
|
TokenAmount[] tokenAmounts,
|
|
address feeToken,
|
|
bytes extraArgs
|
|
);
|
|
|
|
event MessageReceived(
|
|
bytes32 indexed messageId,
|
|
uint64 indexed sourceChainSelector,
|
|
address indexed sender,
|
|
bytes data,
|
|
TokenAmount[] tokenAmounts
|
|
);
|
|
```
|
|
|
|
### Bridge Events
|
|
|
|
```solidity
|
|
event CrossChainTransferInitiated(
|
|
bytes32 indexed messageId,
|
|
address indexed sender,
|
|
uint64 indexed destinationChainSelector,
|
|
address recipient,
|
|
uint256 amount,
|
|
uint256 nonce
|
|
);
|
|
|
|
event CrossChainTransferCompleted(
|
|
bytes32 indexed messageId,
|
|
uint64 indexed sourceChainSelector,
|
|
address indexed recipient,
|
|
uint256 amount
|
|
);
|
|
|
|
event DestinationAdded(uint64 chainSelector, address receiverBridge);
|
|
event DestinationRemoved(uint64 chainSelector);
|
|
event DestinationUpdated(uint64 chainSelector, address receiverBridge);
|
|
```
|
|
|
|
---
|
|
|
|
## Data Structures
|
|
|
|
### EVM2AnyMessage
|
|
|
|
```solidity
|
|
struct EVM2AnyMessage {
|
|
bytes receiver; // Encoded receiver address
|
|
bytes data; // Message data
|
|
TokenAmount[] tokenAmounts; // Token amounts to transfer
|
|
address feeToken; // Fee token address (0 for native)
|
|
bytes extraArgs; // Extra arguments
|
|
}
|
|
```
|
|
|
|
### Any2EVMMessage
|
|
|
|
```solidity
|
|
struct Any2EVMMessage {
|
|
bytes32 messageId; // Unique message ID
|
|
uint64 sourceChainSelector; // Source chain selector
|
|
bytes sender; // Encoded sender address
|
|
bytes data; // Message data
|
|
TokenAmount[] tokenAmounts; // Token amounts received
|
|
}
|
|
```
|
|
|
|
### TokenAmount
|
|
|
|
```solidity
|
|
struct TokenAmount {
|
|
address token; // Token address
|
|
uint256 amount; // Amount
|
|
TokenAmountType amountType; // Fiat or Native
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Error Codes
|
|
|
|
### Router Errors
|
|
|
|
- `CCIPRouter: chain not supported`
|
|
- `CCIPRouter: insufficient native token fee`
|
|
- `CCIPRouter: duplicate message`
|
|
- `CCIPRouter: empty receiver`
|
|
|
|
### Bridge Errors
|
|
|
|
- `CCIPWETH9Bridge: destination not enabled`
|
|
- `CCIPWETH9Bridge: transfer failed`
|
|
- `CCIPWETH9Bridge: transfer already processed`
|
|
- `CCIPWETH9Bridge: invalid amount`
|
|
- `CCIPWETH9Bridge: zero recipient`
|
|
|
|
---
|
|
|
|
## Related Documentation
|
|
|
|
- [Developer Integration Guide](../developer-guides/CCIP_INTEGRATION_GUIDE.md)
|
|
- [User Guide](../user-guides/CCIP_BRIDGE_USER_GUIDE.md)
|
|
- [Deployment Guide](DEPLOYMENT_GUIDE_CHAIN138.md)
|
|
|
|
---
|
|
|
|
**Last Updated**: 2025-01-27
|
|
|