Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
.vscode
yarn.lock
7 changes: 3 additions & 4 deletions applications/subswap/contract/deploy.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"parentnetendpoint": "0x89D933dFBd879DA78643530Bf413c81F94A73c31",
"subnetendpoint": "0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF",
"subnettoken": { "name": "test", "symbol": "test", "initSupply": "1000" }
}
"subnetendpoint": "0xBd0D59f41c7e80012E30cd35Af2375f9A15940A3",
"parentnetendpoint": "0x4381e4c455B35c2894CCDb90164225A5A2c08bbB"
}
6 changes: 3 additions & 3 deletions applications/subswap/contract/network.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"xdcparentnet": "https://devnetstats.apothem.network/devnet",
"xdcsubnet": "https://devnetstats.apothem.network/subnet"
}
"xdcsubnet": "http://localhost:8545",
"xdcparentnet": "https://erpc.apothem.network/"
}
3 changes: 2 additions & 1 deletion applications/subswap/contract/scripts/simpletokendeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ async function main() {
token.initSupply
);

const [deployer] = await hre.ethers.getSigners();
console.log("SimpleToken deploy start, deployer address:", deployer.address)
await simpleToken.deployed();

console.log("ERC20 " + token.name + " deploy to ", simpleToken.address);
}

Expand Down
4 changes: 2 additions & 2 deletions cicd/.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

SUBNET_PK=0x1111111111111111111111111111111111111111111111111111111111111111
PARENTNET_PK=0x2222222222222222222222222222222222222222222222222222222222222222
CSC=0x3333333333333333333333333333333333333333
REVERSE_CSC=0x4444444444444444444444444444444444444444
CHECKPOINT_CONTRACT=0x3333333333333333333333333333333333333333
REVERSE_CHECKPOINT_CONTRACT=0x4444444444444444444444444444444444444444

# PARENTNET_URL: full url or devnet,testnet
# devnet : https://devnetstats.apothem.network/devnet/
Expand Down
2 changes: 0 additions & 2 deletions cicd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
FROM node:20-alpine

COPY . /app

WORKDIR /app/cicd
RUN yarn
WORKDIR /app/endpoint
RUN yarn
WORKDIR /app/applications/subswap/contract
RUN yarn

WORKDIR /app/cicd

ENTRYPOINT ["node"]
8 changes: 4 additions & 4 deletions cicd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Based on the provided `.env.example`, create your own `.env` file with the follo
- **`PARENTNET_URL`**: RPC URL for the parentnet endpoint.
- **`SUBNET_URL`**: RPC URL for the subnet.
- **`SUBNET_PK`**: Private key for the deploy subnet XDC Zero wallet.
- **`CSC`**: Checkpoint smart contract address within the subnet chain (deployed to parentnet).
- **`REVERSE_CSC`**: Checkpoint smart contract address within the parentnet chain (deployed to subnet).
- **`CHECKPOINT_CONTRACT`**: Checkpoint smart contract address within the subnet chain (deployed to parentnet).
- **`REVERSE_CHECKPOINT_CONTRACT`**: Checkpoint smart contract address within the parentnet chain (deployed to subnet).

#### Step 2: Deploy Endpoints and Register Chain

Expand Down Expand Up @@ -78,8 +78,8 @@ Based on the provided `.env.example`, create your own `.env` file with the follo
- **`PARENTNET_URL`**: RPC URL for the parentnet endpoint.
- **`SUBNET_URL`**: RPC URL for the subnet.
- **`SUBNET_PK`**: Private key for the deploy subnet XDC Zero wallet.
- **`CSC`**: Checkpoint smart contract address within the subnet chain (deployed to parentnet).
- **`REVERSE_CSC`**: Checkpoint smart contract address within the parentnet chain (deployed to subnet).
- **`CHECKPOINT_CONTRACT`**: Checkpoint smart contract address within the subnet chain (deployed to parentnet).
- **`REVERSE_CHECKPOINT_CONTRACT`**: Checkpoint smart contract address within the parentnet chain (deployed to subnet).

### Step 3: Deploy Endpoint and Register Chain

Expand Down
23 changes: 15 additions & 8 deletions cicd/applicationregister.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
process.chdir(__dirname);
const { execSync } = require("child_process");
const fs = require("node:fs");
const env = require("dotenv").config({ path: "mount/.env" });
const config = {
relativePath: "../endpoint/",
};
const config = { relativePath: "../endpoint/" };
const endpointConfig = {};

const { ethers } = require("ethers");
const u = require("./util.js");
u.loadContractENV();

main();
if (require.main === module) {
main();
}

