diff --git a/applications/subswap/README.md b/applications/subswap/README.md new file mode 100644 index 0000000..5d03c0c --- /dev/null +++ b/applications/subswap/README.md @@ -0,0 +1,6 @@ +# Subswap + +Contract Deploy doc in [contract](contract/) + +Frontend doc in [contract](https://github.com/XinFinOrg/subswap-frontend) + diff --git a/applications/subswap/contract/README.md b/applications/subswap/contract/README.md index ca5674f..ffc3b19 100644 --- a/applications/subswap/contract/README.md +++ b/applications/subswap/contract/README.md @@ -1,32 +1,44 @@ -# Subswap contract +# Subswap Contract Deployment Guide -## Subswap 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. -### Check `deploy.config.json` File -1. Open the `deploy.config.json` file. -2. Check the values of `parentnetendpoint` and `subnetendpoint`. +## Configuration: `deploy.config.json` + +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 -``` + 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 57% rename from applications/subswap/contract/scripts/treasurytokendeploy.js rename to applications/subswap/contract/scripts/simpletokendeploy.js index 5134f2b..0f59723 100644 --- a/applications/subswap/contract/scripts/treasurytokendeploy.js +++ b/applications/subswap/contract/scripts/simpletokendeploy.js @@ -5,15 +5,27 @@ // 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"); + if (!deploy.subnettoken) { + console.error("Please set the token config in deploy.config.json"); + return; + } - await treasuryToken.deployed(); + const token = deploy.subnettoken; - console.log("TreasuryToken deploy to ", treasuryToken.address); + const simpleToken = await factory.deploy( + token.name, + token.symbol, + token.initSupply + ); + + await simpleToken.deployed(); + + console.log("ERC20 " + token.name + " deploy to ", simpleToken.address); } // We recommend this pattern to be able to use async/await everywhere diff --git a/frontend/config/index.js b/frontend/config/index.js index 268db36..6f656e4 100644 --- a/frontend/config/index.js +++ b/frontend/config/index.js @@ -1,8 +1,6 @@ const contractMapping = { 551: { endpoint: "0x2a79C790Dfc413aAA78af2a617023922325D6e47", - oracle: "0x8EC22d14cD38FAB7C5AeF1d97105A6ec3FefEe5f", - sample: "0xabc8aa43120ff0f53749e9d8b525f50da489e0d9", }, 5173: { endpoint: "0xD4449Bf3f8E6a1b3fb5224F4e1Ec4288BD765547",