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

refactor!: implement AxelarExecutable and AxelarExecutableWithToken in ITS #274

Merged
merged 27 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
37 changes: 25 additions & 12 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ contract InterchainTokenService is
using AddressBytes for bytes;
using AddressBytes for address;

IAxelarGMPGatewayWithToken public immutable gatewayAddress;
/**
* @dev Axelar GMP Gateway for cross-chain messaging.
* Two available approaches:
ahramy marked this conversation as resolved.
Show resolved Hide resolved
* 1. Pure GMP: Uses IAxelarGMPGateway to handle messaging without token transfers, compatible across Amplifier chains.
ahramy marked this conversation as resolved.
Show resolved Hide resolved
* 2. GMP with Token: Legacy functionality. Explicitly cast to IAxelarGMPGatewayWithToken when needed.
* This approach only functions on chains that rely on Axelar consensus Connection.
ahramy marked this conversation as resolved.
Show resolved Hide resolved
*/
IAxelarGMPGateway public immutable gateway;
IAxelarGasService public immutable gasService;
address public immutable interchainTokenFactory;
bytes32 public immutable chainNameHash;
Expand Down Expand Up @@ -136,7 +143,7 @@ contract InterchainTokenService is
gatewayCaller_ == address(0)
) revert ZeroAddress();

gatewayAddress = IAxelarGMPGatewayWithToken(gateway_);
gateway = IAxelarGMPGateway(gateway_);
gasService = IAxelarGasService(gasService_);
tokenManagerDeployer = tokenManagerDeployer_;
interchainTokenDeployer = interchainTokenDeployer_;
Expand Down Expand Up @@ -383,7 +390,7 @@ contract InterchainTokenService is
revert InvalidExpressMessageType(messageType);
}

if (gatewayAddress.isCommandExecuted(commandId)) revert AlreadyExecuted();
if (gateway.isCommandExecuted(commandId)) revert AlreadyExecuted();

address expressExecutor = msg.sender;
bytes32 payloadHash = keccak256(payload);
Expand Down Expand Up @@ -637,7 +644,7 @@ contract InterchainTokenService is
) external onlyRemoteService(sourceChain, sourceAddress) whenNotPaused {
bytes32 payloadHash = keccak256(payload);

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

_execute(commandId, sourceChain, sourceAddress, payload, payloadHash);
ahramy marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -707,8 +714,10 @@ contract InterchainTokenService is
function _checkPayloadAgainstGatewayData(bytes memory payload, string calldata tokenSymbol, uint256 amount) internal view {
(, bytes32 tokenId, , , uint256 amountInPayload) = abi.decode(payload, (uint256, bytes32, uint256, uint256, uint256));

if (validTokenAddress(tokenId) != gatewayAddress.tokenAddresses(tokenSymbol) || amount != amountInPayload)
revert InvalidGatewayTokenTransfer(tokenId, payload, tokenSymbol, amount);
if (
validTokenAddress(tokenId) != IAxelarGMPGatewayWithToken(address(gateway)).tokenAddresses(tokenSymbol) ||
ahramy marked this conversation as resolved.
Show resolved Hide resolved
amount != amountInPayload
) revert InvalidGatewayTokenTransfer(tokenId, payload, tokenSymbol, amount);
}

/**
Expand Down Expand Up @@ -930,8 +939,16 @@ contract InterchainTokenService is
) internal {
bytes32 payloadHash = keccak256(payload);

if (!gatewayAddress.validateContractCallAndMint(commandId, sourceChain, sourceAddress, payloadHash, tokenSymbol, amount))
revert NotApprovedByGateway();
if (
!IAxelarGMPGatewayWithToken(address(gateway)).validateContractCallAndMint(
commandId,
sourceChain,
sourceAddress,
payloadHash,
tokenSymbol,
amount
)
) revert NotApprovedByGateway();

uint256 messageType;
string memory originalSourceChain;
Expand Down Expand Up @@ -1237,8 +1254,4 @@ contract InterchainTokenService is
emit ExpressExecutionFulfilled(commandId, sourceChain, sourceAddress, payloadHash, expressExecutor);
}
}

function gateway() external view override returns (IAxelarGMPGateway) {
return IAxelarGMPGateway(gatewayAddress);
}
}
7 changes: 4 additions & 3 deletions contracts/utils/GatewayCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity ^0.8.0;

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

Expand All @@ -11,7 +12,7 @@ import { IGatewayCaller } from '../interfaces/IGatewayCaller.sol';
* @dev This contract is used to handle cross-chain ITS calls via the Axelar gateway.
*/
contract GatewayCaller is IGatewayCaller {
IAxelarGMPGatewayWithToken public immutable gateway;
IAxelarGMPGateway public immutable gateway;
IAxelarGasService public immutable gasService;

/**
Expand All @@ -20,7 +21,7 @@ contract GatewayCaller is IGatewayCaller {
* @param gasService_ The address of the AxelarGasService contract
*/
constructor(address gateway_, address gasService_) {
gateway = IAxelarGMPGatewayWithToken(gateway_);
gateway = IAxelarGMPGateway(gateway_);
gasService = IAxelarGasService(gasService_);
}

Expand Down Expand Up @@ -117,6 +118,6 @@ contract GatewayCaller is IGatewayCaller {
}
}

gateway.callContractWithToken(destinationChain, destinationAddress, payload, symbol, amount);
IAxelarGMPGatewayWithToken(address(gateway)).callContractWithToken(destinationChain, destinationAddress, payload, symbol, amount);
}
}
8 changes: 4 additions & 4 deletions test/InterchainTokenServiceUpgradeFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Create3Deployer = getContractJSON('Create3Deployer');
const MINT_BURN = 4;

describe('Interchain Token Service Upgrade Flow', () => {
let wallet, otherWallet, multisig;
let wallet, otherWallet, operator;
let service, gateway, gasService;
let tokenManagerDeployer, interchainTokenDeployer, tokenManager, tokenHandler, gatewayCaller;
let interchainTokenFactoryAddress;
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('Interchain Token Service Upgrade Flow', () => {
}

before(async () => {
[wallet, otherWallet, multisig] = await ethers.getSigners();
[wallet, otherWallet, operator] = await ethers.getSigners();
governanceAddress = otherWallet.address;

buffer = isHardhat ? 10 * 60 * 60 : 10;
Expand All @@ -85,7 +85,7 @@ describe('Interchain Token Service Upgrade Flow', () => {
);

axelarServiceGovernance = await axelarServiceGovernanceFactory
.deploy(gateway.address, governanceChain, governanceAddress, minimumTimeDelay, multisig.address)
.deploy(gateway.address, governanceChain, governanceAddress, minimumTimeDelay, operator.address)
ahramy marked this conversation as resolved.
Show resolved Hide resolved
.then((d) => d.deployed());

service = await deployInterchainTokenService(
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Interchain Token Service Upgrade Flow', () => {
.to.emit(axelarServiceGovernance, 'MultisigApproved')
.withArgs(proposalHash, target, calldata, nativeValue);

await expect(axelarServiceGovernance.connect(multisig).executeMultisigProposal(target, calldata, nativeValue))
await expect(axelarServiceGovernance.connect(operator).executeMultisigProposal(target, calldata, nativeValue))
.to.emit(axelarServiceGovernance, 'MultisigExecuted')
.withArgs(proposalHash, target, calldata, nativeValue)
.and.to.emit(service, 'Upgraded')
Expand Down
Loading