-
Notifications
You must be signed in to change notification settings - Fork 0
Hedera ITS / Diff #1
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
base: main
Are you sure you want to change the base?
Changes from 21 commits
5075a45
386f43a
3e6fe1f
374103f
7964a79
414c13b
ab88ce0
a8b20e3
707e7c1
5c6cb05
b133129
9face17
a11e2fb
7dafa59
98985c2
a959b48
f7c81fb
7f25371
f477f74
64037cc
e1dbb8e
ab13603
2e83bc7
da7fc66
b121dd2
a64202d
2ecb8e0
ffd885d
c311f20
0e48ce6
e67e868
7fec126
123e921
35719b8
b97bb76
6bdd53e
84130d1
2198e27
acfaf20
1088024
01ac902
b04a129
70c2fed
4a934f6
cdc6e99
73bb1b7
5666515
1806536
c6fda17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,11 @@ import { IMinter } from './interfaces/IMinter.sol'; | |
import { Create3AddressFixed } from './utils/Create3AddressFixed.sol'; | ||
import { Operator } from './utils/Operator.sol'; | ||
import { ChainTracker } from './utils/ChainTracker.sol'; | ||
import { TokenCreationPricing } from './utils/TokenCreationPricing.sol'; | ||
import { ItsHubAddressTracker } from './utils/ItsHubAddressTracker.sol'; | ||
|
||
import { IWHBAR } from './hedera/IWHBAR.sol'; | ||
|
||
/** | ||
* @title The Interchain Token Service | ||
* @notice This contract is responsible for facilitating interchain token transfers. | ||
|
@@ -42,6 +45,7 @@ contract InterchainTokenService is | |
ExpressExecutorTracker, | ||
InterchainAddressTracker, | ||
ChainTracker, | ||
TokenCreationPricing, | ||
ItsHubAddressTracker, | ||
IInterchainTokenService | ||
{ | ||
|
@@ -236,17 +240,6 @@ contract InterchainTokenService is | |
tokenAddress = ITokenManager(deployedTokenManager(tokenId)).tokenAddress(); | ||
} | ||
|
||
/** | ||
* @notice Returns the address of the interchain token associated with the given tokenId. | ||
* @dev The token does not need to exist. | ||
* @param tokenId The tokenId of the interchain token. | ||
* @return tokenAddress The address of the interchain token. | ||
*/ | ||
function interchainTokenAddress(bytes32 tokenId) public view returns (address tokenAddress) { | ||
tokenId = _getInterchainTokenSalt(tokenId); | ||
tokenAddress = _create3Address(tokenId); | ||
} | ||
|
||
/** | ||
* @notice Calculates the tokenId that would correspond to a link for a given deployer with a specified salt. | ||
* @param sender The address of the TokenManager deployer. | ||
|
@@ -404,9 +397,7 @@ contract InterchainTokenService is | |
emit InterchainTokenIdClaimed(tokenId, deployer, salt); | ||
|
||
if (bytes(destinationChain).length == 0) { | ||
address tokenAddress = _deployInterchainToken(tokenId, minter, name, symbol, decimals); | ||
|
||
_deployTokenManager(tokenId, TokenManagerType.NATIVE_INTERCHAIN_TOKEN, tokenAddress, minter); | ||
_deployTokenManagerWithInterchainToken(tokenId, name, symbol, decimals, minter); | ||
} else { | ||
if (chainNameHash == keccak256(bytes(destinationChain))) revert CannotDeployRemotelyToSelf(); | ||
|
||
|
@@ -575,35 +566,6 @@ contract InterchainTokenService is | |
_interchainTransfer(tokenId, destinationChain, destinationAddress, amount, data, gasValue); | ||
} | ||
|
||
/******************\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Custom tokens should still be able to use this so probably do not remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted the removal. |
||
TOKEN ONLY FUNCTIONS | ||
\******************/ | ||
|
||
/** | ||
* @notice Transmit an interchain transfer for the given tokenId. | ||
* @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 Optional metadata for the call for additional effects (such as calling a destination contract). | ||
*/ | ||
function transmitInterchainTransfer( | ||
bytes32 tokenId, | ||
address sourceAddress, | ||
string calldata destinationChain, | ||
bytes memory destinationAddress, | ||
uint256 amount, | ||
bytes calldata metadata | ||
) external payable whenNotPaused { | ||
amount = _takeToken(tokenId, sourceAddress, amount, true); | ||
|
||
bytes memory data = _decodeMetadata(metadata); | ||
|
||
_transmitInterchainTransfer(tokenId, sourceAddress, destinationChain, destinationAddress, amount, data, msg.value); | ||
} | ||
|
||
/*************\ | ||
OWNER FUNCTIONS | ||
\*************/ | ||
|
@@ -639,6 +601,22 @@ contract InterchainTokenService is | |
_removeTrustedChain(chainName); | ||
} | ||
|
||
/** | ||
* @notice Used to set the token creation price in tinycents. | ||
* @param price The new token creation price in tinycents. | ||
*/ | ||
function setTokenCreationPrice(uint256 price) external onlyOperatorOrOwner { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: Why cast to u8 in onlyOperatorOrOwner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you ask about the I'll leave the convo open in case you meant something else. |
||
_setTokenCreationPrice(price); | ||
} | ||
|
||
/** | ||
* @notice Used to set the WHBAR contract address. | ||
* @param whbarAddress_ The new WHBAR contract address. | ||
*/ | ||
function setWhbarAddress(address whbarAddress_) external onlyOperatorOrOwner { | ||
|
||
_setWhbarAddress(whbarAddress_); | ||
} | ||
|
||
/** | ||
* @notice Allows the owner to pause/unpause the token service. | ||
* @param paused Boolean value representing whether to pause or unpause. | ||
|
@@ -651,22 +629,15 @@ contract InterchainTokenService is | |
} | ||
} | ||
|
||
/** | ||
* @notice Allows the owner to migrate minter of native interchain tokens from ITS to the corresponding token manager. | ||
* @param tokenId the tokenId of the registered token. | ||
*/ | ||
function migrateInterchainToken(bytes32 tokenId) external onlyOwner { | ||
ITokenManager tokenManager_ = deployedTokenManager(tokenId); | ||
address tokenAddress = tokenManager_.tokenAddress(); | ||
IMinter(tokenAddress).transferMintership(address(tokenManager_)); | ||
} | ||
|
||
/****************\ | ||
INTERNAL FUNCTIONS | ||
\****************/ | ||
|
||
function _setup(bytes calldata params) internal override { | ||
(address operator, string memory chainName_, string[] memory trustedChainNames) = abi.decode(params, (address, string, string[])); | ||
(address operator, string memory chainName_, string[] memory trustedChainNames, uint256 _tokenCreationPrice) = abi.decode( | ||
params, | ||
(address, string, string[], uint256) | ||
); | ||
if (operator == address(0)) revert ZeroAddress(); | ||
if (bytes(chainName_).length == 0 || keccak256(bytes(chainName_)) != chainNameHash) revert InvalidChainName(); | ||
|
||
|
@@ -682,6 +653,8 @@ contract InterchainTokenService is | |
_removeTrustedAddress(trustedChainName); | ||
} | ||
} | ||
|
||
_setTokenCreationPrice(_tokenCreationPrice); | ||
} | ||
|
||
/** | ||
|
@@ -767,11 +740,8 @@ contract InterchainTokenService is | |
payload, | ||
(uint256, bytes32, string, string, uint8, bytes) | ||
); | ||
address tokenAddress; | ||
|
||
tokenAddress = _deployInterchainToken(tokenId, minterBytes, name, symbol, decimals); | ||
|
||
_deployTokenManager(tokenId, TokenManagerType.NATIVE_INTERCHAIN_TOKEN, tokenAddress, minterBytes); | ||
_deployTokenManagerWithInterchainToken(tokenId, name, symbol, decimals, minterBytes); | ||
} | ||
|
||
/** | ||
|
@@ -970,6 +940,58 @@ contract InterchainTokenService is | |
_routeMessage(destinationChain, payload, gasValue); | ||
} | ||
|
||
/** | ||
* @notice Deploys a token manager. | ||
* @param tokenId The ID of the token. | ||
rista404 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param operator The operator of the token manager. | ||
*/ | ||
function _deployTokenManagerWithInterchainToken( | ||
bytes32 tokenId, | ||
string memory name, | ||
string memory symbol, | ||
uint8 decimals, | ||
bytes memory operator | ||
) internal { | ||
// Price in tinybars | ||
uint256 tokenCreatePrice = _tokenCreationPriceTinybars(); | ||
|
||
// TokenManagerProxy deploy params | ||
bytes memory params = abi.encode(operator, name, symbol, decimals, tokenCreatePrice); | ||
|
||
TokenManagerType tokenManagerType = TokenManagerType.NATIVE_INTERCHAIN_TOKEN; | ||
|
||
// Get the pre-determined token manager address | ||
address tokenManager_ = tokenManagerAddress(tokenId); | ||
|
||
// Approve the token manager deployer to spend the token creation price | ||
IWHBAR(whbarAddress()).approve(tokenManager_, tokenCreatePrice); | ||
rista404 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
(bool success, bytes memory returnData) = tokenManagerDeployer.delegatecall( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if can delegatecall |
||
abi.encodeWithSelector(ITokenManagerDeployer.deployTokenManager.selector, tokenId, tokenManagerType, params) | ||
); | ||
if (!success) revert TokenManagerDeploymentFailed(returnData); | ||
|
||
assembly { | ||
tokenManager_ := mload(add(returnData, 0x20)) | ||
} | ||
|
||
(success, returnData) = tokenHandler.delegatecall( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if can delegatecall |
||
abi.encodeWithSelector(ITokenHandler.postTokenManagerDeploy.selector, tokenManagerType, tokenManager_) | ||
); | ||
if (!success) revert PostDeployFailed(returnData); | ||
|
||
// Get the token address from the deployed token manager | ||
address tokenAddress = ITokenManager(tokenManager_).tokenAddress(); | ||
|
||
address minter; | ||
if (bytes(operator).length != 0) minter = operator.toAddress(); | ||
|
||
// slither-disable-next-line reentrancy-events | ||
emit InterchainTokenDeployed(tokenId, tokenAddress, minter, name, symbol, decimals); | ||
// slither-disable-next-line reentrancy-events | ||
emit TokenManagerDeployed(tokenId, tokenManager_, tokenManagerType, params); | ||
} | ||
|
||
/** | ||
* @notice Deploys a token manager. | ||
* @param tokenId The ID of the token. | ||
|
@@ -1009,44 +1031,6 @@ contract InterchainTokenService is | |
salt = keccak256(abi.encode(PREFIX_INTERCHAIN_TOKEN_SALT, tokenId)); | ||
} | ||
|
||
/** | ||
* @notice Deploys an interchain token. | ||
* @param tokenId The ID of the token. | ||
* @param minterBytes The minter address for the token. | ||
* @param name The name of the token. | ||
* @param symbol The symbol of the token. | ||
* @param decimals The number of decimals of the token. | ||
*/ | ||
function _deployInterchainToken( | ||
bytes32 tokenId, | ||
bytes memory minterBytes, | ||
string memory name, | ||
string memory symbol, | ||
uint8 decimals | ||
) internal returns (address tokenAddress) { | ||
if (bytes(name).length == 0) revert EmptyTokenName(); | ||
if (bytes(symbol).length == 0) revert EmptyTokenSymbol(); | ||
|
||
bytes32 salt = _getInterchainTokenSalt(tokenId); | ||
|
||
address minter; | ||
if (bytes(minterBytes).length != 0) minter = minterBytes.toAddress(); | ||
|
||
(bool success, bytes memory returnData) = interchainTokenDeployer.delegatecall( | ||
abi.encodeWithSelector(IInterchainTokenDeployer.deployInterchainToken.selector, salt, tokenId, minter, name, symbol, decimals) | ||
); | ||
if (!success) { | ||
revert InterchainTokenDeploymentFailed(returnData); | ||
} | ||
|
||
assembly { | ||
tokenAddress := mload(add(returnData, 0x20)) | ||
} | ||
|
||
// slither-disable-next-line reentrancy-events | ||
emit InterchainTokenDeployed(tokenId, tokenAddress, minter, name, symbol, decimals); | ||
} | ||
|
||
/** | ||
* @notice Decodes the metadata into a version number and data bytes. | ||
* @dev The function expects the metadata to have the version in the first 4 bytes, followed by the actual data. | ||
|
Uh oh!
There was an error while loading. Please reload this page.