Skip to content

Commit

Permalink
Add ISC create native token docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekjain23 authored May 31, 2024
1 parent 939fc06 commit 17a056b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:::caution

This method is now obsolete, use the new [`createNativeTokenFoundry`](../../../how-tos/core-contracts/token/create-native-token.md) method instead.

:::
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ tags:
- how-to
---
import ExampleCodeIntro from '../../../_partials/how-tos/token/_example_code_intro.md';
import ObsoleteTokenCreation from '../../../_partials/how-tos/token/_obsolete_token_creation.md';

# Create a Foundry

<ObsoleteTokenCreation/>

## About Foundries

The Stardust update allows you to create your own native tokens. Native tokens are minted by a [Foundry](/tips/tips/TIP-0018/#foundry-output).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
description: How to Create a Native Token Foundary.
image: /img/logo/WASP_logo_dark.png
tags:
- foundry
- EVM
- how-to
- native tokens
- mint
- register
---

import ExampleCodeIntro from '../../../_partials/how-tos/token/_example_code_intro.md';

# Create a Native Token

This guide will show you how you can efficiently mint new tokens and register them for use as ERC20 tokens with the `createNativeTokenFoundry` function in one seamless operation. It will create a foundry on L1 and register it as an ERC20 on L2. This method ensures that only the foundry owner can mint tokens, maintaining security and control over the token creation process.

## About Foundries

The Stardust update allows you to create your own native tokens. Native tokens are minted by a [Foundry](/tips/tips/TIP-0018/#foundry-output).
The Foundry lets you specify your native token's maximum supply **once** and change the circulating supply.

## Example Code

<ExampleCodeIntro/>

### 2. Define the Token Scheme

Define the `NativeTokenScheme` by specifying its `mintedTokens`, `meltedTokens`, and `maximumSupply`. For simplicity, in this guide we mint the whole maximum supply at creation.

```solidity
NativeTokenScheme memory nativeTokenScheme = NativeTokenScheme({
mintedTokens: _maximumSupply,
meltedTokens: 0,
maximumSupply: _maximumSupply
});
```

### 3. Mint and Register Native Token

Minting native tokens and registering them as ERC20 tokens using `createNativeTokenFoundry` method

```solidity
uint32 foundrySN = ISC.accounts.createNativeTokenFoundry(
_tokenName,
_tokenSymbol,
_tokenDecimals,
nativeTokenScheme,
allowance
);
```

## Full Example Code

```solidity
pragma solidity ^0.8.0;
import "@iota/iscmagic/ISC.sol";
contract MyToken {
event MintedToken(uint32 foundrySN);
constructor(
string memory _tokenName,
string memory _tokenSymbol,
uint8 _tokenDecimals,
uint256 _maximumSupply,
uint64 _storageDeposit
) payable {
require(msg.value == _storageDeposit * (10**12), "Please send exact funds to pay for storage deposit");
ISCAssets memory allowance;
allowance.baseTokens = _storageDeposit;
NativeTokenScheme memory nativeTokenScheme = NativeTokenScheme({
mintedTokens: _maximumSupply,
meltedTokens: 0,
maximumSupply: _maximumSupply
});
uint32 foundrySN = ISC.accounts.createNativeTokenFoundry(
_tokenName,
_tokenSymbol,
_tokenDecimals,
nativeTokenScheme,
allowance
);
emit MintedToken(foundrySN);
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ tags:
- mint
---
import ExampleCodeIntro from '../../../_partials/how-tos/token/_example_code_intro.md';
import ObsoleteTokenCreation from '../../../_partials/how-tos/token/_obsolete_token_creation.md';

# Mint a Native Token using a Foundry

<ObsoleteTokenCreation/>

# Mint Native Tokens

To mint tokens from a [foundry](/tips/tips/TIP-0018/#foundry-output), you first need to be aware that only the foundry owner can mint token,
so you should execute the `ISC.accounts.mintNativeTokens` function in the same contract that [created the foundry](./create-foundry.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ tags:
- how-to
---
import ExampleCodeIntro from '../../../_partials/how-tos/token/_example_code_intro.md';
import ObsoleteTokenCreation from '../../../_partials/how-tos/token/_obsolete_token_creation.md';

# Register Tokens

<ObsoleteTokenCreation/>

To properly use your native tokens, you should register them as ERC20 using the `registerERC20NativeToken` function from the ISC magic contract.

## Example Code
Expand Down
17 changes: 11 additions & 6 deletions docs/build/isc/v1.0.0-rc.6/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,31 @@ module.exports = {
type: 'doc',
id: 'how-tos/core-contracts/token/introduction',
},
{
type: 'doc',
label: 'Create a Native Token',
id: 'how-tos/core-contracts/token/create-native-token',
},
{
type: 'doc',
label: 'Custom ERC20 Functions',
id: 'how-tos/core-contracts/token/erc20-native-token',
},
{
type: 'doc',
label: 'Create a Foundry',
id: 'how-tos/core-contracts/token/create-foundry',
},
{
type: 'doc',
label: 'Mint a Native Token',
label: 'Mint a Native Token using a Foundry',
id: 'how-tos/core-contracts/token/mint-token',
},
{
type: 'doc',
label: 'Register Token as ERC20',
id: 'how-tos/core-contracts/token/register-token',
},
{
type: 'doc',
label: 'Custom ERC20 Functions',
id: 'how-tos/core-contracts/token/erc20-native-token',
},
],
},
{
Expand Down

0 comments on commit 17a056b

Please sign in to comment.