From ab23378680b46434c0b81d02c97aaefcfb07b5c0 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Tue, 20 Feb 2024 20:36:12 +0100 Subject: [PATCH] Register token --- .../how-tos/token/_check_storage_deposit.md | 8 ++++ .../how-tos/token/_example_code_intro.md | 9 ++++ .../docs/how-tos/token/create-foundry.md | 16 +------ .../docs/how-tos/token/mint-token.md | 17 +------ .../docs/how-tos/token/register-token.md | 48 +++++++++++++++++++ docs/build/isc/v1.0.0-rc.6/sidebars.js | 5 ++ 6 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_check_storage_deposit.md create mode 100644 docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_example_code_intro.md create mode 100644 docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/register-token.md diff --git a/docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_check_storage_deposit.md b/docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_check_storage_deposit.md new file mode 100644 index 00000000000..1f2ef198b22 --- /dev/null +++ b/docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_check_storage_deposit.md @@ -0,0 +1,8 @@ +1. Check if the amount paid to the contract is the same as the required [storage deposit](/learn/protocols/stardust/core-concepts/storage-deposit) + and set the allowance. + +```solidity +require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit"); +ISCAssets memory allowance; +allowance.baseTokens = _storageDeposit; +``` \ No newline at end of file diff --git a/docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_example_code_intro.md b/docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_example_code_intro.md new file mode 100644 index 00000000000..daf06c0839b --- /dev/null +++ b/docs/build/isc/v1.0.0-rc.6/docs/_partials/how-tos/token/_example_code_intro.md @@ -0,0 +1,9 @@ +import Ownership from '../../../_admonitions/_ownership.md'; +import Payable from '../../../_admonitions/_payable.md'; +import CheckStorageDeposit from './_check_storage_deposit.md' + + + + + + diff --git a/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/create-foundry.md b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/create-foundry.md index 067c1535293..5f0a86712e1 100644 --- a/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/create-foundry.md +++ b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/create-foundry.md @@ -6,9 +6,7 @@ tags: - EVM - how-to --- - -import Ownership from '../../_admonitions/_ownership.md'; -import Payable from '../../_admonitions/_payable.md'; +import ExampleCodeIntro from '../../_partials/how-tos/token/_example_code_intro.md'; # Create a Foundry ## About Foundries @@ -19,17 +17,7 @@ This guide will show you how to create an L1 foundry using a L2 smart contract. ## Example Code - - -1. Check if the amount paid to the contract is the same as the required [storage deposit](/learn/protocols/stardust/core-concepts/storage-deposit) and set the allowance. - -```solidity - require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit"); - ISCAssets memory allowance; - allowance.baseTokens = _storageDeposit; -``` - - + 2. Define the `NativeTokenScheme`: diff --git a/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/mint-token.md b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/mint-token.md index 3f07488f53f..133eb6f5b44 100644 --- a/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/mint-token.md +++ b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/mint-token.md @@ -8,9 +8,7 @@ tags: - native tokens - mint --- - -import Ownership from '../../_admonitions/_ownership.md'; -import Payable from '../../_admonitions/_payable.md'; +import ExampleCodeIntro from '../../_partials/how-tos/token/_example_code_intro.md'; # Mint Native Tokens @@ -19,18 +17,7 @@ so you should execute the `ISC.accounts.mintNativeTokens` function in the same c ## Example Code - - -1. Check if the amount paid to the contract is the same as the required [storage deposit](/learn/protocols/stardust/core-concepts/storage-deposit) - and set the allowance. - -```solidity -require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit"); -ISCAssets memory allowance; -allowance.baseTokens = _storageDeposit; -``` - - + 2. Mint the native token specifying the foundry serial number, the amount to mint and the allowance. diff --git a/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/register-token.md b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/register-token.md new file mode 100644 index 00000000000..ca4aea0192a --- /dev/null +++ b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/register-token.md @@ -0,0 +1,48 @@ +--- +description: How to register a native token as ERC20 +image: /img/logo/WASP_logo_dark.png +tags: + - ERC20 + - EVM + - how-to +--- +import ExampleCodeIntro from '../../_partials/how-tos/token/_example_code_intro.md'; + +# Register Tokens + +To properly use your native tokens, you should register them as ERC20 using the `registerERC20NativeToken` function from the ISC magic contract. + +## Example Code + + + + +2. Register the native tokens specifying: +* the foundry serial number +* a name +* a symbol +* it's decimals +* the allowance. +```solidity +ISC.sandbox.registerERC20NativeToken(_foundrySN, _name, _symbol, _decimals, allowance); +``` + +3. Get the ERC20 contract address with `erc20NativeTokensAddress`: +```solidity +address erc20address = ISC.sandbox.erc20NativeTokensAddress(_foundrySN); +``` + +### Full Example Code + +```solidity +event ERC20Address(address erc20address); + +function registerERC20NativeToken(uint32 _foundrySN, string calldata _name, string calldata _symbol, uint8 _decimals, uint64 _storageDeposit) public payable { +require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit"); +ISCAssets memory allowance; +allowance.baseTokens = _storageDeposit; +ISC.sandbox.registerERC20NativeToken(_foundrySN, _name, _symbol, _decimals, allowance); +address erc20address = ISC.sandbox.erc20NativeTokensAddress(_foundrySN); +emit ERC20Address(erc20address); +} +``` diff --git a/docs/build/isc/v1.0.0-rc.6/sidebars.js b/docs/build/isc/v1.0.0-rc.6/sidebars.js index ad4a1604248..4b8cb71bb1d 100644 --- a/docs/build/isc/v1.0.0-rc.6/sidebars.js +++ b/docs/build/isc/v1.0.0-rc.6/sidebars.js @@ -175,6 +175,11 @@ module.exports = { label: 'Mint a Native Token', id: 'how-tos/token/mint-token', }, + { + type: 'doc', + label: 'Register Token as ERC20', + id: 'how-tos/token/register-token', + }, ], }, ],