@@ -5,38 +5,55 @@ pragma solidity ^0.8.0;
5
5
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol " ;
6
6
import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol " ;
7
7
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
+ */
8
15
abstract contract AxelarGatewayBase is Ownable {
16
+ /// @dev A remote gateway has been registered for a chain.
9
17
event RegisteredRemoteGateway (string caip2 , string gatewayAddress );
18
+
19
+ /// @dev A chain equivalence has been registered.
10
20
event RegisteredChainEquivalence (string caip2 , string destinationChain );
11
21
22
+ /// @dev Error emitted when an unsupported chain is queried.
12
23
error UnsupportedChain (string caip2 );
13
24
25
+ /// @dev Axelar's official gateway for the current chain.
14
26
IAxelarGateway public immutable localGateway;
15
27
16
28
mapping (string caip2 = > string remoteGateway ) private _remoteGateways;
17
- mapping (string caip2OrAxelar = > string axelarOfCaip2 ) private _chainEquivalence;
29
+ mapping (string caip2OrAxelar = > string axelarOrCaip2 ) private _chainEquivalence;
18
30
31
+ /// @dev Sets the local gateway address (i.e. Axelar's official gateway for the current chain).
19
32
constructor (IAxelarGateway _gateway ) {
20
33
localGateway = _gateway;
21
34
}
22
35
36
+ /// @dev Returns the equivalent chain given an id that can be either CAIP-2 or an Axelar network identifier.
23
37
function getEquivalentChain (string memory input ) public view virtual returns (string memory output ) {
24
38
output = _chainEquivalence[input];
25
39
require (bytes (output).length > 0 , UnsupportedChain (input));
26
40
}
27
41
42
+ /// @dev Returns the remote gateway address for a given chain.
28
43
function getRemoteGateway (string memory caip2 ) public view virtual returns (string memory remoteGateway ) {
29
44
remoteGateway = _remoteGateways[caip2];
30
45
require (bytes (remoteGateway).length > 0 , UnsupportedChain (caip2));
31
46
}
32
47
48
+ /// @dev Registers a chain equivalence between a CAIP-2 chain identifier and an Axelar network identifier.
33
49
function registerChainEquivalence (string calldata caip2 , string calldata axelarSupported ) public virtual onlyOwner {
34
50
require (bytes (_chainEquivalence[caip2]).length == 0 );
35
51
_chainEquivalence[caip2] = axelarSupported;
36
52
_chainEquivalence[axelarSupported] = caip2;
37
53
emit RegisteredChainEquivalence (caip2, axelarSupported);
38
54
}
39
55
56
+ /// @dev Registers a remote gateway address for a given CAIP-2 chain identifier.
40
57
function registerRemoteGateway (string calldata caip2 , string calldata remoteGateway ) public virtual onlyOwner {
41
58
require (bytes (_remoteGateways[caip2]).length == 0 );
42
59
_remoteGateways[caip2] = remoteGateway;
0 commit comments