async function main() {
await applicationRegister();
}

async function applicationRegister() {
console.log("start application register");
u.loadContractENV();
importEndpointJson();
initApplicationRegister();
await u.getNetworkID(config);
Expand Down Expand Up @@ -81,6 +83,7 @@ function initApplicationRegister() {
"incomplete ENVs, require SUBNET_PK, PARENTNET_PK, SUBNET_APP, PARENTNET_APP, SUBNET_URL"
);
}

subnetPK = process.env.SUBNET_PK.startsWith("0x")
? process.env.SUBNET_PK
: `0x${process.env.SUBNET_PK}`;
Expand Down Expand Up @@ -192,3 +195,7 @@ function exportEndpointJson() {
console.log("SUCCESS register application, endpointconfig:");
console.log(ep);
}

module.exports = {
applicationRegister,
};
54 changes: 34 additions & 20 deletions cicd/endpointandregisterchain.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
process.chdir(__dirname);
const { execSync } = require("child_process");
const fs = require("node:fs");
const env = require("dotenv").config({ path: "mount/.env" });
const config = {
relativePath: "../endpoint/",
};
const config = { relativePath: "../endpoint/" };
const endpointConfig = {};

const { ethers } = require("ethers");
const u = require("./util.js");
u.loadContractENV();

main();

if (require.main === module) {
main();
}
async function main() {
const newENV = await endpointAndRegisterChain();
for (const [key, value] of Object.entries(newENV)) {
u.replaceOrAddENV("./mount/contract_deploy.env", key, value);
u.replaceOrAddENV("./mount/common.env", key, value);
}
u.loadContractENV();
}

async function endpointAndRegisterChain() {
console.log("start endpoint deploy and register chain");
initEndpointDeploy();
await u.getNetworkID(config);
deployEndpoint();
configureEndpointJson();
registerEndpoint();
exportEndpointJson();
const newENV = exportEndpointJson();
return newENV;
}

