Skip to content

Commit

Permalink
add interface
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Jul 29, 2024
1 parent 6b1e5f5 commit 85f3e5b
Showing 3 changed files with 89 additions and 27 deletions.
6 changes: 3 additions & 3 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ import { IInterchainTokenDeployer } from './interfaces/IInterchainTokenDeployer.
import { IInterchainTokenExecutable } from './interfaces/IInterchainTokenExecutable.sol';
import { IInterchainTokenExpressExecutable } from './interfaces/IInterchainTokenExpressExecutable.sol';
import { ITokenManager } from './interfaces/ITokenManager.sol';
import { IGatewayCaller } from './interfaces/IGatewayCaller.sol';
import { Create3AddressFixed } from './utils/Create3AddressFixed.sol';
import { GatewayCaller } from './utils/GatewayCaller.sol';

import { Operator } from './utils/Operator.sol';

@@ -834,7 +834,7 @@ contract InterchainTokenService is

(bool success, bytes memory returnData) = gatewayCaller.delegatecall(
abi.encodeWithSelector(
GatewayCaller.callContract.selector,
IGatewayCaller.callContract.selector,
destinationChain,
destinationAddress,
payload,
@@ -874,7 +874,7 @@ contract InterchainTokenService is

(bool success, bytes memory returnData) = gatewayCaller.delegatecall(
abi.encodeWithSelector(
GatewayCaller.callContractWithToken.selector,
IGatewayCaller.callContractWithToken.selector,
destinationChain,
destinationAddress,
payload,
58 changes: 58 additions & 0 deletions contracts/interfaces/IGatewayCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
* @title IGatewayCaller interface
* @dev Interface for the GatewayCaller contract
*/
interface IGatewayCaller {
/**
* @dev Enum representing different metadata versions
*/
enum MetadataVersion {
CONTRACT_CALL,
EXPRESS_CALL
}

/**
* @dev Error thrown when an invalid metadata version is provided
*/
error InvalidMetadataVersion(uint32 metadataVersion);

/**
* @dev Calls a contract on a specific destination chain with the given payload
* @param destinationChain The target chain where the contract will be called
* @param destinationAddress The address of the contract to be called on the destination chain
* @param payload The data payload for the transaction
* @param metadataVersion The version of metadata to be used
* @param gasValue The amount of gas to be paid for the transaction
*/
function callContract(
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
MetadataVersion metadataVersion,
uint256 gasValue
) external payable;

/**
* @dev Calls a contract on a specific destination chain with the given payload and token
* @param destinationChain The target chain where the contract will be called
* @param destinationAddress The address of the contract to be called on the destination chain
* @param payload The data payload for the transaction
* @param symbol The symbol of the token to be sent
* @param amount The amount of tokens to be sent
* @param metadataVersion The version of metadata to be used
* @param gasValue The amount of gas to be paid for the transaction
*/
function callContractWithToken(
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
MetadataVersion metadataVersion,
uint256 gasValue
) external payable;
}
52 changes: 28 additions & 24 deletions contracts/utils/GatewayCaller.sol
Original file line number Diff line number Diff line change
@@ -4,56 +4,56 @@ pragma solidity ^0.8.0;

import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { IGatewayCaller } from '../interfaces/IGatewayCaller.sol';

/**
* @title GatewayCaller contract
* @notice This contract is used like a library to resolve metadata for the interchain token service
* @dev This contract is used to handle cross-chain calls via the Axelar gateway
*/
contract GatewayCaller {
error UntrustedChain();
error InvalidMetadataVersion(uint32 metadataVersion);

contract GatewayCaller is IGatewayCaller {
IAxelarGateway public immutable gateway;
IAxelarGasService public immutable gasService;

enum MetadataVersion {
CONTRACT_CALL,
EXPRESS_CALL
}

/**
* @dev Constructor to initialize the GatewayCaller contract
* @param gateway_ The address of the AxelarGateway contract
* @param gasService_ The address of the AxelarGasService contract
*/
constructor(address gateway_, address gasService_) {
gateway = IAxelarGateway(gateway_);
gasService = IAxelarGasService(gasService_);
}

/**
* @notice Calls a contract on a specific destination chain with the given payload
* @param destinationChain The target chain where the contract will be called.
* @param payload The data payload for the transaction.
* @param gasValue The amount of gas to be paid for the transaction.
* @dev Calls a contract on a specific destination chain with the given payload
* @param destinationChain The target chain where the contract will be called
* @param destinationAddress The address of the contract to be called on the destination chain
* @param payload The data payload for the transaction
* @param metadataVersion The version of metadata to be used
* @param gasValue The amount of gas to be paid for the transaction
*/
function callContract(
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
MetadataVersion metadataVersion,
uint256 gasValue
) external payable {
) external payable override {
if (gasValue > 0) {
if (metadataVersion == MetadataVersion.CONTRACT_CALL) {
gasService.payNativeGasForContractCall{ value: gasValue }(
address(this),
destinationChain,
destinationAddress,
payload, // solhint-disable-next-line avoid-tx-origin
payload,
tx.origin

Check warning on line 49 in contracts/utils/GatewayCaller.sol

GitHub Actions / lint

Avoid to use tx.origin
);
} else if (metadataVersion == MetadataVersion.EXPRESS_CALL) {
gasService.payNativeGasForExpressCall{ value: gasValue }(
address(this),
destinationChain,
destinationAddress,
payload, // solhint-disable-next-line avoid-tx-origin
payload,
tx.origin

Check warning on line 57 in contracts/utils/GatewayCaller.sol

GitHub Actions / lint

Avoid to use tx.origin
);
} else {
@@ -65,10 +65,14 @@ contract GatewayCaller {
}

/**
* @notice Calls a contract on a specific destination chain with the given payload and gateway token
* @param destinationChain The target chain where the contract will be called.
* @param payload The data payload for the transaction.
* @param gasValue The amount of gas to be paid for the transaction.
* @dev Calls a contract on a specific destination chain with the given payload and token
* @param destinationChain The target chain where the contract will be called
* @param destinationAddress The address of the contract to be called on the destination chain
* @param payload The data payload for the transaction
* @param symbol The symbol of the token to be sent
* @param amount The amount of tokens to be sent
* @param metadataVersion The version of metadata to be used
* @param gasValue The amount of gas to be paid for the transaction
*/
function callContractWithToken(
string calldata destinationChain,
@@ -78,7 +82,7 @@ contract GatewayCaller {
uint256 amount,
MetadataVersion metadataVersion,
uint256 gasValue
) external payable {
) external payable override {
if (gasValue > 0) {
if (metadataVersion == MetadataVersion.CONTRACT_CALL) {
gasService.payNativeGasForContractCallWithToken{ value: gasValue }(
@@ -87,7 +91,7 @@ contract GatewayCaller {
destinationAddress,
payload,
symbol,
amount, // solhint-disable-next-line avoid-tx-origin
amount,
tx.origin

Check warning on line 95 in contracts/utils/GatewayCaller.sol

GitHub Actions / lint

Avoid to use tx.origin
);
} else if (metadataVersion == MetadataVersion.EXPRESS_CALL) {
@@ -97,7 +101,7 @@ contract GatewayCaller {
destinationAddress,
payload,
symbol,
amount, // solhint-disable-next-line avoid-tx-origin
amount,
tx.origin

Check warning on line 105 in contracts/utils/GatewayCaller.sol

GitHub Actions / lint

Avoid to use tx.origin
);
} else {

0 comments on commit 85f3e5b

Please sign in to comment.