Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc for subswap #25

Merged
merged 9 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions applications/subswap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Subswap

Contract Deploy doc in [contract](contract/)

Frontend doc in [contract](https://github.com/XinFinOrg/subswap-frontend)

48 changes: 30 additions & 18 deletions applications/subswap/contract/README.md
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing the installation cmd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn is install cmd

```

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
```

14 changes: 14 additions & 0 deletions applications/subswap/contract/contracts/SimpleToken.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 1 addition & 3 deletions applications/subswap/contract/contracts/TreasuryToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion applications/subswap/contract/deploy.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"parentnetendpoint": "0x89D933dFBd879DA78643530Bf413c81F94A73c31",
"subnetendpoint": "0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF"
"subnetendpoint": "0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF",
"subnettoken": { "name": "test", "symbol": "test", "initSupply": "1000" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
GalaxySciTech marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down