GlacisClient

The base of your cross-chain contracts.

GlacisClient is a smart contract base that can be used by developers to interact with the features that Glacis has to offer. By inheriting from GlacisClient, a smart contract is able to send and receive messages across chains with Glacis features. You can discover the source smart contract GlacisClient.sol in this repository. There is also an Ownable variant, GlacisClientOwnable.sol.

These are the constructor arguments for GlacisClient:

  • The address of GlacisRouter

  • The default GMP quorum for this contract to effectively receive a message

    constructor(address glacisRouter_, uint256 quorum) IGlacisClient(quorum) {
        if (glacisRouter_ == address(0))
            revert GlacisClient__InvalidRouterAddress();
        GLACIS_ROUTER = glacisRouter_;
    }

The Route Function

GlacisClient has multiple internal route functions that mirror the route functions that GlacisRouter provides, each which return a bytes32 message ID:

_route(
        uint256 chainId,
        bytes32 to,
        bytes memory payload,
        address[] memory adapters,
        CrossChainGas[] memory fees,
        address refundAddress,
        bool retryable,
        uint256 gasPayment) 
returns (bytes32,uint256)
_routeSingle(
        uint256 chainId,
        bytes32 to,
        bytes memory payload,
        address adapter,
        address refundAddress,
        uint256 gasPayment)
returns(bytes32)
_routeRedundant(
        uint256 chainId,
        bytes32 to,
        bytes memory payload,
        address[] memory adapters,
        CrossChainGas[] memory fees,
        address refundAddress,
        uint256 gasPayment)
returns (bytes32)

Each of these 3 varieties perform the same function: sending an original cross-chain message. _route is the encompassing route function that allows for complete configuration of all Glacis features. _routeSingle allows you to easily route through a single GMP. _routeRedundant allows you to easily route redundant messages (each message has the same ID and data) through multiple GMPs.

The following parameters are applicable to each of these route functions, similar to GlacisRouter:

Each of the routing functions returns a bytes32, which is the Glacis message ID for the routing. The more verbose route function also returns a uint256 nonce.

The Retry Route

An additional route is provided within GlacisClient, which doesn't send a new message. Instead, it resends a previous message so long as it receives identical input.

_routeRetry(
        uint256 chainId,
        bytes32 to,
        bytes memory payload,
        address[] memory adapters,
        CrossChainGas[] memory fees,
        address refundAddress,
        bytes32 messageId,
        uint256 nonce,
        uint256 gasPayment)
returns(bytes32)

Two additional parameters are required with this function:

Keep in mind that in the GlacisRouter, only the original sender can retry routes. If this internal function is exposed publicly, anyone can retry on your smart contract's behalf.

The Receive Message Function

The GlacisRouter will call the receiveMessage function within your GlacisClient whenever there is a message sent to your smart contract. You must override the following internal function to react to cross-chain messages:

_receiveMessage(
        address[] memory fromAdapters,
        uint256 fromChainId,
        bytes32 fromAddress,
        bytes memory payload)

The parameters involved with this function are:

Adding Routes for Access Control

You must set up routes within your instance of GlacisClient before it can receive messages. To do so, use the following function:

  • addAllowedRoute(GlacisRoute memory allowedRoute)

The GlacisRoute struct is defined as:

    struct GlacisRoute {
        uint256 fromChainId;    // WILDCARD means any chain
        address fromAddress;    // WILDCARD means any address
        address fromAdapter;    // WILDCARD means any official Glacis adapter
    }
    
    uint160 constant public WILDCARD = type(uint160).max;

Leaving any value as WILDCARD indicates that it is a wildcard route.

You can have multiple routes at a time. To remove a route, use the following function:

  • removeAllowedRoute(GlacisRoute calldata route)

Setting Quorum

Quorum is an important concept for Glacis, as it defines how many times a message with a specific message ID must be received before glacis calls your receiveMessage function. It is most likely that this number should be 1, but you can increase this number if you intend to have greater security through higher redundancy.

You can set the quorum's default value in the constructor by setting the quorum value.

If you wish to instead manually handle quorum per message, override the getQuorum function:

function getQuorum(
        GlacisCommons.GlacisData memory,    // glacis data
        bytes memory,                       // payload
        uint256                             // unique messages received so far (for dynamic quorum, usually unused)
) returns (uint256)

The parameters involved with this function are:

Read-Only

These are some of the read-only functions in GlacisClient:

  • glacisRouter() returns(address) — returns the address set as the GlacisRouter, which was set in the constructor

  • isAllowedRoute(GlacisRoute memory accessRoute) returns(bool) — returns true if the provided route is available, false otherwise. Used by the GlacisRouter to verify access

Errors

GlacisClient includes the following errors, which you might encounter:

Last updated