Skip to content

Commit

Permalink
feat: removed operator from interchain token payload (#149)
Browse files Browse the repository at this point in the history
* removed operator from interchain token payload

* added a small fix

* Update contracts/InterchainTokenFactory.sol

---------

Co-authored-by: Milap Sheth <[email protected]>
  • Loading branch information
Foivos and milapsheth authored Nov 4, 2023
1 parent 334398f commit 237907e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 131 deletions.
24 changes: 9 additions & 15 deletions contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
string calldata symbol,
uint8 decimals,
uint256 mintAmount,
address distributor,
address operator
address distributor
) external payable {
address sender = msg.sender;
salt = interchainTokenSalt(chainNameHash, sender, salt);
Expand All @@ -80,29 +79,32 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
distributorBytes = distributor.toBytes();
}

_deployInterchainToken(salt, '', name, symbol, decimals, distributorBytes, operator.toBytes(), 0);
_deployInterchainToken(salt, '', name, symbol, decimals, distributorBytes, 0);

if (mintAmount > 0) {
bytes32 tokenId = service.interchainTokenId(address(this), salt);
IInterchainToken token = IInterchainToken(service.interchainTokenAddress(tokenId));
token.mint(address(this), mintAmount);
token.transferDistributorship(distributor);

ITokenManager tokenManager = ITokenManager(service.tokenManagerAddress(tokenId));
tokenManager.removeFlowLimiter(address(this));
if (distributor != address(0)) tokenManager.addFlowLimiter(distributor);
tokenManager.transferOperatorship(distributor);
}
}

function deployRemoteInterchainToken(
string calldata originalChainName,
bytes32 salt,
address additionalDistributor,
address optionalOperator,
string memory destinationChain,
uint256 gasValue
) external payable {
string memory tokenName;
string memory tokenSymbol;
uint8 tokenDecimals;
bytes memory distributor = new bytes(0);
bytes memory operator = new bytes(0);

{
bytes32 chainNameHash_;
Expand All @@ -116,7 +118,6 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
bytes32 tokenId = service.interchainTokenId(address(this), salt);

IInterchainToken token = IInterchainToken(service.interchainTokenAddress(tokenId));
ITokenManager tokenManager = ITokenManager(service.tokenManagerAddress(tokenId));

tokenName = token.name();
tokenSymbol = token.symbol();
Expand All @@ -125,14 +126,9 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
if (!token.isDistributor(additionalDistributor)) revert NotDistributor(additionalDistributor);
distributor = additionalDistributor.toBytes();
}

if (optionalOperator != address(0)) {
if (!tokenManager.isOperator(optionalOperator)) revert NotOperator(optionalOperator);
operator = optionalOperator.toBytes();
}
}

_deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, distributor, operator, gasValue);
_deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, distributor, gasValue);
}

function _deployInterchainToken(
Expand All @@ -142,7 +138,6 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
string memory tokenSymbol,
uint8 tokenDecimals,
bytes memory distributor,
bytes memory operator,
uint256 gasValue
) internal {
// slither-disable-next-line arbitrary-send-eth
Expand All @@ -153,7 +148,6 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
tokenSymbol,
tokenDecimals,
distributor,
operator,
gasValue
);
}
Expand Down Expand Up @@ -191,7 +185,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
string memory tokenSymbol = token.symbol();
uint8 tokenDecimals = token.decimals();

_deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, '', '', gasValue);
_deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, '', gasValue);
}

function interchainTransfer(
Expand Down
25 changes: 9 additions & 16 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,16 @@ contract InterchainTokenService is
string memory symbol,
uint8 decimals,
bytes memory distributor,
bytes memory operator,
uint256 gasValue
) external payable whenNotPaused {
bytes32 tokenId = interchainTokenId(msg.sender, salt);

if (bytes(destinationChain).length == 0) {
address tokenAddress_ = _deployInterchainToken(tokenId, distributor, name, symbol, decimals);

_deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(operator, tokenAddress_));
_deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(distributor, tokenAddress_));
} else {
_deployRemoteInterchainToken(tokenId, name, symbol, decimals, distributor, operator, destinationChain, gasValue);
_deployRemoteInterchainToken(tokenId, name, symbol, decimals, distributor, destinationChain, gasValue);
}
}

