Create a New Index Token

To interact with Covenants index contracts in order to create a new Index token, it is necessary to use the mint public function.

function mint(string memory name, string memory symbol, string memory uri, address[] memory _tokens, uint256[] memory _amounts, uint256 value, address receiver) public override payable returns(uint256 objectId, address interoperableInterfaceAddress) 

The input functions are as follows:

  • name -> token name

  • symbol -> token symbol

  • uri -> token uri

  • _tokens -> array containing the address of tokens selected to be indexed as the index token. To input ETH as one of the chosen tokens, you need to pass 0x0000000000000000000000000000000000000000.

  • _amounts -> amount of each chosen token. Every token input (in the previous tokens field) must correspond to its specific amount (there cannot be an amount equal to 0).

  • value -> amount of the Index token to create. The value parameter calculates the necessary amount of tokens for the creation of the Index as follows:

uint256 tokenValue = (_amounts[i] * value) / 1e18;

This implies that if the value is equal to 0, you are creating an empty index. In this case, to create the correctly interoperable version of the index and its object Id (and to avoid the call failing), a value of 1e18 is adopted by default:

(objectId, interoperableInterfaceAddress) = theCollection.mint(value == 0 ? 1e18 : value, name, symbol, uri, true);

With value=0 the mint function burns what has been created so far, but the interoperable version of the created index remains to allow for its future minting:

 if(value == 0) {
     theCollection.burn(objectId, theCollection.balanceOf(address(this), objectId));} 
  • receiver -> pass 0x0000000000000000000000000000000000000000 to send Index tokens to msg.sender or otherwise the specific receiver address

With a value > 0, the _safeTransferFrom function is internally called to transfer the required token amounts from the msg.sender (or msg.value in the case that ETH is involved) to the contract:

if(_tokens[i] == address(0)) {
    require(msg.value == tokenValue, "insufficient eth");
} else {
    _safeTransferFrom(_tokens[i], msg.sender, address(this), tokenValue);
}

The mint function creates the desired amount of index tokens by calling the mint method of the native Item collection:

objectId, interoperableInterfaceAddress) = theCollection.mint(value == 0 ? 1e18 : value, name, symbol, uri, true);

Then, the amount is minted and sent to the receiver address using the _safeTransfer method via the interoperable Item interface version:

_safeTransfer(interoperableInterfaceAddress, receiver == address(0) ? msg.sender : receiver, theCollection.toInteroperableInterfaceAmount(objectId, theCollection.balanceOf(address(this), objectId)));

Please note: the native collection of index tokens created via Covenants was initially created via the contract Constructor.

Last updated