Skip to content
Open
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
39 changes: 25 additions & 14 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,31 @@ const config : HardhatUserConfig = {
gasReporter: {
enabled: false,
},
networks: {},
// etherscan: {
// apiKey: `${process.env.ETHERSCAN_API_KEY}`,
// customChains: [
// {
// network: "meowtestnet",
// chainId: 883424730,
// urls: {
// apiURL: "https://meowchain-testnet-blockscout.eu-north-2.gateway.fm/api/",
// browserURL: "https://meowchain-testnet-blockscout.eu-north-2.gateway.fm/",
// },
// },
// ],
// },
networks: {
// zephyr: {
// url: process.env.ZCHAIN_ZEPHYR_RPC_URL,
// chainId: 1417429182,
// accounts: [
// `${process.env.DEPLOY_ADMIN_ZEPHYR_PK}`,
// `${process.env.TESTNET_PRIVATE_KEY_F}`,
// `${process.env.TESTNET_PRIVATE_KEY_USER_1}`,
// ],
// },
},
etherscan: {
apiKey: {
zephyr: `${process.env.ETHERSCAN_API_KEY}` },
customChains: [
{
network: "zephyr",
chainId: 1417429182,
urls: {
apiURL: "https://zephyr-blockscout.eu-north-2.gateway.fm/api/",
browserURL: "https://zephyr-blockscout.eu-north-2.gateway.fm/",
},
},
],
},
docgen: {
pages: "files",
templates: "docs/docgen-templates",
Expand Down
7 changes: 7 additions & 0 deletions src/deploy/campaign/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
} from "@zero-tech/zdc";
import {
Match,
MockERC20,
MockERC721,
StakingERC20,
StakingERC721,
TimelockController,
Expand Down Expand Up @@ -100,6 +102,8 @@ export type ZModulesContract =
StakingERC721 |
ZeroVotingERC20 |
ZeroVotingERC721 |
MockERC20 |
MockERC721 |
ZDAO |
Match |
TimelockController |
Expand All @@ -110,6 +114,9 @@ export interface IZModulesContracts extends IContractState<ZModulesContract> {
staking721 : StakingERC721;
votingErc20 : ZeroVotingERC20;
votingErc721 : ZeroVotingERC721;
mockErc20STK : MockERC20;
mockErc20REW : MockERC20;
mockErc721STK : MockERC721;
zDao : ZDAO;
match : Match;
timelockController : TimelockController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { IZModulesConfig } from "../../campaign/types";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { EnvironmentLevels } from "@zero-tech/zdc";
import { ZeroHash } from "ethers";
import * as hre from "hardhat";
import { LP_TOKEN_ADDRESS, WILD_TOKEN_ADDRESS } from "./constants";
import { getBaseZModulesConfig } from "../../campaign/base-campaign-config";

Expand Down
183 changes: 183 additions & 0 deletions test/helpers/staking-dao-deploy-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import * as hre from "hardhat";
import fs from "fs";
import path from "path";
import {
getStaking20SystemConfig,
getStaking721SystemConfig,
} from "../../src/deploy/campaign/staking-system-config";
import {
IZModulesConfig,
IZModulesContracts,
} from "../../src/deploy/campaign/types";
import { DeployCampaign } from "@zero-tech/zdc";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { runZModulesCampaign } from "../../src/deploy/campaign/campaign";
import {
getDao20SystemConfig,
getDao721SystemConfig,
} from "../../src/deploy/campaign/dao-system-config";
import { ZModulesZeroVotingERC20DM } from "../../src/deploy/missions/voting-erc20/voting20.mission";
import { ZModulesZeroVotingERC721DM } from "../../src/deploy/missions/voting-erc721/voting721.mission";
import { ZModulesTimelockControllerDM } from "../../src/deploy/missions/dao/timelock.mission";
import { ZModulesZDAODM } from "../../src/deploy/missions/dao/zdao.mission";
import { getZModulesLogger } from "../../src/deploy/mongo";
import { ZModulesStakingERC20DM } from "../../src/deploy/missions/staking-erc20/staking20.mission";
import { ZModulesStakingERC721DM } from "../../src/deploy/missions/staking-erc721/staking721.mission";
import { getMockERC20Mission, TokenTypes } from "../../src/deploy/missions/mocks/mockERC20.mission";
import { getBaseZModulesConfig } from "../../src/deploy/campaign/base-campaign-config";
import { getMockERC721Mission } from "../../src/deploy/missions/mocks/mockERC721.mission";


let config : IZModulesConfig;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let campaign : DeployCampaign<
HardhatRuntimeEnvironment,
SignerWithAddress,
IZModulesConfig,
IZModulesContracts>;

export const mockDeploy = async (shouldSetDBVersion : boolean) => {
config = await getBaseZModulesConfig();

campaign = await runZModulesCampaign({
config,
missions: [
getMockERC20Mission({
tokenType: TokenTypes.staking,
tokenName: "Staking Token",
tokenSymbol: "STK",
}),
getMockERC20Mission({
tokenType: TokenTypes.rewards,
tokenName: "Rewards Token",
tokenSymbol: "RWD",
}),
getMockERC721Mission({
tokenType: TokenTypes.staking,
tokenName: "Staking Token",
tokenSymbol: "STK",
baseUri: "0://NFT/",
}),
],
});

if (shouldSetDBVersion) {
const {
curDbVersion,
} = campaign.dbAdapter.versioner;

process.env.MONGO_DB_VERSION = curDbVersion;
}
};

export const stakingDeploy = async (is721 : boolean) => {
const [ deployAdmin, fWallet, user2 ] = await hre.ethers.getSigners();

if (!is721) {
config = await getStaking20SystemConfig(user2, deployAdmin, fWallet);

campaign = await runZModulesCampaign({
config,
missions: [
ZModulesZeroVotingERC20DM,
ZModulesStakingERC20DM,
],
});
} else {
config = await getStaking721SystemConfig(user2, deployAdmin, fWallet);

campaign = await runZModulesCampaign({
config,
missions: [
ZModulesZeroVotingERC721DM,
ZModulesStakingERC721DM,
],
});
}
};

export const daoDeploy = async (is721 : boolean) => {
const [ deployAdmin, fWallet, user2 ] = await hre.ethers.getSigners();

if (!is721) {
config = await getDao20SystemConfig(user2, fWallet, deployAdmin);

campaign = await runZModulesCampaign({
config,
missions: [
ZModulesTimelockControllerDM,
ZModulesZDAODM,
],
});
} else {
config = await getDao721SystemConfig(user2, fWallet, deployAdmin);

campaign = await runZModulesCampaign({
config,
missions: [
ZModulesTimelockControllerDM,
ZModulesZDAODM,
],
});
}
};

const logger = getZModulesLogger({
logLevel: "debug",
makeLogFile: process.env.MAKE_LOG_FILE === "true",
silence: process.env.SILENT_LOGGER === "true",
});

// Error handling for the deployment
const loadAbiAndInterface = (contractName : string) => {
let abiPath;
if (contractName === "Staking20") {
abiPath = path.resolve("artifacts/contracts/staking/ERC20/StakingERC20.sol/StakingERC20.json");
} else if (contractName === "Staking721") {
abiPath = path.resolve("artifacts/contracts/staking/ERC721/StakingERC721.sol/StakingERC721.json");
} else if (contractName === "DAO") {
abiPath = path.resolve("artifacts/contracts/dao/ZDAO.sol/ZDAO.json");
}
if (!abiPath) logger.error("Deploy Helper: Couldn't find the contract ABI file");

const contractJson = JSON.parse(fs.readFileSync(abiPath as string, "utf8"));
const abi = contractJson.abi;
return new hre.ethers.Interface(abi);
};

// Changed the order of the deployQueue to match the order of the deploy functions
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const deployQueueForStakings = [
{ name: "MockDeploy", func: async () => mockDeploy(true) },
{ name: "Staking20", func: async () => stakingDeploy(true) },
{ name: "Staking721", func: async () => stakingDeploy(false) },
];

// Call this to run the deployment
export const runTestDeploy = async (
deployQueue : Array<{
name : string;
func : () => Promise<void>;
}>
) => {
for (const task of deployQueue) {
try {
await task.func();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error : any) {
const iface = loadAbiAndInterface(task.name);
const errorHash = error.data;
const decodedErr = iface.parseError(errorHash);

if (decodedErr) {
logger.error(`Deploy Helper: Custom error #${error.message}: ${decodedErr.name}; Args: ${decodedErr.args}`);
} else {
logger.error(`Deploy Helper: Couldn't decode the error! ${error}; ${errorHash}`);
}
process.exit(1);
}
}
logger.info("Deploy Helper: Deployment finished");
process.exit(0);
};
21 changes: 21 additions & 0 deletions test/helpers/transation-call.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TransactionResponse } from "ethers";
import { ZModulesContract } from "../../src/deploy";


export const executeTX = async (contract : ZModulesContract, contractCall : Promise<TransactionResponse>) => {
try {
const tx = await contractCall;
return await tx.wait(Number(process.env.CONFIRMATIONS_N));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error : any) {

const errorHash = error.data;
const decodedErr = contract.interface.parseError(errorHash);

if (decodedErr) {
throw new Error(`Custom error #${error.message}: ${decodedErr.name}; Args: ${decodedErr.args}`);
} else {
throw new Error(`Couldn't decode the error! ${error}; ${errorHash}`);
}
}
};
8 changes: 8 additions & 0 deletions test/helpers/voting/mine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ export const mineBlocks = async (numberOfBlocks : number) => {
await ethers.provider.send("evm_mine", []);
}
};

export const skipSeconds = async (sec : number | bigint) => {
if (typeof sec === "number") {
return new Promise(resolve => setTimeout(resolve, sec * 1000));
} else {
return new Promise(resolve => setTimeout(resolve, Number(sec) * 1000));
}
};
3 changes: 2 additions & 1 deletion test/mongo-global.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EnvironmentLevels } from "@zero-tech/zdc";
import { getZModulesMongoAdapter } from "../src/deploy/mongo";


Expand All @@ -8,6 +9,6 @@ export const mochaGlobalSetup = async () => {
export const mochaGlobalTeardown = async () => {
const mongoAdapter = await getZModulesMongoAdapter();
// the next line can be commented out to leave the DB after test to manually test
await mongoAdapter.dropDB();
if (process.env.ENV_LEVEL === EnvironmentLevels.dev) await mongoAdapter.dropDB();
await mongoAdapter.close();
};
Loading