Tokensis MainStorage, LibConstants, MGovernance, MTokens¶
Registration of a new token (
registerToken) entails defining a new token ID identifying the token within the system, and associating it with an assetData array of bytes and a quantization factor (quantum).
The assetData is a byte array, with a size depending on the token type. For ETH, assetData is 4 bytes long. For ERC20 tokens, it is 36 bytes long.
For each token type, the following constant 4-byte hash is defined, called the selector:ETH_SELECTOR = bytes4(keccak256(“ETH()”));ERC20_SELECTOR = bytes4(keccak256(“ERC20Token(address)”));
For each token type, assetData is defined as follows:For ETH, assetData = ETH_SELECTOR;For ERC20, assetData = abi.encodePacked(ERC20_SELECTOR, address);
The quantum quantization factor defines the multiplicative transformation from the native token denomination as a 256b unsigned integer to a 63b unsigned integer representation as used by the Stark exchange. Only amounts in the native representation that represent an integer number of quanta are allowed in the system.
The token ID is restricted to be the result of a hash of the assetData and the quantum masked to 250 bits (to be less than the prime used) according to the following formula:
uint256 tokenID = uint256(keccak256(abi.encodePacked(assetData, quantum))) &
Once registered, tokens cannot be removed from the system, as their IDs may be used by off-chain accounts.
New tokens may only be registered by a Token Administrator. A Token Administrator may be instantly appointed or removed by the contract Governor (see
MainGovernance). Typically, the Token Administrator’s private key should be kept in a cold wallet.
registerToken(uint256 tokenId, bytes calldata assetData, uint256 quantum)¶