Expand Down Expand Up @@ -642,20 +641,15 @@ contract InterchainTokenService is
* @param payload The encoded data payload to be processed
*/
function _processDeployInterchainTokenPayload(bytes calldata payload) internal {
(
,
bytes32 tokenId,
string memory name,
string memory symbol,
uint8 decimals,
bytes memory distributorBytes,
bytes memory operatorBytes
) = abi.decode(payload, (uint256, bytes32, string, string, uint8, bytes, bytes));
(, bytes32 tokenId, string memory name, string memory symbol, uint8 decimals, bytes memory distributorBytes) = abi.decode(
payload,
(uint256, bytes32, string, string, uint8, bytes)
);
address tokenAddress_;

tokenAddress_ = _deployInterchainToken(tokenId, distributorBytes, name, symbol, decimals);

_deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(operatorBytes, tokenAddress_));
_deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(distributorBytes, tokenAddress_));
}

/**
Expand Down Expand Up @@ -722,17 +716,16 @@ contract InterchainTokenService is
string memory symbol,
uint8 decimals,
bytes memory distributor,
bytes memory operator,
string calldata destinationChain,
uint256 gasValue
) internal {
// slither-disable-next-line unused-return
validTokenManagerAddress(tokenId);

// slither-disable-next-line reentrancy-events
emit InterchainTokenDeploymentStarted(tokenId, name, symbol, decimals, distributor, operator, destinationChain);
emit InterchainTokenDeploymentStarted(tokenId, name, symbol, decimals, distributor, destinationChain);

bytes memory payload = abi.encode(MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, name, symbol, decimals, distributor, operator);
bytes memory payload = abi.encode(MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, name, symbol, decimals, distributor);

_callContract(destinationChain, payload, gasValue);
}
Expand Down
4 changes: 1 addition & 3 deletions contracts/interfaces/IInterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ interface IInterchainTokenFactory {
string calldata symbol,
uint8 decimals,
uint256 mintAmount,
address distributor,
address operator
address distributor
) external payable;

function deployRemoteInterchainToken(
string calldata originalChainName,
bytes32 salt,
address additionalDistributor,
address optionalOperator,
string memory destinationChain,
uint256 gasValue
) external payable;
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ interface IInterchainTokenService is
string tokenSymbol,
uint8 tokenDecimals,
bytes distributor,
bytes operator,
string destinationChain
);
event TokenManagerDeployed(bytes32 indexed tokenId, address tokenManager, TokenManagerType indexed tokenManagerType, bytes params);
Expand Down Expand Up @@ -172,7 +171,6 @@ interface IInterchainTokenService is
string memory symbol,
uint8 decimals,
bytes memory distributor,
bytes memory operator,
uint256 gasValue
) external payable;

Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/ITokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ interface ITokenManager is ITokenManagerType, IOperatable, IFlowLimit, IImplemen
*/
function takeToken(address sourceAddress, uint256 amount) external returns (uint256);

/**
* @notice This function adds a flow limiter for this TokenManager. Can only be called by the operator.
* @param flowLimiter the address of the new flow limiter.
*/
function addFlowLimiter(address flowLimiter) external;

/**
* @notice This function removes a flow limiter for this TokenManager. Can only be called by the operator.
* @param flowLimiter the address of an existing flow limiter.
*/
function removeFlowLimiter(address flowLimiter) external;

/**
* @notice This function sets the flow limit for this TokenManager. Can only be called by the operator.
* @param flowLimit_ the maximum difference between the tokens flowing in and/or out at any given interval of time (6h)
Expand Down
Loading

0 comments on commit 237907e

Please sign in to comment.