Skip to content

Commit a5f1368

Browse files
committed
Add docs
1 parent c926b36 commit a5f1368

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

contracts/crosschain/axelar/AxelarGatewayBase.sol

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,55 @@ pragma solidity ^0.8.0;
55
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
66
import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol";
77

8+
/**
9+
* @dev Base implementation of a cross-chain gateway adapter for the Axelar Network.
10+
*
11+
* This contract allows developers to register equivalence between chains (i.e. CAIP-2 chain identifiers
12+
* to Axelar chain identifiers) and remote gateways (i.e. gateways on other chains) to
13+
* facilitate cross-chain communication.
14+
*/
815
abstract contract AxelarGatewayBase is Ownable {
16+
/// @dev A remote gateway has been registered for a chain.
917
event RegisteredRemoteGateway(string caip2, string gatewayAddress);
18+
19+
/// @dev A chain equivalence has been registered.
1020
event RegisteredChainEquivalence(string caip2, string destinationChain);
1121

22+
/// @dev Error emitted when an unsupported chain is queried.
1223
error UnsupportedChain(string caip2);
1324

25+
/// @dev Axelar's official gateway for the current chain.
1426
IAxelarGateway public immutable localGateway;
1527

1628
mapping(string caip2 => string remoteGateway) private _remoteGateways;
17-
mapping(string caip2OrAxelar => string axelarOfCaip2) private _chainEquivalence;
29+
mapping(string caip2OrAxelar => string axelarOrCaip2) private _chainEquivalence;
1830

31+
/// @dev Sets the local gateway address (i.e. Axelar's official gateway for the current chain).
1932
constructor(IAxelarGateway _gateway) {
2033
localGateway = _gateway;
2134
}
2235

36+
/// @dev Returns the equivalent chain given an id that can be either CAIP-2 or an Axelar network identifier.
2337
function getEquivalentChain(string memory input) public view virtual returns (string memory output) {
2438
output = _chainEquivalence[input];
2539
require(bytes(output).length > 0, UnsupportedChain(input));
2640
}
2741

42+
/// @dev Returns the remote gateway address for a given chain.
2843
function getRemoteGateway(string memory caip2) public view virtual returns (string memory remoteGateway) {
2944
remoteGateway = _remoteGateways[caip2];
3045
require(bytes(remoteGateway).length > 0, UnsupportedChain(caip2));
3146
}
3247

48+
/// @dev Registers a chain equivalence between a CAIP-2 chain identifier and an Axelar network identifier.
3349
function registerChainEquivalence(string calldata caip2, string calldata axelarSupported) public virtual onlyOwner {
3450
require(bytes(_chainEquivalence[caip2]).length == 0);
3551
_chainEquivalence[caip2] = axelarSupported;
3652
_chainEquivalence[axelarSupported] = caip2;
3753
emit RegisteredChainEquivalence(caip2, axelarSupported);
3854
}
3955

56+
/// @dev Registers a remote gateway address for a given CAIP-2 chain identifier.
4057
function registerRemoteGateway(string calldata caip2, string calldata remoteGateway) public virtual onlyOwner {
4158
require(bytes(_remoteGateways[caip2]).length == 0);
4259
_remoteGateways[caip2] = remoteGateway;

contracts/crosschain/axelar/AxelarGatewayDestination.sol

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ import {Strings} from "@openzeppelin/contracts@master/utils/Strings.sol";
99
import {IERC7786GatewayDestinationPassive, IERC7786Receiver} from "../interfaces/draft-IERC7786.sol";
1010
import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
1111

12+
/**
13+
* @dev Implementation of an ERC7786 gateway destination adapter for the Axelar Network in dual mode.
14+
*
15+
* The contract provides an internal {_execute} function to be used by a child contract (active mode),
16+
* Alternatively, it provides a way to set a message as executed by calling the {setExecutedMessage}
17+
* function (passive mode).
18+
*/
1219
abstract contract AxelarGatewayDestination is IERC7786GatewayDestinationPassive, AxelarGatewayBase, AxelarExecutable {
1320
using Strings for address;
1421
using Strings for string;
1522

16-
/// @dev Passive mode
23+
/// @dev Sets a message as executed so it can't be executed again. Should be called by the receiver contract.
1724
function setExecutedMessage(
1825
bytes calldata messageKey,
1926
string calldata source, // CAIP-2
@@ -44,14 +51,18 @@ abstract contract AxelarGatewayDestination is IERC7786GatewayDestinationPassive,
4451
);
4552
}
4653

47-
/// @dev Active mode
48-
// In this function:
49-
// - `remoteChain` is in the Axelar format. It should not be expected to be a proper CAIP-2 format
50-
// - `remoteAccount` is the sender of the crosschain message. That should be the remote gateway on the chain which
51-
// the message originates from. It is NOT the sender of the crosschain message
52-
//
53-
// Proper CAIP-10 encoding of the message sender (including the CAIP-2 name of the origin chain can be found in
54-
// the message)
54+
/**
55+
* @dev Active mode execution of a cross-chain message.
56+
*
57+
* In this function:
58+
*
59+
* - `remoteChain` is in the Axelar format. It should not be expected to be a proper CAIP-2 format
60+
* - `remoteAccount` is the sender of the crosschain message. That should be the remote gateway on the chain which
61+
* the message originates from. It is NOT the sender of the crosschain message
62+
*
63+
* Proper CAIP-10 encoding of the message sender (including the CAIP-2 name of the origin chain can be found in
64+
* the message)
65+
*/
5566
function _execute(
5667
string calldata remoteChain, // chain of the remote gateway - axelar format
5768
string calldata remoteAccount, // address of the remote gateway

contracts/crosschain/axelar/AxelarGatewaySource.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ import {Strings} from "@openzeppelin/contracts@master/utils/Strings.sol";
88
import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
99
import {IERC7786GatewaySource} from "../interfaces/draft-IERC7786.sol";
1010

11+
/**
12+
* @dev Implementation of an ERC7786 gateway source adapter for the Axelar Network.
13+
*
14+
* The contract provides a way to send messages to a remote chain using the Axelar Network
15+
* using the {sendMessage} function.
16+
*/
1117
abstract contract AxelarGatewaySource is IERC7786GatewaySource, AxelarGatewayBase {
1218
using Strings for address;
1319

20+
/// @inheritdoc IERC7786GatewaySource
1421
function supportsAttribute(bytes4 /*selector*/) public pure returns (bool) {
1522
return false;
1623
}
1724

25+
/// @inheritdoc IERC7786GatewaySource
1826
function sendMessage(
1927
string calldata destination, // CAIP-2 chain ID
2028
string calldata receiver, // i.e. address

0 commit comments

Comments
 (0)