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 for 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,
    address to,
    bytes memory payload,
    uint8[] memory gmps,
    bool retriable,
    uint256 gasPayment)
    returns(bytes32)
_routeSingle(
    uint256 chainId,
    address to,
    bytes memory payload,
    uint8 gmp,
    uint256 gasPayment)
    returns(bytes32)
_routeRedundant(
    uint256 chainId,
    address to,
    bytes memory payload,
    uint8[] memory gmps,
    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 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,
    address to,
    bytes memory payload,
    uint8[] memory gmps,
    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(
    uint8 fromGmpId,
    uint256 sourceChain,
    address sourceAddress,
    address to,
    bytes calldata 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;    // 0 means any chain
        address fromAddress;    // 0x00 means any address
        uint8 fromGmpId;        // 0 means any GMP
    }

Leaving any value as 0 indicates that it is a wildcard route. You can have multiple routes at a time. To remove a route, use one of the following functions:

  • removeAllowedRoute(GlacisRoute calldata route)

  • removeAllAllowedRoutes()

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 glacisData, bytes memory payload) external view virtual 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