GlacisTokenClient
The base of your cross-chain token transfer contracts.
GlacisTokenClient is a smart contract base that can be used by developers to interact with token passing features that Glacis has to offer. By inheriting from GlacisTokenClient, a smart contract is able to send and receive messages and tokens across chains through the GlacisTokenMediator with specific security/availability features.
You can discover the source smart contract GlacisTokenClient.sol
in this repository. There is also an Ownable
variant, GlacisTokenClientOwnable.sol
.
This contract inherits from GlacisClient extending its message passing capabilities with token passing features, it communicates with GlacisTokenMediator.sol
to perform message and/or token routing actions through Glacis infrastructure.
These are the constructor arguments for GlacisTokenClient:
The address for GlacisRouter
The address for GlacisTokenMediator to create the underlying GlacisClient
The default GMP quorum for this contract to effectively receive a message
The Route Function
GlacisTokenClient has multiple internal route functions that mirror the route functions that GlacisRouter provides, each which return a bytes32 message ID:
_sendMessageAndTokens__abstract( uint256 chainId, address to, uint8 gmp, bytes memory payload, uint256 gasPayment, address token, uint256 tokenAmount ) internal returns (bytes32)
_sendMessageAndTokens__redundant( uint256 chainId, address to, uint8[] memory gmps, uint256[] memory fees, bytes memory payload, uint256 gasPayment, address token, uint256 tokenAmount ) internal returns (bytes32)
_sendMessageAndTokens__retriable( uint256 chainId, address to, uint8[] memory gmps, uint256[] memory fees, bytes memory payload, uint256 gasPayment, address token, uint256 tokenAmount ) internal returns (bytes32)
_sendMessageAndTokens( uint256 chainId, address to, bytes memory payload, uint8[] memory gmps, uint256[] memory fees, bool retriable, address token, uint256 tokenAmount, uint256 gasPayment ) internal returns (bytes32)
The following parameters are applicable to each of these route functions, similar to GlacisTokenMediator:
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 GlacisTokenClient, which doesn't send a new message and/or tokens. Instead, it resends a previous message and tokens so long as it receives identical input.
_retrySendWithTokens( uint256 chainId, address to, uint8[] memory gmps, uint256[] memory fees, bytes memory payload, bytes32 messageId, uint256 nonce, uint256 gasPayment, address token, uint256 tokenAmount ) internal returns (bytes32)
Two additional parameters are required with this function:
Keep in mind that in the GlacisTokenMediator, 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 GlacisTokenMediator will call the receiveMessageWithTokens function within your GlacisTokenClient whenever there is a message sent to your smart contract. You must override the following internal function to react to cross-chain messages:
function _receiveMessageWithTokens( uint8[] memory fromGmpIds, uint256 fromChainId, address fromAddress, address toAddress, bytes memory payload, address token, uint256 tokenAmount ) internal virtual {}
The parameters involved with this function are:
Adding Routes for Access Control
This operation is inherited so it is performed exactly as in GlacisClient
Setting Quorum
This operation is inherited so it is performed exactly as in GlacisClient
Read-Only
These are some of the read-only functions in GlacisClient:
GLACIS_TOKEN_ROUTER() returns(address) — returns the address set as the GlacisTokenMediator, 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
Glacis is not compatible with fee-on-transfer tokens.
GlacisTokenClient includes the following errors, which you might encounter:
Last updated