// Source: contracts/executable/InterchainTokenExecutable.sol pragma solidity ^0.8.0; // SPDX-License-Identifier: MIT // File contracts/interfaces/IInterchainTokenExecutable.sol /** * @title IInterchainTokenExecutable * @notice Contracts should implement this interface to accept calls from the InterchainTokenService. */ interface IInterchainTokenExecutable { /** * @notice This will be called after the tokens are sent to this contract. * @dev Execution should revert unless the msg.sender is the InterchainTokenService * @param commandId The unique message id for the call. * @param sourceChain The name of the source chain. * @param sourceAddress The address that sent the contract call. * @param data The data to be processed. * @param tokenId The tokenId of the token manager managing the token. * @param token The address of the token. * @param amount The amount of tokens that were sent. * @return bytes32 Hash indicating success of the execution. */ function executeWithInterchainToken( bytes32 commandId, string calldata sourceChain, bytes calldata sourceAddress, bytes calldata data, bytes32 tokenId, address token, uint256 amount ) external returns (bytes32); } // File contracts/executable/InterchainTokenExecutable.sol /** * @title InterchainTokenExecutable * @notice Abstract contract that defines an interface for executing arbitrary logic * in the context of interchain token operations. * @dev This contract should be inherited by contracts that intend to execute custom * logic in response to interchain token actions such as transfers. This contract * will only be called by the interchain token service. */ abstract contract InterchainTokenExecutable is IInterchainTokenExecutable { error NotService(address caller); address public immutable interchainTokenService; bytes32 internal constant EXECUTE_SUCCESS = keccak256('its-execute-success'); /** * @notice Creates a new InterchainTokenExecutable contract. * @param interchainTokenService_ The address of the interchain token service that will call this contract. */ constructor(address interchainTokenService_) { interchainTokenService = interchainTokenService_; } /** * Modifier to restrict function execution to the interchain token service. */ modifier onlyService() { if (msg.sender != interchainTokenService) revert NotService(msg.sender); _; } /** * @notice Executes logic in the context of an interchain token transfer. * @dev Only callable by the interchain token service. * @param commandId The unique message id. * @param sourceChain The source chain of the token transfer. * @param sourceAddress The source address of the token transfer. * @param data The data associated with the token transfer. * @param tokenId The token ID. * @param token The token address. * @param amount The amount of tokens being transferred. * @return bytes32 Hash indicating success of the execution. */ function executeWithInterchainToken( bytes32 commandId, string calldata sourceChain, bytes calldata sourceAddress, bytes calldata data, bytes32 tokenId, address token, uint256 amount ) external virtual onlyService returns (bytes32) { _executeWithInterchainToken(commandId, sourceChain, sourceAddress, data, tokenId, token, amount); return EXECUTE_SUCCESS; } /** * @notice Internal function containing the logic to be executed with interchain token transfer. * @dev Logic must be implemented by derived contracts. * @param commandId The unique message id. * @param sourceChain The source chain of the token transfer. * @param sourceAddress The source address of the token transfer. * @param data The data associated with the token transfer. * @param tokenId The token ID. * @param token The token address. * @param amount The amount of tokens being transferred. */ function _executeWithInterchainToken( bytes32 commandId, string calldata sourceChain, bytes calldata sourceAddress, bytes calldata data, bytes32 tokenId, address token, uint256 amount ) internal virtual; }