Skip to content
Open
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5075a45
add hedera libraries and interfaces
rista404 Jun 4, 2025
386f43a
create hts token from token manager + inherit Minter contract
rista404 Jun 6, 2025
3e6fe1f
add token creation price calculation + whbar contract address
rista404 Jun 10, 2025
374103f
pay for token creation, specify price
rista404 Jun 10, 2025
7964a79
deploy hts lib for testing
rista404 Jun 11, 2025
414c13b
rm unused `transmitInterchainTransfer` ITS method
rista404 Jun 11, 2025
ab88ce0
revert on initial supply token deployments in factory
rista404 Jun 11, 2025
a8b20e3
wip tests
rista404 Jun 11, 2025
707e7c1
add test checks for token deployment events
rista404 Jun 13, 2025
5c6cb05
save isHtsToken flag in TokenManagerProxy
rista404 Jun 13, 2025
b133129
add deploy and fund scripts for whbar
rista404 Jun 13, 2025
9face17
get token metadata for hts tokens in factory
rista404 Jun 23, 2025
a11e2fb
approve service to int64.max for hts tokens
rista404 Jun 24, 2025
7dafa59
don't transfer mintership to TM post-deployment
rista404 Jun 24, 2025
98985c2
associate TM only for HTS tokens and LOCK_UNLOCK
rista404 Jun 24, 2025
a959b48
update deploy scripts + add token associate script
rista404 Jun 26, 2025
f7c81fb
set `tokenCreationPrice` during ITS setup
rista404 Jul 1, 2025
7f25371
optionally include a Hedera testnet account in hardhat config
rista404 Jul 1, 2025
f477f74
remove `migrateInterchainToken` support
rista404 Jul 1, 2025
64037cc
update hedera/README.md with the new design
rista404 Jul 3, 2025
e1dbb8e
remove impossible < 0 check
rista404 Jul 3, 2025
ab13603
fix its unit tests suite + improve docs
rista404 Jul 18, 2025
2e83bc7
add note about WHBAR balance of ITS
rista404 Jul 18, 2025
da7fc66
rm cross-invokation deployment context + review fixes
rista404 Jul 18, 2025
b121dd2
add deploy interchain token diagram
rista404 Jul 18, 2025
a64202d
add todo note about auto associations
rista404 Jul 18, 2025
2ecb8e0
add auto association explanation to the docs
rista404 Jul 21, 2025
ffd885d
add register and mint diagram to docs
rista404 Jul 21, 2025
c311f20
add note on test suite time
rista404 Jul 21, 2025
0e48ce6
don't add its as a minter in TM
rista404 Jul 21, 2025
e67e868
rm unused `centsToTinybars` from HTS lib
rista404 Jul 21, 2025
7fec126
explain why we add one tinybar to token creation price
rista404 Jul 21, 2025
123e921
fix deploy TM proxy invalid params test
rista404 Jul 21, 2025
35719b8
fix ITF tests + revert on empty name and symbol
rista404 Jul 21, 2025
b97bb76
skip ERC20 tests
rista404 Jul 21, 2025
6bdd53e
fix canonical interchain token full flow tests
rista404 Jul 21, 2025
84130d1
fix some full flow tests + IHRC719 interface for executable + docs
rista404 Jul 22, 2025
2198e27
fix full flow and upgrade tests
rista404 Jul 23, 2025
acfaf20
require approval of WHBAR for local deployment
rista404 Aug 18, 2025
1088024
make whbar address immutable
rista404 Aug 20, 2025
01ac902
revert removal of `transmitInterchainTransfer` method
rista404 Aug 21, 2025
b04a129
mention non-deterministic token addresses in the overview
rista404 Aug 25, 2025
70c2fed
docs: add info about the token creation price
rista404 Sep 10, 2025
4a934f6
docs: use h2 for sections
rista404 Sep 10, 2025
cdc6e99
docs: add lines between diagrams
rista404 Sep 10, 2025
73bb1b7
docs: add hedera links
rista404 Sep 10, 2025
5666515
docs: add note about canonical ITS
rista404 Sep 10, 2025
1806536
docs: link to tree view instead of commit
rista404 Sep 10, 2025
c6fda17
fix: support registration of native tokens with lower max supply
rista404 Sep 25, 2025
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
85 changes: 46 additions & 39 deletions contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { IInterchainTokenFactory } from './interfaces/IInterchainTokenFactory.so
import { ITokenManager } from './interfaces/ITokenManager.sol';
import { IInterchainToken } from './interfaces/IInterchainToken.sol';
import { IERC20Named } from './interfaces/IERC20Named.sol';
import { IMinter } from './interfaces/IMinter.sol';

import { HTS, IHederaTokenService } from './hedera/HTS.sol';

