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

[Multi ZNS] Replacing the meowToken with zToken #117

Open
wants to merge 14 commits into
base: rc/zns-meowchain
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ SILENT_LOGGER="false" | "true"
# Boolean value for if we deploy the mock
# true = we deploy the mock
# false = we use a hard coded address and pull data from chain
MOCK_MEOW_TOKEN=
# Address of the MEOW Token deployed to the network PRIOR to running Campaign or any other EXISTING token
# This is only used if MOCK_MEOW_TOKEN is set to false (`test` and `prod` environments)
MOCK_Z_TOKEN=
# Address of the Z Token deployed to the network PRIOR to running Campaign or any other EXISTING token
# This is only used if MOCK_Z_TOKEN is set to false (`test` and `prod` environments)
STAKING_TOKEN_ADDRESS=

# Environment variables to create an entirely custom config when `env_level` above is not dev
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ docker*.tgz

# We don't ever use the generated manifests
.openzeppelin
/.vscode
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Create `.env` file in the root directory and add the following variables:
ENV_LEVEL: "dev" # local dev environment
MONGO_DB_URI: "mongodb://localhost:27018" # local instance of MongoDB in the Docker
MONGO_DB_NAME: "zns-campaign" # name of the database
MOCK_MEOW_TOKEN: "true" # use mock MeowToken contract for local testing
MOCK_Z_TOKEN: "true" # use mock ZToken contract for local testing
SILENT_LOGGER: "true" # disable logging for tests
```

Expand Down
16 changes: 0 additions & 16 deletions contracts/token/mocks/MeowTokenMock.sol

This file was deleted.

34 changes: 34 additions & 0 deletions contracts/token/mocks/ZTokenMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { ZToken } from "@zero-tech/z-token/contracts/ZToken.sol";


contract ZTokenMock is ZToken {
MichaelKorchagin marked this conversation as resolved.
Show resolved Hide resolved
constructor(
string memory _name,
string memory _symbol,
address _defaultAdmin,
uint48 _initialAdminDelay,
address _minter,
address _mintBeneficiary,
uint256 _initialSupplyBase,
uint16[] memory _inflationRates,
uint16 _finalInflationRate
) ZToken(
_name,
_symbol,
_defaultAdmin,
_initialAdminDelay,
_minter,
_mintBeneficiary,
_initialSupplyBase,
_inflationRates,
_finalInflationRate
) {}

// for tests, to identify mock contract
function identifyMock() external pure returns (string memory) {
return "This is a mock token";
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@types/mocha": "^9.1.0",
"@types/node": "^18.15.11",
"@zero-tech/eslint-config-cpt": "0.2.7",
"@zero-tech/ztoken": "2.1.0",
"@zero-tech/z-token": "1.0.0",
"chai": "^4.3.10",
"eslint": "^8.37.0",
"ethers": "^6.9.0",
Expand All @@ -83,4 +83,4 @@
"mongodb": "^6.1.0",
"winston": "^3.11.0"
}
}
}
82 changes: 59 additions & 23 deletions src/deploy/campaign/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ import {
INVALID_CURVE_ERR,
MONGO_URI_ERR,
INVALID_ENV_ERR, NO_ZERO_VAULT_ERR,
INITIAL_ADMIN_DELAY_DEFAULT,
INITIAL_SUPPLY_DEFAULT,
INFLATION_RATES_DEFAULT,
FINAL_INFLATION_RATE_DEFAULT,
Z_NAME_DEFAULT,
Z_SYMBOL_DEFAULT,
} from "../../../test/helpers";
import { ethers } from "ethers";
import { ICurvePriceConfig } from "../missions/types";
import { MeowMainnet } from "../missions/contracts/meow-token/mainnet-data";
import { ICurvePriceConfig, IZTokenConfig } from "../missions/types";
import process from "process";
import { ZSepolia } from "../missions/contracts/z-token/mainnet-data";


const getCustomAddresses = (
Expand Down Expand Up @@ -59,12 +66,14 @@ export const getConfig = async ({
admins,
zeroVaultAddress,
env, // this is ONLY used for tests!
zTokenConfig,
} : {
deployer : SignerWithAddress;
governors ?: Array<string>;
admins ?: Array<string>;
zeroVaultAddress ?: string;
env ?: string;
zTokenConfig ?: IZTokenConfig;
}) : Promise<IZNSCampaignConfig<SignerWithAddress>> => {
// Will throw an error based on any invalid setup, given the `ENV_LEVEL` set
const priceConfig = validateEnv(env);
Expand All @@ -78,31 +87,55 @@ export const getConfig = async ({

let zeroVaultAddressConf;

if (process.env.ENV_LEVEL === "dev") {
const zeroVaultAddressEnv = process.env.ZERO_VAULT_ADDRESS;
const mockZTokenEnv = process.env.MOCK_Z_TOKEN;
const envLevel = process.env.ENV_LEVEL;


// Get governor addresses set through env, if any
const governorAddresses = getCustomAddresses("GOVERNOR_ADDRESSES", deployerAddress, governors);
// Get admin addresses set through env, if any
const adminAddresses = getCustomAddresses("ADMIN_ADDRESSES", deployerAddress, admins);

let zConfig : IZTokenConfig | undefined;

if (envLevel === "dev") {
requires(
!!zeroVaultAddress || !!process.env.ZERO_VAULT_ADDRESS,
!!zeroVaultAddress || !!zeroVaultAddressEnv,
"Must pass `zeroVaultAddress` to `getConfig()` for `dev` environment"
);
zeroVaultAddressConf = zeroVaultAddress || process.env.ZERO_VAULT_ADDRESS;
zeroVaultAddressConf = zeroVaultAddress || zeroVaultAddressEnv;

if (!zTokenConfig) {
// in case, we didn't provide addresses, it will choose the governon as `admin` argument,
// deployAdmin as `minter` and first passed admin as `mintBeneficiary`.
zConfig = {
name: Z_NAME_DEFAULT,
symbol: Z_SYMBOL_DEFAULT,
defaultAdmin: governorAddresses[0],
initialAdminDelay: INITIAL_ADMIN_DELAY_DEFAULT,
minter: deployer.address,
mintBeneficiary: adminAddresses[0],
initialSupplyBase: INITIAL_SUPPLY_DEFAULT,
inflationRates: INFLATION_RATES_DEFAULT,
finalInflationRate: FINAL_INFLATION_RATE_DEFAULT,
};
} else {
zConfig = zTokenConfig;
}
} else {
zeroVaultAddressConf = process.env.ZERO_VAULT_ADDRESS;
zeroVaultAddressConf = zeroVaultAddressEnv;
}

// Domain Token Values
const royaltyReceiver = process.env.ENV_LEVEL !== "dev" ? process.env.ROYALTY_RECEIVER! : zeroVaultAddressConf;
const royaltyReceiver = envLevel !== "dev" ? process.env.ROYALTY_RECEIVER! : zeroVaultAddressConf;
const royaltyFraction =
process.env.ROYALTY_FRACTION
? BigInt(process.env.ROYALTY_FRACTION)
: DEFAULT_ROYALTY_FRACTION;

// Get governor addresses set through env, if any
const governorAddresses = getCustomAddresses("GOVERNOR_ADDRESSES", deployerAddress, governors);

// Get admin addresses set through env, if any
const adminAddresses = getCustomAddresses("ADMIN_ADDRESSES", deployerAddress, admins);

const config : IZNSCampaignConfig<SignerWithAddress> = {
env: process.env.ENV_LEVEL!,
env: envLevel!,
deployAdmin: deployer,
governorAddresses,
adminAddresses,
Expand All @@ -113,8 +146,9 @@ export const getConfig = async ({
defaultRoyaltyFraction: royaltyFraction,
},
rootPriceConfig: priceConfig,
zTokenConfig: zConfig,
zeroVaultAddress: zeroVaultAddressConf as string,
mockMeowToken: process.env.MOCK_MEOW_TOKEN === "true",
mockZToken: mockZTokenEnv === "true",
stakingTokenAddress: process.env.STAKING_TOKEN_ADDRESS!,
postDeploy: {
tenderlyProjectSlug: process.env.TENDERLY_PROJECT_SLUG!,
Expand Down Expand Up @@ -143,11 +177,13 @@ export const validateEnv = (
// Validate price config first since we have to return it
const priceConfig = getValidateRootPriceConfig();

const mockZTokenEnv = process.env.MOCK_Z_TOKEN;

if (envLevel === "dev") return priceConfig;

if (envLevel === "test" || envLevel === "dev") {
if (process.env.MOCK_MEOW_TOKEN === "false" && !process.env.STAKING_TOKEN_ADDRESS) {
throw new Error("Must provide a staking token address if not mocking MEOW token in `dev` environment");
if (mockZTokenEnv === "false" && !process.env.STAKING_TOKEN_ADDRESS) {
throw new Error("Must provide a staking token address if not mocking Z token in `dev` environment");
}
}

Expand All @@ -172,19 +208,19 @@ export const validateEnv = (

// Mainnet
if (envLevel === "prod") {
requires(process.env.MOCK_MEOW_TOKEN === "false", NO_MOCK_PROD_ERR);
requires(process.env.STAKING_TOKEN_ADDRESS === MeowMainnet.address, STAKING_TOKEN_ERR);
requires(!process.env.MONGO_DB_URI.includes("localhost"), MONGO_URI_ERR);
requires(mockZTokenEnv === "false", NO_MOCK_PROD_ERR);
requires(process.env.STAKING_TOKEN_ADDRESS === ZSepolia.address, STAKING_TOKEN_ERR);
}

if (process.env.VERIFY_CONTRACTS === "true") {
requires(!!process.env.ETHERSCAN_API_KEY, "Must provide an Etherscan API Key to verify contracts");
requires(process.env.ETHERSCAN_API_KEY === "true", "Must provide an Etherscan API Key to verify contracts");
}

if (process.env.MONITOR_CONTRACTS === "true") {
requires(!!process.env.TENDERLY_PROJECT_SLUG, "Must provide a Tenderly Project Slug to monitor contracts");
requires(!!process.env.TENDERLY_ACCOUNT_ID, "Must provide a Tenderly Account ID to monitor contracts");
requires(!!process.env.TENDERLY_ACCESS_KEY, "Must provide a Tenderly Access Key to monitor contracts");
requires(process.env.TENDERLY_PROJECT_SLUG === "true", "Must provide a Tenderly Project Slug to monitor contracts");
requires(process.env.TENDERLY_ACCOUNT_ID === "true", "Must provide a Tenderly Account ID to monitor contracts");
requires(process.env.TENDERLY_ACCESS_KEY === "true", "Must provide a Tenderly Access Key to monitor contracts");
}

return priceConfig;
Expand Down
15 changes: 8 additions & 7 deletions src/deploy/campaign/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { HardhatEthersSigner, SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { DefenderRelaySigner } from "@openzeppelin/defender-sdk-relay-signer-client/lib/ethers";
import { ICurvePriceConfig } from "../missions/types";
import { ICurvePriceConfig, IZTokenConfig } from "../missions/types";
import { IContractState, IDeployCampaignConfig } from "@zero-tech/zdc";
import {
MeowTokenMock,
ZNSAccessController,
ZNSAddressResolver,
ZNSCurvePricer,
Expand All @@ -13,8 +12,9 @@ import {
ZNSRootRegistrar,
ZNSSubRegistrar,
ZNSTreasury,
ZToken,
ZTokenMock,
} from "../../../typechain";
import { MeowToken } from "@zero-tech/ztoken/typechain-js";

export type IZNSSigner = HardhatEthersSigner | DefenderRelaySigner | SignerWithAddress;

Expand All @@ -30,8 +30,9 @@ export interface IZNSCampaignConfig <Signer> extends IDeployCampaignConfig<Signe
defaultRoyaltyFraction : bigint;
};
rootPriceConfig : ICurvePriceConfig;
zTokenConfig ?: IZTokenConfig;
zeroVaultAddress : string;
mockMeowToken : boolean;
mockZToken : boolean;
stakingTokenAddress : string;
postDeploy : {
tenderlyProjectSlug : string;
Expand All @@ -44,8 +45,8 @@ export type ZNSContract =
ZNSAccessController |
ZNSRegistry |
ZNSDomainToken |
MeowTokenMock |
MeowToken |
ZTokenMock |
ZToken |
ZNSAddressResolver |
ZNSCurvePricer |
ZNSTreasury |
Expand All @@ -57,7 +58,7 @@ export interface IZNSContracts extends IContractState<ZNSContract> {
accessController : ZNSAccessController;
registry : ZNSRegistry;
domainToken : ZNSDomainToken;
meowToken : MeowTokenMock;
zToken : ZTokenMock;
addressResolver : ZNSAddressResolver;
curvePricer : ZNSCurvePricer;
treasury : ZNSTreasury;
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/missions/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export * from "./domain-token";
export * from "./treasury";
export * from "./curve-pricer";
export * from "./access-controller";
export * from "./meow-token/meow-token";
export * from "./z-token/z-token";
export * from "./fixed-pricer";
export * from "./sub-registrar";
Loading