Skip to content

Commit

Permalink
fix: Publish zToken contract as an npm package and import into zNS (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Whytecrowe authored Jun 13, 2023
2 parents 7acdb80 + ba58441 commit 5aa6ddc
Show file tree
Hide file tree
Showing 4 changed files with 795 additions and 838 deletions.
19 changes: 3 additions & 16 deletions contracts/token/mocks/ZeroTokenMock.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ZeroToken } from "@zero-tech/ztoken/contracts/ZeroToken.sol";
import { IZeroTokenMock } from "./IZeroTokenMock.sol";

contract ZeroTokenMock is ERC20, IZeroTokenMock {
contract ZeroTokenMock is ZeroToken {
uint256 private _totalSupply = 1000000 * 10 ** 18;

constructor(address owner) ERC20("Zero Token Mock", "ZTM") {
_mint(owner, _totalSupply);
}

function balanceOf(
address user
) public view override(ERC20, IERC20) returns (uint) {
return super.balanceOf(user);
}

function burn(address account, uint256 amount) external override {
_burn(account, amount);
}
constructor(address owner) {}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-toolbox": "2.0.2",
"@nomiclabs/hardhat-ethers": "2.2.2",
"@nomiclabs/hardhat-etherscan": "3.0.0",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@openzeppelin/contracts": "4.8.2",
"@openzeppelin/contracts-upgradeable": "4.8.2",
"@openzeppelin/hardhat-upgrades": "^1.26.0",
Expand All @@ -43,9 +43,10 @@
"@types/mocha": "9.1.0",
"@types/node": "^18.15.11",
"@zero-tech/eslint-config-cpt": "0.2.7",
"@zero-tech/ztoken": "1.0.1",
"chai": "4.2.0",
"eslint": "^8.37.0",
"ethers": "5.4.7",
"ethers": "5.5.1",
"hardhat": "2.13.0",
"hardhat-gas-reporter": "1.0.8",
"logdown": "3.3.1",
Expand Down
53 changes: 47 additions & 6 deletions test/helpers/deployZNS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
ZNSRegistry__factory,
ZNSTreasury,
ZNSTreasury__factory,
ZeroToken,
ZeroToken__factory,
} from "../../typechain";
import { DeployZNSParams, PriceParams, RegistrarConfig, ZNSContracts } from "./types";
import { ethers, upgrades } from "hardhat";
Expand All @@ -28,6 +30,33 @@ import {
import { deployAccessController, REGISTRAR_ROLE } from "./access";
import { BigNumber } from "ethers";

export const deployZeroToken = async (
deployer : SignerWithAddress
) => {
const factory = new ZeroToken__factory(deployer);

const zeroToken = await hre.upgrades.deployProxy(
factory,
[
"ZERO",
"ZERO",
],
{
kind: "transparent",
}
) as ZeroToken;

const mintAmount = ethers.utils.parseEther("10000");

// Mint 10,000 ZERO for self
await zeroToken.mint(zeroToken.address, mintAmount);

// Mint 100 ZERO for deployer
await zeroToken.mint(deployer.address, mintAmount.div("100"));

return zeroToken;
};

export const deployRegistry = async (
deployer : SignerWithAddress,
accessControllerAddress : string
Expand Down Expand Up @@ -170,6 +199,12 @@ export const deployRegistrar = async (
return registrar;
};

/**
* We use this script to aid in testing, NOT for anything more
* such as deploying to live testnets or mainnet. Do not use any
* of the code present for tasks other than testing behavior on a
* local hardhat build
*/
export const deployZNS = async ({
deployer,
governorAddresses,
Expand All @@ -184,11 +219,21 @@ export const deployZNS = async ({
adminAddresses: [deployer.address, ...adminAddresses],
});

// We deploy every contract as a UUPS proxy, but ZERO is already
// deployed as a transparent proxy. This means that there is already
// a proxy admin deployed to the network. Because future deployments
// warn when this is the case, we silence the warning from hardhat here
// to not clog the test output.
await hre.upgrades.silenceWarnings();

const registry = await deployRegistry(deployer, accessController.address);

const domainToken = await deployDomainToken(deployer, accessController.address);

const zeroTokenMock = await deployZeroTokenMock(deployer);
// While we do use the real ZeroToken contract, it is only deployed as a mock here
// for testing purposes that verify expected behavior of other contracts.
// This should not be used in any other context than deploying to a local hardhat testnet.
const zeroTokenMock = await deployZeroToken(deployer);

const addressResolver = await deployAddressResolver(
deployer,
Expand Down Expand Up @@ -231,16 +276,12 @@ export const deployZNS = async ({
registrar,
};

// Final configuration steps
// TODO AC: remove all redundant calls here! and delete hashing of the root and the need
// for Registrar to be owner/operator of the root

// TODO verify tests are fine without this line
// await registry.connect(deployer).setOwnerOperator(registrar.address, true);

// Give 15 ZERO to the deployer and allowance to the treasury
// Give allowance to the treasury from the deployer
await zeroTokenMock.connect(deployer).approve(treasury.address, ethers.constants.MaxUint256);
await zeroTokenMock.transfer(deployer.address, ethers.utils.parseEther("15"));

return znsContracts;
};
Loading

0 comments on commit 5aa6ddc

Please sign in to comment.