Sender
Inherits: ISender, Initializable, UUPSUpgradeable
This contract implements the ISender interface to send cross-chain messaging. It allows sending messages to a destination chain, managing allowlists for source, destination chains and sender contracts.
State Variables
MINIMUM_BRIDGE_AMOUNT
uint256 public constant MINIMUM_BRIDGE_AMOUNT = 1e18;
s_gasLimit
uint256 s_gasLimit = 120000;
s_tokenToBridge
address public s_tokenToBridge;
s_router
IRouterClient public s_router;
s_sponsoredFees
bool public s_sponsoredFees = false;
s_addressProvider
IAddressProvider public s_addressProvider;
s_whitelistedMerkleRoot
bytes32 public s_whitelistedMerkleRoot;
s_allowlistedDestinationChains
mapping(uint64 => bool) public s_allowlistedDestinationChains;
Functions
onlyMaintainer
check that msg.sender has MAINTAINER_ROLE
modifier onlyMaintainer();
onlyUserCentalized
check that msg.sender has OPERATOR_ROLE
modifier onlyUserCentalized();
onlyAllowlistedDestinationChain
check that the destination chain is allowlisted
modifier onlyAllowlistedDestinationChain(uint64 destinationChainSelector);
onlyWhitelistedIfSetup
check that msg.sender is whitelisted if the merkle root is set
modifier onlyWhitelistedIfSetup(bytes32[] calldata _proof);
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor();
initialize
Initialize for the Sender contract.
function initialize(address router, address tokenToBridge, address addressProvider) external initializer;
Parameters
| Name | Type | Description |
|---|---|---|
router | address | The address of the CCIP router according to the chainlink documentation |
tokenToBridge | address | The token to bridge from the source chain to the destination chain |
addressProvider | address | The address of the address provider contract |
receive
enable the receive function to receive native token
receive() external payable;
sendMessage
This function sends a message to a destination chain.
function sendMessage(uint64 destinationChainSelector, address receiver, uint256 amount, bytes32[] calldata _proof)
external
payable
override
onlyAllowlistedDestinationChain(destinationChainSelector)
onlyWhitelistedIfSetup(_proof)
returns (bytes32 messageId);
Parameters
| Name | Type | Description |
|---|---|---|
destinationChainSelector | uint64 | The selector of the destination chain. |
receiver | address | The address of the receiver contract on the destination chain. |
amount | uint256 | The amount of tokens to send. |
_proof | bytes32[] | The merkle proof to verify the sender's whitelisting. |
allowlistDestinationChain
This function updates the allowlist for receiving from a source chain
function allowlistDestinationChain(uint64 destinationChainSelector, bool allow) external override onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
destinationChainSelector | uint64 | The selector of the destination chain |
allow | bool | The permission |
updateWhitelistedRoot
This function allows the operator to update the whitelisted merkle root.
function updateWhitelistedRoot(bytes32 newRoot) external onlyUserCentalized;
Parameters
| Name | Type | Description |
|---|---|---|
newRoot | bytes32 | The new whitelisted merkle root. |
withdraw
This function is used to withdraw native tokens
function withdraw(address beneficiary) external override onlyMaintainer;
setAddressProvider
Sets the address provider for the messenger contract.
function setAddressProvider(address newAddressProvider) external onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
newAddressProvider | address | The address of the new address provider |
setSponsoredFees
Sets whether the fees for sending messages are sponsored or not.
If sponsored, the contract will pay the fees for sending messages.
function setSponsoredFees(bool sponsoredFees) external onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
sponsoredFees | bool | Whether the fees for sending messages are sponsored or not. |
estimateFees
This function estimates the fees for sending a message
function estimateFees(uint64 destinationChainSelector, address receiver, uint256 amount)
external
view
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
destinationChainSelector | uint64 | The selector of the destination chain |
receiver | address | The address of the receiver contract on the destination chain |
amount | uint256 | The amount of tokens to send |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | uint256 The estimated fees in native token |
_setAddressProvider
function _setAddressProvider(address newAddressProvider) private;
_setSponsoredFees
function _setSponsoredFees(bool sponsoredFees) private;
_buildCCIPMessage
Builds the CCIP message to be sent.
function _buildCCIPMessage(address receiver, bytes memory _data, address feeTokenAddress)
private
pure
returns (Client.EVM2AnyMessage memory);
Parameters
| Name | Type | Description |
|---|---|---|
receiver | address | The address of the receiver contract on the destination chain. |
_data | bytes | The ABI-encoded data to be sent. |
feeTokenAddress | address | The address of the token to be used for fees, 0 for native token. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | Client.EVM2AnyMessage | Client.EVM2AnyMessage The constructed CCIP message. |
_estimateFees
function _estimateFees(Client.EVM2AnyMessage memory evm2AnyMessage, uint64 destinationChainSelector)
private
view
returns (uint256);
_authorizeUpgrade
function _authorizeUpgrade(address newImplementation) internal override onlyMaintainer;