/**
* @title InterchainTokenFactory
Expand Down Expand Up @@ -124,7 +127,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, Multicall, Upgradabl
* @param name The name of the token.
* @param symbol The symbol of the token.
* @param decimals The number of decimals for the token.
* @param initialSupply The amount of tokens to mint initially (can be zero), allocated to the msg.sender.
* @param initialSupply The amount of tokens to mint initially (can be zero), allocated to the msg.sender. Not supported for HTS tokens.
* @param minter The address to receive the minter and operator role of the token, in addition to ITS. If it is set to `address(0)`,
* the additional minter isn't set, and can't be added later. This allows creating tokens that are managed only by ITS, reducing trust assumptions.
* Reverts if the minter is the ITS address since it's already added as a minter.
Expand All @@ -144,9 +147,14 @@ contract InterchainTokenFactory is IInterchainTokenFactory, Multicall, Upgradabl
string memory currentChain = '';
uint256 gasValue = 0;

if (initialSupply > 0) {
minterBytes = address(this).toBytes();
} else if (minter != address(0)) {
// HTS tokens must previously be associated with an account
// to be able to send tokens to it. Since a new token will be created
// it's not possible to send it right away.
if (initialSupply != 0) {
revert HTS.InitialSupplyUnsupported();
}

if (minter != address(0)) {
if (minter == address(interchainTokenService)) revert InvalidMinter(minter);

minterBytes = minter.toBytes();
Expand All @@ -155,21 +163,6 @@ contract InterchainTokenFactory is IInterchainTokenFactory, Multicall, Upgradabl
}

tokenId = _deployInterchainToken(deploySalt, currentChain, name, symbol, decimals, minterBytes, gasValue);

if (initialSupply > 0) {
IInterchainToken token = IInterchainToken(interchainTokenService.registeredTokenAddress(tokenId));
ITokenManager tokenManager = ITokenManager(interchainTokenService.deployedTokenManager(tokenId));

token.mint(sender, initialSupply);

token.transferMintership(minter);
tokenManager.removeFlowLimiter(address(this));

// If minter == address(0), we still set it as a flow limiter for consistency with the remote token manager.
tokenManager.addFlowLimiter(minter);

tokenManager.transferOperatorship(minter);
}
}

/**
Expand Down Expand Up @@ -329,8 +322,8 @@ contract InterchainTokenFactory is IInterchainTokenFactory, Multicall, Upgradabl
*/
function _checkTokenMinter(bytes32 tokenId, address minter) internal view {
// Ensure that the minter is registered for the token on the current chain
IInterchainToken token = IInterchainToken(interchainTokenService.registeredTokenAddress(tokenId));
if (!token.isMinter(minter)) revert NotMinter(minter);
ITokenManager tokenManager = ITokenManager(interchainTokenService.deployedTokenManager(tokenId));
if (!tokenManager.isMinter(minter)) revert NotMinter(minter);

// Sanity check to prevent accidental use of the current ITS address as the token minter
if (minter == address(interchainTokenService)) revert InvalidMinter(minter);
Expand Down Expand Up @@ -412,31 +405,45 @@ contract InterchainTokenFactory is IInterchainTokenFactory, Multicall, Upgradabl
}

/**
* @notice Retrieves the metadata of an ERC20 token. Reverts with `NotToken` error if metadata is not available.
* @notice Retrieves the metadata of an ERC20 or HTS token. Reverts with `NotToken` error if metadata is not available.
* @notice Returns HTS.InvalidtokenDecimals() if the decimals are not supported.
* @param tokenAddress The address of the token.
* @return name The name of the token.
* @return symbol The symbol of the token.
* @return decimals The number of decimals for the token.
*/
function _getTokenMetadata(address tokenAddress) internal view returns (string memory name, string memory symbol, uint8 decimals) {
IERC20Named token = IERC20Named(tokenAddress);
function _getTokenMetadata(address tokenAddress) internal returns (string memory name, string memory symbol, uint8 decimals) {
bool isHTSToken = HTS.isToken(tokenAddress);

if (isHTSToken) {
IHederaTokenService.FungibleTokenInfo memory fTokenInfo = HTS.getFungibleTokenInfo(tokenAddress);
name = fTokenInfo.tokenInfo.token.name;
symbol = fTokenInfo.tokenInfo.token.symbol;
int32 htsDecimals = fTokenInfo.decimals;
if (htsDecimals > int32(uint32(type(uint8).max))) {
revert HTS.InvalidTokenDecimals();
}
decimals = uint8(uint32(htsDecimals));
} else {
IERC20Named token = IERC20Named(tokenAddress);

try token.name() returns (string memory name_) {
name = name_;
} catch {
revert NotToken(tokenAddress);
}
try token.name() returns (string memory name_) {
name = name_;
} catch {
revert NotToken(tokenAddress);
}

try token.symbol() returns (string memory symbol_) {
symbol = symbol_;
} catch {
revert NotToken(tokenAddress);
}
try token.symbol() returns (string memory symbol_) {
symbol = symbol_;
} catch {
revert NotToken(tokenAddress);
}

try token.decimals() returns (uint8 decimals_) {
decimals = decimals_;
} catch {
revert NotToken(tokenAddress);
try token.decimals() returns (uint8 decimals_) {
decimals = decimals_;
} catch {
revert NotToken(tokenAddress);
}
}
}

Expand Down Expand Up @@ -503,7 +510,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, Multicall, Upgradabl
}

/**
* @notice Register an existing ERC20 token under a `tokenId` computed from the provided `salt`.
* @notice Register an existing ERC20 or HTS token under a `tokenId` computed from the provided `salt`.
* A token metadata registration message will also be sent to the ITS Hub.
* This token can then be linked to remote tokens on different chains by submitting the `linkToken` function from the same `msg.sender` and using the same `salt`.
* @dev This function is marked as payable since it can be called within a multicall with other payable methods.
Expand Down
Loading
Loading