Skip to content

Commit

Permalink
feat: using a custom implementation of AxelarExecutable (#114)
Browse files Browse the repository at this point in the history
* using a custom implementation of AxelarExecutable

* Fixed an import bug.

---------

Co-authored-by: Milap Sheth <[email protected]>
  • Loading branch information
Foivos and milapsheth authored Oct 9, 2023
1 parent 111fed9 commit 69cc47e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
40 changes: 26 additions & 14 deletions contracts/interchain-token-service/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol';
import { AxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';

Expand Down Expand Up @@ -33,15 +33,7 @@ import { Multicall } from '../utils/Multicall.sol';
* It (mostly) does not handle tokens, but is responsible for the messaging that needs to occur for cross chain transfers to happen.
* @dev The only storage used here is for ExpressCalls
*/
contract InterchainTokenService is
IInterchainTokenService,
AxelarExecutable,
Upgradable,
Operatable,
ExpressCallHandler,
Pausable,
Multicall
{
contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatable, ExpressCallHandler, Pausable, Multicall {
using StringToBytes32 for string;
using Bytes32ToString for bytes32;
using AddressBytesUtils for bytes;
Expand All @@ -51,6 +43,7 @@ contract InterchainTokenService is
address internal immutable implementationMintBurn;
address internal immutable implementationLockUnlockFee;
address internal immutable implementationLiquidityPool;
IAxelarGateway public immutable gateway;
IAxelarGasService public immutable gasService;
IRemoteAddressValidator public immutable remoteAddressValidator;
address public immutable tokenManagerDeployer;
Expand Down Expand Up @@ -84,13 +77,16 @@ contract InterchainTokenService is
address gasService_,
address remoteAddressValidator_,
address[] memory tokenManagerImplementations
) AxelarExecutable(gateway_) {
) {
if (
remoteAddressValidator_ == address(0) ||
gasService_ == address(0) ||
tokenManagerDeployer_ == address(0) ||
standardizedTokenDeployer_ == address(0)
standardizedTokenDeployer_ == address(0) ||
gateway_ == address(0)
) revert ZeroAddress();

gateway = IAxelarGateway(gateway_);
remoteAddressValidator = IRemoteAddressValidator(remoteAddressValidator_);
gasService = IAxelarGasService(gasService_);
tokenManagerDeployer = tokenManagerDeployer_;
Expand Down Expand Up @@ -530,11 +526,16 @@ contract InterchainTokenService is
* @param sourceAddress The address where the transaction originates from
* @param payload The encoded data payload for the transaction
*/
function _execute(
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) internal override onlyRemoteService(sourceChain, sourceAddress) notPaused {
) external onlyRemoteService(sourceChain, sourceAddress) notPaused {
bytes32 payloadHash = keccak256(payload);

if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, payloadHash)) revert NotApprovedByGateway();

uint256 selector = abi.decode(payload, (uint256));
if (selector == SELECTOR_SEND_TOKEN || selector == SELECTOR_SEND_TOKEN_WITH_DATA) {
_processSendTokenPayload(sourceChain, payload, selector);
Expand All @@ -547,6 +548,17 @@ contract InterchainTokenService is
}
}

function executeWithToken(
bytes32 /*commandId*/,
string calldata /*sourceChain*/,
string calldata /*sourceAddress*/,
bytes calldata /*payload*/,
string calldata /*tokenSymbol*/,
uint256 /*amount*/
) external pure {
revert ExecuteWithTokenNotSupported();
}

/**
* @notice Processes the payload data for a send token call
* @param sourceChain The chain where the transaction originates from
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx
error SelectorUnknown();
error InvalidMetadataVersion(uint32 version);
error AlreadyExecuted(bytes32 commandId);
error ExecuteWithTokenNotSupported();
error InvalidExpressSelector();

event TokenSent(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
Expand Down

0 comments on commit 69cc47e

Please sign in to comment.