Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC implementation of Axelar cross chain #177

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "lib/PermitC"]
path = lib/PermitC
url = https://github.com/limitbreakinc/PermitC
[submodule "lib/axelar-gmp-sdk-solidity"]
path = lib/axelar-gmp-sdk-solidity
url = https://github.com/axelarnetwork/axelar-gmp-sdk-solidity
1 change: 1 addition & 0 deletions lib/axelar-gmp-sdk-solidity
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ forge-std/=lib/forge-std/src/
@erc721a-upgradeable/=lib/ERC721A-Upgradeable/contracts/
@limitbreak/creator-token-standards/=lib/creator-token-standards/src/
@limitbreak/permit-c/=lib/PermitC/src/
@axelar-network/sdk-solidity/=lib/axelar-gmp-sdk-solidity/contracts/
98 changes: 98 additions & 0 deletions src/module/token/crosschain/Axelar.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {Module} from "../../../Module.sol";

import {Role} from "../../../Role.sol";
import {IInstallationCallback} from "../../../interface/IInstallationCallback.sol";

import {CrossChain} from "./CrossChain.sol";
import {AxelarExecutable} from "@axelar-network/sdk-solidity/executable/AxelarExecutable.sol";
import {IAxelarGateway} from "@axelar-network/sdk-solidity/interfaces/IAxelarGateway.sol";
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";

contract AxelarCrossChain is Module, AxelarExecutable, CrossChain {

constructor(address _axelarGateway) AxelarExecutable(_axelarGateway) {}

/// @notice Returns all implemented callback and fallback functions.
function getModuleConfig() external pure override returns (ModuleConfig memory config) {
config.fallbackFunctions = new FallbackFunction[](3);

config.fallbackFunctions[0] = FallbackFunction({selector: this.getRouter.selector, permissionBits: 0});
config.fallbackFunctions[1] =
FallbackFunction({selector: this.setRouter.selector, permissionBits: Role._MANAGER_ROLE});
config.fallbackFunctions[2] =
FallbackFunction({selector: this.sendCrossChainTransaction.selector, permissionBits: 0});
}

/*//////////////////////////////////////////////////////////////
FALLBACK FUNCTIONS
//////////////////////////////////////////////////////////////*/

function getRouter() external view override returns (address) {
return address(gateway);
}

function setRouter(address _router) external override {}

function sendCrossChainTransaction(
uint64 _destinationChain,
address _callAddress,
bytes calldata _payload,
bytes calldata _extraArgs
) external payable override {
(string memory destinationChain, string memory contractAddress, bytes memory tokenData) =
abi.decode(_extraArgs, (string, string, bytes));

if (tokenData.length > 0) {
(string memory symbol, uint256 amount) = abi.decode(tokenData, (string, uint256));
gateway.callContractWithToken(destinationChain, contractAddress, _payload, symbol, amount);
} else {
gateway.callContract(destinationChain, contractAddress, _payload);
}

onCrossChainTransactionSent(_destinationChain, _callAddress, _payload, _extraArgs);
}

function _execute(string calldata sourceChain, string calldata sourceAddress, bytes calldata payload)
internal
override
{
onCrossChainTransactionReceived(0, address(0), payload, "");
}

function _executeWithToken(
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) internal override {
bytes memory extraArgs = abi.encode(tokenSymbol, amount);
onCrossChainTransactionReceived(0, address(0), payload, extraArgs);
}

/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

function onCrossChainTransactionSent(
uint64 _destinationChain,
address _callAddress,
bytes calldata _payload,
bytes calldata _extraArgs
) internal override {
/// post cross chain transaction sent logic goes here
}

function onCrossChainTransactionReceived(
uint64 _sourceChain,
address _sourceAddress,
bytes memory _payload,
bytes memory _extraArgs
) internal override {
/// post cross chain transaction received logic goes here
}

}