From 9688abf363cdd1cc37ebdc2911241e24cc2badbe Mon Sep 17 00:00:00 2001 From: Milap Sheth Date: Wed, 6 Dec 2023 03:37:38 -0500 Subject: [PATCH] refactor: remove ITS interface dep in BaseInterchainToken --- contracts/InterchainTokenService.sol | 10 ++++---- .../interchain-token/BaseInterchainToken.sol | 24 +++++++++++++------ .../interchain-token/InterchainToken.sol | 3 +-- .../interfaces/IInterchainTokenService.sol | 23 +++--------------- .../interfaces/IInterchainTokenStandard.sol | 5 ++-- 5 files changed, 28 insertions(+), 37 deletions(-) diff --git a/contracts/InterchainTokenService.sol b/contracts/InterchainTokenService.sol index df992e41..34f629ce 100644 --- a/contracts/InterchainTokenService.sol +++ b/contracts/InterchainTokenService.sol @@ -449,7 +449,7 @@ contract InterchainTokenService is * @param destinationChain The destination chain to send the tokens to. * @param destinationAddress The address on the destination chain to send the tokens to. * @param amount The amount of tokens to be transferred. - * @param metadata Additional data to be passed along with the transfer. If provided with a bytes4(0) version prefix, it will execute the destination contract. + * @param metadata Optional metadata for the call for additional effects (such as calling a destination contract). */ function interchainTransfer( bytes32 tokenId, @@ -491,13 +491,13 @@ contract InterchainTokenService is /** * @notice Transmit an interchain transfer for the given tokenId. - * @dev Only callable by a token registered under tokenId. - * @param tokenId The tokenId of the TokenManager (which must be the msg.sender). - * @param sourceAddress The address where the token is coming from, which will also be used for reimbursement of gas. + * @dev Only callable by a token registered under a tokenId. + * @param tokenId The tokenId of the token (which must be the msg.sender). + * @param sourceAddress The address where the token is coming from. * @param destinationChain The name of the chain to send tokens to. * @param destinationAddress The destinationAddress for the interchainTransfer. * @param amount The amount of token to give. - * @param metadata The data to be passed to the destination. + * @param metadata Optional metadata for the call for additional effects (such as calling a destination contract). */ function transmitInterchainTransfer( bytes32 tokenId, diff --git a/contracts/interchain-token/BaseInterchainToken.sol b/contracts/interchain-token/BaseInterchainToken.sol index 251f2268..233a6caa 100644 --- a/contracts/interchain-token/BaseInterchainToken.sol +++ b/contracts/interchain-token/BaseInterchainToken.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import { IInterchainTokenStandard } from '../interfaces/IInterchainTokenStandard.sol'; -import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol'; +import { ITransmitInterchainToken } from '../interfaces/ITransmitInterchainToken.sol'; /** * @title An example implementation of the IInterchainTokenStandard. @@ -44,9 +44,14 @@ abstract contract BaseInterchainToken is IInterchainTokenStandard { _beforeInterchainTransfer(msg.sender, destinationChain, recipient, amount, metadata); - IInterchainTokenService service = IInterchainTokenService(interchainTokenService()); - - service.transmitInterchainTransfer{ value: msg.value }(interchainTokenId(), sender, destinationChain, recipient, amount, metadata); + ITransmitInterchainToken(interchainTokenService()).transmitInterchainTransfer{ value: msg.value }( + interchainTokenId(), + sender, + destinationChain, + recipient, + amount, + metadata + ); } /** @@ -70,9 +75,14 @@ abstract contract BaseInterchainToken is IInterchainTokenStandard { _beforeInterchainTransfer(sender, destinationChain, recipient, amount, metadata); - IInterchainTokenService service = IInterchainTokenService(interchainTokenService()); - - service.transmitInterchainTransfer{ value: msg.value }(interchainTokenId(), sender, destinationChain, recipient, amount, metadata); + ITransmitInterchainToken(interchainTokenService()).transmitInterchainTransfer{ value: msg.value }( + interchainTokenId(), + sender, + destinationChain, + recipient, + amount, + metadata + ); } /** diff --git a/contracts/interchain-token/InterchainToken.sol b/contracts/interchain-token/InterchainToken.sol index bbcbcdc5..1a3de5f5 100644 --- a/contracts/interchain-token/InterchainToken.sol +++ b/contracts/interchain-token/InterchainToken.sol @@ -7,7 +7,6 @@ import { AddressBytes } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/ import { IInterchainToken } from '../interfaces/IInterchainToken.sol'; import { BaseInterchainToken } from './BaseInterchainToken.sol'; -import { ERC20 } from './ERC20.sol'; import { ERC20Permit } from './ERC20Permit.sol'; import { Minter } from '../utils/Minter.sol'; @@ -16,7 +15,7 @@ import { Minter } from '../utils/Minter.sol'; * @notice This contract implements an interchain token which extends InterchainToken functionality. * @dev This contract also inherits Minter and Implementation logic. */ -contract InterchainToken is BaseInterchainToken, ERC20, ERC20Permit, Minter, IInterchainToken { +contract InterchainToken is BaseInterchainToken, ERC20Permit, Minter, IInterchainToken { using AddressBytes for bytes; string public name; diff --git a/contracts/interfaces/IInterchainTokenService.sol b/contracts/interfaces/IInterchainTokenService.sol index f14d2d2f..a1560896 100644 --- a/contracts/interfaces/IInterchainTokenService.sol +++ b/contracts/interfaces/IInterchainTokenService.sol @@ -7,6 +7,7 @@ import { IContractIdentifier } from '@axelar-network/axelar-gmp-sdk-solidity/con import { IMulticall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IMulticall.sol'; import { IPausable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IPausable.sol'; +import { ITransmitInterchainToken } from './ITransmitInterchainToken.sol'; import { ITokenManagerType } from './ITokenManagerType.sol'; import { ITokenManagerImplementation } from './ITokenManagerImplementation.sol'; import { IAddressTracker } from './IAddressTracker.sol'; @@ -16,6 +17,7 @@ import { IAddressTracker } from './IAddressTracker.sol'; * @notice Interface for the Interchain Token Service */ interface IInterchainTokenService is + ITransmitInterchainToken, ITokenManagerType, ITokenManagerImplementation, IAxelarValuedExpressExecutable, @@ -193,7 +195,7 @@ interface IInterchainTokenService is * @param destinationChain The destination chain to send the tokens to. * @param destinationAddress The address on the destination chain to send the tokens to. * @param amount The amount of tokens to be transferred. - * @param metadata Additional metadata to be passed along with the transfer. + * @param metadata Optional metadata for the call for additional effects (such as calling a destination contract). */ function interchainTransfer( bytes32 tokenId, @@ -219,25 +221,6 @@ interface IInterchainTokenService is bytes calldata data ) external payable; - /** - * @notice Initiates an interchain token transfer. - * @dev Only callable by TokenManagers. - * @param tokenId The tokenId of the token to be transmitted. - * @param sourceAddress The source address of the token. - * @param destinationChain The name of the destination chain. - * @param destinationAddress The destination address on the destination chain. - * @param amount The amount of tokens to transmit. - * @param metadata The metadata associated with the transmission. - */ - function transmitInterchainTransfer( - bytes32 tokenId, - address sourceAddress, - string calldata destinationChain, - bytes memory destinationAddress, - uint256 amount, - bytes calldata metadata - ) external payable; - /** * @notice Sets the flow limits for multiple tokens. * @param tokenIds An array of tokenIds. diff --git a/contracts/interfaces/IInterchainTokenStandard.sol b/contracts/interfaces/IInterchainTokenStandard.sol index 089e8ef1..6b641df1 100644 --- a/contracts/interfaces/IInterchainTokenStandard.sol +++ b/contracts/interfaces/IInterchainTokenStandard.sol @@ -14,8 +14,7 @@ interface IInterchainTokenStandard { * @param destinationChain The destination chain identifier. * @param recipient The bytes representation of the address of the recipient. * @param amount The amount of token to be transferred. - * @param metadata Either empty, to just facilitate an interchain transfer, or the data can be passed for an interchain contract - * call with transfer as per semantics defined by the token service. + * @param metadata Optional metadata for the call for additional effects (such as calling a destination contract). */ function interchainTransfer( string calldata destinationChain, @@ -32,7 +31,7 @@ interface IInterchainTokenStandard { * @param destinationChain The string representation of the destination chain. * @param recipient The bytes representation of the address of the recipient. * @param amount The amount of token to be transferred. - * @param metadata Either empty, to just facilitate an interchain transfer, or the data to be passed to an interchain contract call and transfer. + * @param metadata Optional metadata for the call for additional effects (such as calling a destination contract.) */ function interchainTransferFrom( address sender,