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

feat: using a custom implementation of AxelarExecutable #114

Merged
merged 4 commits into from
Oct 9, 2023
Merged
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
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
Loading