# GlacisTokenMediator

**Your gateway to cross-chain token activity.**

The GlacisTokenMediator smart contract acts as the on-chain interface for all token cross-chain activity with Glacis.

You can discover the source smart contract [`GlacisTokenMediator.sol`](https://github.com/glacislabs/v1-core/blob/main/contracts/mediators/GlacisTokenMediator.sol) in this repository.

## The Route Function

The main function in GlacisTokenMediator is route, which sends a cross-chain message and/or tokens. Using the GlacisTokenMediator to send tokens will always have retryable be enabled.

```solidity
function route(
        uint256 chainId,
        bytes32 to,
        bytes memory payload,
        address[] memory adapters,
        GlacisCommons.CrossChainGas[] memory fees,
        address refundAddress,
        address token,
        uint256 tokenAmount
  ) payable returns (bytes32, uint256)
```

> Internally this function is in charge of populating GlacisTokenData, adding it to the payload and finally routing it to the GlacisRouter

Here is a detailed description of function parameters.

<table><thead><tr><th width="279">Parameter Name</th><th>Parameter Description</th></tr></thead><tbody><tr><td><strong>uint256</strong> chainId</td><td>The Glacis ID of the blockchain that you wish to send a message and/or tokens to</td></tr><tr><td><strong>bytes32</strong> to</td><td>The address of the destination contract that you are sending a message and/or tokens to</td></tr><tr><td><strong>bytes memory</strong> payload</td><td>The payload (message) of data that you wish to send to the destination contract</td></tr><tr><td><strong>address[] memory</strong> adapters</td><td>An array of adapters to send the message over, such as an <a href="https://www.axelar.network/">Axelar</a> adapter. Can be an address if you wish to use an adapter that Glacis does not use, otherwise it can be a <a href="/pages/468mOakZwtVJutATMAUq">GMP ID</a> stored as an address</td></tr><tr><td><strong>GlacisRouter.CrossChainGas[] memory</strong> fees</td><td>An array of fees that correspond to the amount provided to each adapter. This is a parallel array to the adapters parameter. The sum of the "nativeCurrencyValue" must be equal to the value sent with this function</td></tr><tr><td><strong>address</strong> refundAddress</td><td>The address to which excess native currency is sent to if an adapter deems that the user overpaid</td></tr><tr><td><strong>address</strong> token</td><td>The address of the XERC20 token you wish to send to the destination contract</td></tr><tr><td><strong>uint256</strong> tokenAmount</td><td>The amount of XERC20 tokens you wish to send to the destination contract</td></tr></tbody></table>

## The Retry Route

An additional route is provided, which doesn't send a new message and/or tokens. Instead, it allows resending of a previous message and/or tokens so long as it receives identical input.

```solidity
function routeRetry(
        uint256 chainId,
        bytes32 to,
        bytes memory payload,
        address[] memory adapters,
        GlacisCommons.CrossChainGas[] memory fees,
        address refundAddress,
        bytes32 messageId,
        uint256 nonce,
        address token,
        uint256 tokenAmount)
  public payable virtual returns (bytes32)
```

> This route cannot be used for original cross-chain messages. Instead, it is used to retry a cross-chain message with an identical message ID and identical data (but potentially through a different GMP). This can be helpful in cases where a message is somehow lost by a GMP's consensus mechanism or its relayers. An identical message would be sent, and whichever message arrives after the first will revert.

Two additional parameters are required with this function:

| Parameter Name    | Parameter Description                                                                |
| ----------------- | ------------------------------------------------------------------------------------ |
| bytes32 messageId | The Glacis message ID of the original message                                        |
| uint256 nonce     | The nonce of the message, which can be retrieved in the original message's event log |

> Only the original message sender can retry a message, no other address can do it on their behalf. Also note that identical data must be provided.

## Errors

It also includes the following errors, some of which you may encounter:

| Error Name                                    | Error Description                                                                                                   |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| GlacisTokenMediator\_\_OnlyTokenRouterAllowed | Occurs when routing, and the from address of the receiving payload is not the same token router on the remote chain |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.glacislabs.com/glacis-core/references/smart-contracts/glacistokenmediator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
