Receiver
Inherits: CCIPReceiver, IReceiver, ReentrancyGuard
State Variables
inError
bool public inError = false;
PRECISION
uint256 public constant PRECISION = 1e18;
BONUS_PRECISION
uint256 public constant BONUS_PRECISION = 100;
i_token
address public immutable i_token;
i_stTrendex
address public immutable i_stTrendex;
s_addressProvider
IAddressProvider public s_addressProvider;
s_conversionRatio
uint256 public s_conversionRatio = 1e18;
s_allowlistedSourceChains
mapping(uint64 => bool) public s_allowlistedSourceChains;
s_allowlistedSenders
mapping(address => bool) public s_allowlistedSenders;
s_processedMessages
mapping(bytes32 messageId => bool isProcessed) public s_processedMessages;
s_failedMessages
mapping(bytes32 messageId => bytes errorData) public s_failedMessages;
s_messageContents
mapping(bytes32 messageId => Client.Any2EVMMessage content) public s_messageContents;
s_amountToMint
mapping(address user => uint256 amount) public s_amountToMint;
Functions
setInError
function setInError() public;
onlyMaintainer
check that msg.sender has MAINTAINER_ROLE
modifier onlyMaintainer();
onlyOperator
check that msg.sender has OPERATOR_ROLE
modifier onlyOperator();
onlyAllowlisted
check that the source chain and the sender are allowlisted
modifier onlyAllowlisted(uint64 sourceChainSelector, address sender);
onlyReceiver
check that the caller is the receiver (address(this))
modifier onlyReceiver();
constructor
constructor(
address stTrendex,
address router,
address token,
address addressProvider,
address sender,
uint64 sourceChain
) CCIPReceiver(router);
ccipReceive
This function is called by the CCIP router to receive messages
It processes the message and increment the amount of tokens to the destination user address.
It catches any errors that occur during the processing of the message and handles them accordingly by storing the error data and emitting an event.
function ccipReceive(Client.Any2EVMMessage calldata any2EvmMessage)
external
override
onlyRouter
onlyAllowlisted(any2EvmMessage.sourceChainSelector, abi.decode(any2EvmMessage.sender, (address)));
Parameters
| Name | Type | Description |
|---|---|---|
any2EvmMessage | Client.Any2EVMMessage | The message coming from the source chain |
retryFailedMessage
This function allows protocole to retry failed message
function retryFailedMessage(bytes32 messageId) external override onlyOperator;
Parameters
| Name | Type | Description |
|---|---|---|
messageId | bytes32 | The ID of the message to retry |
processMessage
This function processes the message received from the CCIP router
function processMessage(Client.Any2EVMMessage memory any2EvmMessage) external onlyReceiver;
Parameters
| Name | Type | Description |
|---|---|---|
any2EvmMessage | Client.Any2EVMMessage | The message coming from the source chain |
setAddressProvider
This function sets the address provider
function setAddressProvider(address addressProvider) external override onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
addressProvider | address | The address of the address provider |
setAllowlistSourceChain
This function updates the allowlist for receiving from a source chain
function setAllowlistSourceChain(uint64 sourceChainSelector, bool allow) external override onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
sourceChainSelector | uint64 | The selector of the source chain |
allow | bool | The permission |
setAllowlistSender
This function updates the allowlist for receive message from a sender contract
function setAllowlistSender(address sender, bool allow) external override onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
sender | address | The address of the sender contract |
allow | bool | The permission |
setConversionRatio
This function sets the conversion ratio
function setConversionRatio(uint256 ratio) external override onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
ratio | uint256 | The conversion ratio |
getMessageContents
This function returns the contents of a message by its ID
function getMessageContents(bytes32 messageId) external view returns (Client.Any2EVMMessage memory);
Parameters
| Name | Type | Description |
|---|---|---|
messageId | bytes32 | The ID of the message |
Returns
| Name | Type | Description |
|---|---|---|
<none> | Client.Any2EVMMessage | The contents of the message |
getConvertedAmount
This function return the conerted amount and the final amount with bonus percentage
function getConvertedAmount(uint256 amount)
external
view
returns (uint256 convertedAmount, uint256 finalAmount, uint256 bonusPercentage);
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | The amount to convert |
Returns
| Name | Type | Description |
|---|---|---|
convertedAmount | uint256 | The amount after conversion |
finalAmount | uint256 | The final amount after applying the bonus percentage |
bonusPercentage | uint256 | The percentage of the bonus applied |
_ccipReceive
This function is called by the CCIP router to receive messages
function _ccipReceive(Client.Any2EVMMessage memory any2EvmMessage) internal virtual override;
Parameters
| Name | Type | Description |
|---|---|---|
any2EvmMessage | Client.Any2EVMMessage | The message coming from the source chain |
_handleFailedMessage
This function handles a failed message by storing the error data and emitting an event
function _handleFailedMessage(Client.Any2EVMMessage calldata any2EvmMessage, bytes memory errorData) private;
Parameters
| Name | Type | Description |
|---|---|---|
any2EvmMessage | Client.Any2EVMMessage | The message that failed |
errorData | bytes | The error data to store |
_setAddressProvider
function _setAddressProvider(address addressProvider) private;
_setAllowlistSourceChain
function _setAllowlistSourceChain(uint64 sourceChainSelector, bool allow) private;
_setAllowlistSender
function _setAllowlistSender(address sender, bool allow) private;
_setConversionRatio
function _setConversionRatio(uint256 ratio) private;
_calculateConversion
This function calculates the conversion of the amount based on the conversion ratio
function _calculateConversion(uint256 amount)
private
view
returns (uint256 _amount, uint256 finalAmount, uint256 bonusPercentage);
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | The amount to convert |
Returns
| Name | Type | Description |
|---|---|---|
_amount | uint256 | The converted amount |
finalAmount | uint256 | The final amount after applying the bonus |
bonusPercentage | uint256 | The bonus percentage applied |