From 105e61e7b6639a1d478820a56d0b2fa022177d7c Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:21:32 +0400 Subject: [PATCH 1/9] update --- applications/subswap/README.md | 5 ++ applications/subswap/contract/README.md | 48 +++++++++++-------- .../contract/contracts/SimpleToken.sol | 14 ++++++ .../contract/contracts/TreasuryToken.sol | 4 +- .../subswap/contract/deploy.config.json | 3 +- ...urytokendeploy.js => simpletokendeploy.js} | 15 ++++-- 6 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 applications/subswap/README.md create mode 100644 applications/subswap/contract/contracts/SimpleToken.sol rename applications/subswap/contract/scripts/{treasurytokendeploy.js => simpletokendeploy.js} (65%) diff --git a/applications/subswap/README.md b/applications/subswap/README.md new file mode 100644 index 0000000..99e99a5 --- /dev/null +++ b/applications/subswap/README.md @@ -0,0 +1,5 @@ +#Subswap + +How to deploy a new token + +you can use any simple erc20 token code \ No newline at end of file diff --git a/applications/subswap/contract/README.md b/applications/subswap/contract/README.md index ca5674f..1d20d45 100644 --- a/applications/subswap/contract/README.md +++ b/applications/subswap/contract/README.md @@ -1,32 +1,42 @@ -# Subswap contract +# Subswap Contract Deployment Guide -## Subswap Deployment Guide +## Configuration: `deploy.config.json` -### Check `deploy.config.json` File - -1. Open the `deploy.config.json` file. -2. Check the values of `parentnetendpoint` and `subnetendpoint`. +1. **Open the `deploy.config.json` File** + - Verify the values for `parentnetendpoint` and `subnetendpoint`. - `parentnetendpoint`: The endpoint contract address on Parentnet. - `subnetendpoint`: The endpoint contract address on Subnet. + - `subnettoken`: + - `name`: The name of the token. + - `symbol`: The symbol of the token. + - `initSupply`: The initial supply of the token. -### Deploy Subswap +## Deploying Subswap -#### Method 1: Using Hardhat Scripts +### Method 1: Using Hardhat Scripts -1. Install Hardhat and dependencies: +1. **Install Hardhat and Dependencies** -``` -yarn -``` + ```bash + yarn + ``` -2. Deploy the Parentnet Treasury contract: +2. **Deploy the Parentnet Treasury Contract** -``` -npx hardhat run scripts/parentnettreasurydeploy.js --network xdcparentnet -``` + ```bash + npx hardhat run scripts/parentnettreasurydeploy.js --network xdcparentnet + ``` -3. Deploy the Subnet Treasury contract: +3. **Deploy the Subnet Treasury Contract** + ```bash + npx hardhat run scripts/subnettreasurydeploy.js --network xdcsubnet + ``` + +## Deploying the Subnet Token + +```bash +npx hardhat run scripts/simpletokendeploy.js --network xdcsubnet ``` -npx hardhat run scripts/subnettreasurydeploy.js --network xdcsubnet -``` + +This guide provides the steps to check and configure necessary values in the `deploy.config.json` file, and then deploy Subswap and the Subnet Token using Hardhat scripts. diff --git a/applications/subswap/contract/contracts/SimpleToken.sol b/applications/subswap/contract/contracts/SimpleToken.sol new file mode 100644 index 0000000..4571953 --- /dev/null +++ b/applications/subswap/contract/contracts/SimpleToken.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity =0.8.23; + +import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; + +contract SimpleToken is ERC20Burnable { + constructor( + string memory name_, + string memory symbol_, + uint256 initSupply + ) ERC20(name_, symbol_) { + _mint(msg.sender, initSupply * 1 ether); + } +} diff --git a/applications/subswap/contract/contracts/TreasuryToken.sol b/applications/subswap/contract/contracts/TreasuryToken.sol index 91820c6..d3e6eae 100644 --- a/applications/subswap/contract/contracts/TreasuryToken.sol +++ b/applications/subswap/contract/contracts/TreasuryToken.sol @@ -8,9 +8,7 @@ contract TreasuryToken is ERC20Burnable, Ownable { constructor( string memory name_, string memory symbol_ - ) ERC20(name_, symbol_) Ownable(msg.sender) { - mint(msg.sender, 10000000e18); - } + ) ERC20(name_, symbol_) Ownable(msg.sender) {} function mint(address account, uint256 amount) public onlyOwner { _mint(account, amount); diff --git a/applications/subswap/contract/deploy.config.json b/applications/subswap/contract/deploy.config.json index 844c415..260714a 100644 --- a/applications/subswap/contract/deploy.config.json +++ b/applications/subswap/contract/deploy.config.json @@ -1,4 +1,5 @@ { "parentnetendpoint": "0x89D933dFBd879DA78643530Bf413c81F94A73c31", - "subnetendpoint": "0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF" + "subnetendpoint": "0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF", + "subnettoken": { "name": "test", "symbol": "test", "initSupply": "1000" } } diff --git a/applications/subswap/contract/scripts/treasurytokendeploy.js b/applications/subswap/contract/scripts/simpletokendeploy.js similarity index 65% rename from applications/subswap/contract/scripts/treasurytokendeploy.js rename to applications/subswap/contract/scripts/simpletokendeploy.js index 5134f2b..16f1501 100644 --- a/applications/subswap/contract/scripts/treasurytokendeploy.js +++ b/applications/subswap/contract/scripts/simpletokendeploy.js @@ -5,15 +5,24 @@ // will compile your contracts, add the Hardhat Runtime Environment's members to the // global scope, and execute the script. const hre = require("hardhat"); +const deploy = require("../deploy.config.json"); async function main() { - const factory = await hre.ethers.getContractFactory("TreasuryToken"); + const factory = await hre.ethers.getContractFactory("SimpleToken"); - const treasuryToken = await factory.deploy("test", "test"); + const token = deploy.subnettoken; + + console.log(token); + + const treasuryToken = await factory.deploy( + token.name, + token.symbol, + token.initSupply + ); await treasuryToken.deployed(); - console.log("TreasuryToken deploy to ", treasuryToken.address); + console.log("ERC20 " + token.name + " deploy to ", treasuryToken.address); } // We recommend this pattern to be able to use async/await everywhere From ea1ce68ace2fe6fd10f4d8616d73bc12398f04ac Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:35:05 +0400 Subject: [PATCH 2/9] Update README.md --- applications/subswap/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/subswap/README.md b/applications/subswap/README.md index 99e99a5..9599f90 100644 --- a/applications/subswap/README.md +++ b/applications/subswap/README.md @@ -1,5 +1,5 @@ -#Subswap +#Subswap + +Contract Deploy doc in [contract](contract/) -How to deploy a new token -you can use any simple erc20 token code \ No newline at end of file From 943c88fb8acdd60997aa268afc79b1ae39ce4d7c Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:35:28 +0400 Subject: [PATCH 3/9] Update README.md --- applications/subswap/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/subswap/README.md b/applications/subswap/README.md index 9599f90..59d2eea 100644 --- a/applications/subswap/README.md +++ b/applications/subswap/README.md @@ -2,4 +2,5 @@ Contract Deploy doc in [contract](contract/) +Frontend doc in [contract](frontend/) From 00f5a8c7da24a0188b32f8bec607c0ace1bd0c0b Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:03:37 +0400 Subject: [PATCH 4/9] Update simpletokendeploy.js --- applications/subswap/contract/scripts/simpletokendeploy.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/subswap/contract/scripts/simpletokendeploy.js b/applications/subswap/contract/scripts/simpletokendeploy.js index 16f1501..69fea7f 100644 --- a/applications/subswap/contract/scripts/simpletokendeploy.js +++ b/applications/subswap/contract/scripts/simpletokendeploy.js @@ -14,15 +14,15 @@ async function main() { console.log(token); - const treasuryToken = await factory.deploy( + const simpleToken = await factory.deploy( token.name, token.symbol, token.initSupply ); - await treasuryToken.deployed(); + await simpleToken.deployed(); - console.log("ERC20 " + token.name + " deploy to ", treasuryToken.address); + console.log("ERC20 " + token.name + " deploy to ", simpleToken.address); } // We recommend this pattern to be able to use async/await everywhere From a1ce0b71c33c7eefad1dd0666ea725353125f8f6 Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:15:40 +0400 Subject: [PATCH 5/9] Update README.md --- applications/subswap/contract/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/applications/subswap/contract/README.md b/applications/subswap/contract/README.md index 1d20d45..ffc3b19 100644 --- a/applications/subswap/contract/README.md +++ b/applications/subswap/contract/README.md @@ -1,5 +1,8 @@ # Subswap Contract Deployment Guide +This guide provides the steps to check and configure necessary values in the `deploy.config.json` file, and then deploy Subswap and the Subnet Token using Hardhat scripts. + + ## Configuration: `deploy.config.json` 1. **Open the `deploy.config.json` File** @@ -39,4 +42,3 @@ npx hardhat run scripts/simpletokendeploy.js --network xdcsubnet ``` -This guide provides the steps to check and configure necessary values in the `deploy.config.json` file, and then deploy Subswap and the Subnet Token using Hardhat scripts. From 4a389c5f28fe0f15da4a33ff5c5a6a1202e2c647 Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:16:05 +0400 Subject: [PATCH 6/9] Update simpletokendeploy.js --- applications/subswap/contract/scripts/simpletokendeploy.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/applications/subswap/contract/scripts/simpletokendeploy.js b/applications/subswap/contract/scripts/simpletokendeploy.js index 69fea7f..6931f01 100644 --- a/applications/subswap/contract/scripts/simpletokendeploy.js +++ b/applications/subswap/contract/scripts/simpletokendeploy.js @@ -12,8 +12,6 @@ async function main() { const token = deploy.subnettoken; - console.log(token); - const simpleToken = await factory.deploy( token.name, token.symbol, From e21a9e54be2b844f2cc3eb5a6cd196d0657b1601 Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:16:49 +0400 Subject: [PATCH 7/9] Update simpletokendeploy.js --- applications/subswap/contract/scripts/simpletokendeploy.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/applications/subswap/contract/scripts/simpletokendeploy.js b/applications/subswap/contract/scripts/simpletokendeploy.js index 6931f01..0f59723 100644 --- a/applications/subswap/contract/scripts/simpletokendeploy.js +++ b/applications/subswap/contract/scripts/simpletokendeploy.js @@ -10,6 +10,11 @@ const deploy = require("../deploy.config.json"); async function main() { const factory = await hre.ethers.getContractFactory("SimpleToken"); + if (!deploy.subnettoken) { + console.error("Please set the token config in deploy.config.json"); + return; + } + const token = deploy.subnettoken; const simpleToken = await factory.deploy( From 75d6a76899b278ecd1d6647f601ae18369402a06 Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:17:21 +0400 Subject: [PATCH 8/9] Update README.md --- applications/subswap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/subswap/README.md b/applications/subswap/README.md index 59d2eea..434b065 100644 --- a/applications/subswap/README.md +++ b/applications/subswap/README.md @@ -1,4 +1,4 @@ -#Subswap +# Subswap Contract Deploy doc in [contract](contract/) From 07eaee00b48c68a1f824e11da58d142cc46f264e Mon Sep 17 00:00:00 2001 From: Galaxy <30950645+GalaxySciTech@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:17:35 +0400 Subject: [PATCH 9/9] Update README.md --- applications/subswap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/subswap/README.md b/applications/subswap/README.md index 434b065..5d03c0c 100644 --- a/applications/subswap/README.md +++ b/applications/subswap/README.md @@ -2,5 +2,5 @@ Contract Deploy doc in [contract](contract/) -Frontend doc in [contract](frontend/) +Frontend doc in [contract](https://github.com/XinFinOrg/subswap-frontend)