function initEndpointDeploy() {
Expand All @@ -33,18 +39,17 @@ function initEndpointDeploy() {
throw Error("PARENTNET_URL not found");
}


const reqENV = [
"SUBNET_PK",
"PARENTNET_PK",
"SUBNET_URL",
"CSC",
"REVERSE_CSC",
"CHECKPOINT_CONTRACT",
"REVERSE_CHECKPOINT_CONTRACT",
];
const isEnabled = reqENV.every((envVar) => envVar in process.env);
if (!isEnabled) {
throw Error(
"incomplete ENVs, require SUBNET_PK, PARENTNET_PK, SUBNET_URL, CSC, REVERSE_CSC"
"incomplete ENVs, require SUBNET_PK, PARENTNET_PK, SUBNET_URL, CHECKPOINT_CONTRACT, REVERSE_CHECKPOINT_CONTRACT"
);
}
subnetPK = process.env.SUBNET_PK.startsWith("0x")
Expand All @@ -53,12 +58,12 @@ function initEndpointDeploy() {
parentnetPK = process.env.PARENTNET_PK.startsWith("0x")
? process.env.PARENTNET_PK
: `0x${process.env.PARENTNET_PK}`;
csc = process.env.CSC.startsWith("0x")
? process.env.CSC
: `0x${process.env.CSC}`;
reverseCSC = process.env.REVERSE_CSC.startsWith("0x")
? process.env.REVERSE_CSC
: `0x${process.env.REVERSE_CSC}`;
csc = process.env.CHECKPOINT_CONTRACT.startsWith("0x")
? process.env.CHECKPOINT_CONTRACT
: `0x${process.env.CHECKPOINT_CONTRACT}`;
reverseCSC = process.env.REVERSE_CHECKPOINT_CONTRACT.startsWith("0x")
? process.env.REVERSE_CHECKPOINT_CONTRACT
: `0x${process.env.REVERSE_CHECKPOINT_CONTRACT}`;
subnetURL = process.env.SUBNET_URL;

// return subnetURL, parentnetURL, subnetPK, parentnetPK, csc, reverseCSC
Expand Down Expand Up @@ -119,6 +124,11 @@ function exportEndpointJson() {
console.log("SUCCESS deploy endpoint and register chain, env:");
console.log("SUBNET_ZERO_CONTRACT=" + config.subnetEndpoint);
console.log("PARENTNET_ZERO_CONTRACT=" + config.parentnetEndpoint);

return {
SUBNET_ZERO_CONTRACT: config.subnetEndpoint,
PARENTNET_ZERO_CONTRACT: config.parentnetEndpoint,
};
}

function deployEndpoint() {
Expand Down Expand Up @@ -181,3 +191,7 @@ function parseEndpointOutput(outString) {
throw Error("invalid output string: " + outString);
}
}

module.exports = {
endpointAndRegisterChain,
};
100 changes: 88 additions & 12 deletions cicd/subswap.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
process.chdir(__dirname);
const { execSync } = require("child_process");
const fs = require("node:fs");
const env = require("dotenv").config({ path: "mount/.env" });
const config = {
relativePath: "../applications/subswap/contract/",
};
const endpointConfig = {};

const { ethers } = require("ethers");
const config = { relativePath: "../applications/subswap/contract/" };
const u = require("./util.js");
u.loadContractENV();

main();
if (require.main === module) {
main();
}

async function main() {
const newENV = await subswap();
for (const [key, value] of Object.entries(newENV)) {
u.replaceOrAddENV("./mount/contract_deploy.env", key, value);
u.replaceOrAddENV("./mount/common.env", key, value);
}
u.loadContractENV();
}

async function subswap() {
console.log("start subswap deploy");
u.loadContractENV();
checkEndpointConfig();
initSubswapDeploy();
await initSubswapDeploy();
deploySubswap();
exportSubswap();
deploySampleToken();
writeSubswapConfigJson();
const newENV = exportSubswap();
return newENV;
}

function checkEndpointConfig() {
Expand Down Expand Up @@ -46,7 +55,7 @@ function checkEndpointConfig() {
throw Error("endpoints not found in mount/endpointconfig.json");
}

function initSubswapDeploy() {
async function initSubswapDeploy() {
if (process.env.PARENTNET_URL) {
parentnetURL = process.env.PARENTNET_URL;
if (parentnetURL == "devnet")
Expand Down Expand Up @@ -74,6 +83,7 @@ function initSubswapDeploy() {
config["parentnetPK"] = parentnetPK;
config["subnetURL"] = subnetURL;
config["parentnetURL"] = parentnetURL;
await u.getNetworkID(config);
}

function deploySubswap() {
Expand Down Expand Up @@ -111,11 +121,35 @@ function exportSubswap() {
);
console.log(finalSubnet);
console.log(finalParentnet);

return {
SUBNET_APP: config.subnetSubswap,
PARENTNET_APP: config.parentnetSubswap,
};
}

function deploySampleToken() {
console.log("writing deploy.config.json");
writeSubswapDeployJson();
console.log("configuring PK");
u.writeEnv(config.subnetPK, config.relativePath);
console.log("deploying subnet sample token on subnet");
tokenDeployOut = u.callExec(
"cd ../applications/subswap/contract; npx hardhat run scripts/simpletokendeploy.js --network xdcsubnet"
);
tokenAddr = parseEndpointOutput(tokenDeployOut);
config["subnetSampleTokenAddress"] = tokenAddr;
}

function writeSubswapDeployJson() {
deployJson = {
subnetendpoint: config.subnetEndpoint,
parentnetendpoint: config.parentnetEndpoint,
subnettoken: {
name: "Subnet Sample Token",
symbol: "SST",
initSupply: 1_000_000,
},
};
fs.writeFileSync(
"../applications/subswap/contract/deploy.config.json",
Expand Down Expand Up @@ -144,3 +178,45 @@ function parseEndpointOutput(outString) {
throw Error("invalid output string: " + outString);
}
}

function writeSubswapConfigJson() {
// {
// "parentnetUrl":"https://erpc.apothem.network/",
// "parentnetChainId":"51",
// "subnetUrl":"http://localhost:8545",
// "subnetChainId":"999",
// "subnetApp": "0x9777050a8402ac5958aA87631B15e98e26610EB5",
// "parentnetApp": "0xC355520747171Bd75f505E8cd12f935944bD783b",
// "tokens" : [
// {
// "name": "Token A",
// "address": "0x103BAA273da5C2FEF2d1B8f839044A9bd07Bc1A1"
// }
// ]
// }
const obj = {
parentnetUrl: config["parentnetURL"],
parentnetChainId: config["parentnetID"],
parentnetApp: config["parentnetSubswap"],
subnetUrl: config["subnetURL"],
subnetChainId: config["subnetID"],
subnetApp: config["subnetSubswap"],
tokens: [
{
name: "Subnet Sample Token",
address:
config["subnetSampleTokenAddress"] ||
"0x1111111111111111111111111111111111111111",
},
],
};

fs.writeFileSync(
"./mount/subswap-frontend.config.json",
JSON.stringify(obj, null, 2)
);
}

module.exports = {
subswap,
};
Loading