Skip to content

Commit

Permalink
rename to gateway caller
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Jul 29, 2024
1 parent d49d008 commit 220e44b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 59 deletions.
53 changes: 29 additions & 24 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IInterchainTokenExecutable } from './interfaces/IInterchainTokenExecuta
import { IInterchainTokenExpressExecutable } from './interfaces/IInterchainTokenExpressExecutable.sol';
import { ITokenManager } from './interfaces/ITokenManager.sol';
import { Create3AddressFixed } from './utils/Create3AddressFixed.sol';
import { CallContract } from './utils/CallContract.sol';
import { GatewayCaller } from './utils/GatewayCaller.sol';

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

Expand Down Expand Up @@ -57,7 +57,7 @@ contract InterchainTokenService is
*/
address public immutable tokenManager;
address public immutable tokenHandler;
address public immutable contractCaller;
address public immutable gatewayCaller;

bytes32 internal constant PREFIX_INTERCHAIN_TOKEN_ID = keccak256('its-interchain-token-id');
bytes32 internal constant PREFIX_INTERCHAIN_TOKEN_SALT = keccak256('its-interchain-token-salt');
Expand Down Expand Up @@ -116,6 +116,7 @@ contract InterchainTokenService is
* @param chainName_ The name of the chain that this contract is deployed on.
* @param tokenManagerImplementation_ The tokenManager implementation.
* @param tokenHandler_ The tokenHandler implementation.
* @param gatewayCaller_ The gatewayCaller implementation.
*/
constructor(
address tokenManagerDeployer_,
Expand All @@ -126,7 +127,7 @@ contract InterchainTokenService is
string memory chainName_,
address tokenManagerImplementation_,
address tokenHandler_,
address contractCaller_
address gatewayCaller_
) {
if (
gasService_ == address(0) ||
Expand All @@ -149,7 +150,7 @@ contract InterchainTokenService is

tokenManager = tokenManagerImplementation_;
tokenHandler = tokenHandler_;
contractCaller = contractCaller_;
gatewayCaller = gatewayCaller_;
}

/*******\
Expand Down Expand Up @@ -831,16 +832,18 @@ contract InterchainTokenService is

if (bytes(destinationAddress).length == 0) revert UntrustedChain();

(bool success, bytes memory returnData) = contractCaller.delegatecall(abi.encodeWithSelector(
CallContract.callContract.selector,
destinationChain,
destinationAddress,
payload,
metadataVersion,
gasValue
));
(bool success, bytes memory returnData) = gatewayCaller.delegatecall(
abi.encodeWithSelector(
GatewayCaller.callContract.selector,
destinationChain,
destinationAddress,
payload,
metadataVersion,
gasValue
)
);

if(!success) revert CallContractFailed(returnData);
if (!success) revert GatewayCallFailed(returnData);
}

/**
Expand Down Expand Up @@ -869,18 +872,20 @@ contract InterchainTokenService is

if (bytes(destinationAddress).length == 0) revert UntrustedChain();

(bool success, bytes memory returnData) = contractCaller.delegatecall(abi.encodeWithSelector(
CallContract.callContractWithToken.selector,
destinationChain,
destinationAddress,
payload,
symbol,
amount,
metadataVersion,
gasValue
));
(bool success, bytes memory returnData) = gatewayCaller.delegatecall(
abi.encodeWithSelector(
GatewayCaller.callContractWithToken.selector,
destinationChain,
destinationAddress,
payload,
symbol,
amount,
metadataVersion,
gasValue
)
);

if(!success) revert CallContractFailed(returnData);
if (!success) revert GatewayCallFailed(returnData);
}

function _execute(
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface IInterchainTokenService is
error CannotDeploy(TokenManagerType);
error InvalidGatewayTokenTransfer(bytes32 tokenId, bytes payload, string tokenSymbol, uint256 amount);
error InvalidPayload();
error CallContractFailed(bytes data);
error GatewayCallFailed(bytes data);

event InterchainTransfer(
bytes32 indexed tokenId,
Expand Down
13 changes: 2 additions & 11 deletions contracts/test/TestInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract TestInterchainTokenService is InterchainTokenService {
string memory chainName_,
address tokenManager_,
address tokenHandler_,
address contractCaller_
address gatewayCaller_
)
InterchainTokenService(
tokenManagerDeployer_,
Expand All @@ -27,7 +27,7 @@ contract TestInterchainTokenService is InterchainTokenService {
chainName_,
tokenManager_,
tokenHandler_,
contractCaller_
gatewayCaller_
)
{
if (LATEST_METADATA_VERSION != uint32(type(MetadataVersion).max))
Expand All @@ -37,13 +37,4 @@ contract TestInterchainTokenService is InterchainTokenService {
function setupTest(bytes calldata params) external {
_setup(params);
}

function callContract(
string calldata destinationChain,
bytes memory payload,
MetadataVersion metadataVersion,
uint256 gasValue
) external payable {
_callContract(destinationChain, payload, metadataVersion, gasValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contr
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';

/**
* @title CallContract contract
* @title GatewayCaller contract
* @notice This contract is used like a library to resolve metadata for the interchain token service
*/
contract CallContract {
contract GatewayCaller {
error UntrustedChain();
error InvalidMetadataVersion(uint32 metadataVersion);

Expand Down
10 changes: 5 additions & 5 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function deployInterchainTokenService(
interchainTokenFactoryAddress,
tokenManagerAddress,
tokenHandlerAddress,
contractCaller,
gatewayCaller,
chainName,
evmChains = [],
deploymentKey,
Expand All @@ -52,7 +52,7 @@ async function deployInterchainTokenService(
chainName,
tokenManagerAddress,
tokenHandlerAddress,
contractCaller,
gatewayCaller,
]);
const proxy = await create3DeployContract(create3DeployerAddress, wallet, Proxy, deploymentKey, [
implementation.address,
Expand Down Expand Up @@ -96,7 +96,7 @@ async function deployAll(
const interchainTokenDeployer = await deployContract(wallet, 'InterchainTokenDeployer', [interchainToken.address]);
const tokenManager = await deployContract(wallet, 'TokenManager', [interchainTokenServiceAddress]);
const tokenHandler = await deployContract(wallet, 'TokenHandler', [gateway.address]);
const contractCaller = await deployContract(wallet, 'CallContract', [gateway.address, gasService.address]);
const gatewayCaller = await deployContract(wallet, 'GatewayCaller', [gateway.address, gasService.address]);

const interchainTokenFactoryAddress = await getCreate3Address(create3Deployer.address, wallet, factoryDeploymentKey);

Expand All @@ -110,7 +110,7 @@ async function deployAll(
interchainTokenFactoryAddress,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
evmChains,
deploymentKey,
Expand All @@ -134,7 +134,7 @@ async function deployAll(
interchainTokenDeployer,
tokenManager,
tokenHandler,
contractCaller,
gatewayCaller,
};
}

Expand Down
22 changes: 11 additions & 11 deletions test/InterchainTokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Interchain Token Service', () => {
let interchainTokenDeployer;
let tokenManager;
let tokenHandler;
let contractCaller;
let gatewayCaller;
let interchainTokenFactoryAddress;
let serviceTest;

Expand Down Expand Up @@ -212,7 +212,7 @@ describe('Interchain Token Service', () => {
interchainTokenDeployer,
tokenManager,
tokenHandler,
contractCaller,
gatewayCaller,
} = await deployAll(wallet, 'Test', [sourceChain, destinationChain]));

testToken = await deployContract(wallet, 'TestInterchainTokenStandard', [
Expand All @@ -233,7 +233,7 @@ describe('Interchain Token Service', () => {
chainName,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
]);
});

Expand Down Expand Up @@ -295,7 +295,7 @@ describe('Interchain Token Service', () => {
AddressZero,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand All @@ -319,7 +319,7 @@ describe('Interchain Token Service', () => {
interchainTokenFactoryAddress,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand All @@ -343,7 +343,7 @@ describe('Interchain Token Service', () => {
interchainTokenFactoryAddress,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
'',
[],
deploymentKey,
Expand All @@ -366,7 +366,7 @@ describe('Interchain Token Service', () => {
interchainTokenFactoryAddress,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand All @@ -388,7 +388,7 @@ describe('Interchain Token Service', () => {
interchainTokenFactoryAddress,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand All @@ -412,7 +412,7 @@ describe('Interchain Token Service', () => {
interchainTokenFactoryAddress,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand All @@ -436,7 +436,7 @@ describe('Interchain Token Service', () => {
interchainTokenFactoryAddress,
AddressZero,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand All @@ -460,7 +460,7 @@ describe('Interchain Token Service', () => {
interchainTokenFactoryAddress,
tokenManager.address,
AddressZero,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand Down
10 changes: 5 additions & 5 deletions test/InterchainTokenServiceUpgradeFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const MINT_BURN = 4;
describe('Interchain Token Service Upgrade Flow', () => {
let wallet, otherWallet, signer;
let service, gateway, gasService;
let tokenManagerDeployer, interchainTokenDeployer, tokenManager, tokenHandler, contractCaller;
let tokenManagerDeployer, interchainTokenDeployer, tokenManager, tokenHandler, gatewayCaller;
let interchainTokenFactoryAddress;

let axelarServiceGovernanceFactory;
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('Interchain Token Service Upgrade Flow', () => {
interchainTokenDeployer = await deployContract(wallet, 'InterchainTokenDeployer', [interchainToken.address]);
tokenManager = await deployContract(wallet, 'TokenManager', [interchainTokenServiceAddress]);
tokenHandler = await deployContract(wallet, 'TokenHandler', [gateway.address]);
contractCaller = await deployContract(wallet, 'CallContract', [gateway.address, gasService.address]);
gatewayCaller = await deployContract(wallet, 'GatewayCaller', [gateway.address, gasService.address]);
interchainTokenFactoryAddress = await getCreate3Address(create3Deployer.address, wallet, deploymentKey + 'Factory');

axelarServiceGovernanceFactory = await ethers.getContractFactory(
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('Interchain Token Service Upgrade Flow', () => {
interchainTokenFactoryAddress,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
chainName,
[],
deploymentKey,
Expand All @@ -130,7 +130,7 @@ describe('Interchain Token Service Upgrade Flow', () => {
chainName,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
]);
const newServiceImplementationCodeHash = await getBytecodeHash(newServiceImplementation);
const setupParams = '0x';
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('Interchain Token Service Upgrade Flow', () => {
chainName,
tokenManager.address,
tokenHandler.address,
contractCaller.address,
gatewayCaller.address,
]);
const newServiceImplementationCodeHash = await getBytecodeHash(newServiceImplementation);
const setupParams = '0x';
Expand Down

0 comments on commit 220e44b

Please sign in to comment.