Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sender

ABI

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

NameTypeDescription
routeraddressThe address of the CCIP router according to the chainlink documentation
tokenToBridgeaddressThe token to bridge from the source chain to the destination chain
addressProvideraddressThe 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

NameTypeDescription
destinationChainSelectoruint64The selector of the destination chain.
receiveraddressThe address of the receiver contract on the destination chain.
amountuint256The amount of tokens to send.
_proofbytes32[]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

NameTypeDescription
destinationChainSelectoruint64The selector of the destination chain
allowboolThe permission

updateWhitelistedRoot

This function allows the operator to update the whitelisted merkle root.

function updateWhitelistedRoot(bytes32 newRoot) external onlyUserCentalized;

Parameters

NameTypeDescription
newRootbytes32The 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

NameTypeDescription
newAddressProvideraddressThe 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

NameTypeDescription
sponsoredFeesboolWhether 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

NameTypeDescription
destinationChainSelectoruint64The selector of the destination chain
receiveraddressThe address of the receiver contract on the destination chain
amountuint256The amount of tokens to send

Returns

NameTypeDescription
<none>uint256uint256 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

NameTypeDescription
receiveraddressThe address of the receiver contract on the destination chain.
_databytesThe ABI-encoded data to be sent.
feeTokenAddressaddressThe address of the token to be used for fees, 0 for native token.

Returns

NameTypeDescription
<none>Client.EVM2AnyMessageClient.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;