Skip to content

Commit

Permalink
Proxy upgradable
Browse files Browse the repository at this point in the history
  • Loading branch information
Corantin committed Jul 29, 2023
1 parent 955e9d3 commit feba0e7
Show file tree
Hide file tree
Showing 27 changed files with 4,127 additions and 765 deletions.
4 changes: 3 additions & 1 deletion packages/hardhat/contracts/QuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import "./libraries/Deposit.sol";
import "./libraries/Models.sol";
import "./Quest.sol";

contract QuestFactoryy is OwnableUpgradeable {
contract QuestFactory is OwnableUpgradeable {
using DepositLib for Models.Deposit;

address public aragonGovernAddress;
Models.Deposit public createDeposit;
Models.Deposit public playDeposit;
uint256 public constant version = 3;

event QuestCreated(
address questAddress,
Expand Down Expand Up @@ -53,6 +54,7 @@ contract QuestFactoryy is OwnableUpgradeable {
uint256 _playDepositAmount,
address _initialOwner
) public initializer {
__Ownable_init();
aragonGovernAddress = _aragonGovernAddress;
setCreateDeposit(_createDepositToken, _createDepositAmount);
setPlayDeposit(_playDepositToken, _playDepositAmount);
Expand Down
3 changes: 1 addition & 2 deletions packages/hardhat/deploy/deploy-quest_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default async (
playDepositAmount: number;
}
) => {
const { deploy } = deployments;
const { deployer, govern, owner } = await getNamedAccounts();
const { govern, owner } = await getNamedAccounts();
const createDeposit = args
? { token: args.createDepositToken, amount: args.createDepositAmount }
: defaultConfig.CreateQuestDeposit[network.name];
Expand Down
44 changes: 27 additions & 17 deletions packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import fs from "fs";
import chalk from "chalk";
import "@tenderly/hardhat-tenderly";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-ethers";
import "@openzeppelin/hardhat-upgrades";
import "@nomiclabs/hardhat-ethers";
import "hardhat-typechain";
import "typechain";
import { task, HardhatUserConfig, types } from "hardhat/config";
Expand Down Expand Up @@ -246,6 +246,10 @@ const hardhatConfig: HardhatUserConfig = {
goerli: defaultConfig.RootOwner.goerli,
}, // Goerli Gnosis Safe address
},
typechain: {
outDir: "typechain",
target: "ethers-v5",
},
};

const DEBUG = false;
Expand All @@ -258,7 +262,7 @@ function debug(text) {

task("wallet", "Create a wallet (pk) link", async (_, { ethers }) => {
const randomWallet = ethers.Wallet.createRandom();
const privateKey = randomWallet.signingKey.privateKey;
const privateKey = randomWallet._signingKey().privateKey;
console.log("🔐 WALLET Generated as " + randomWallet.address + "");
console.log("🔗 http://localhost:3000/pk#" + privateKey);
});
Expand All @@ -272,7 +276,7 @@ task("fundedwallet", "Create a wallet (pk) link and fund it with deployer?")

.setAction(async (taskArgs, { network, ethers }) => {
const randomWallet = ethers.Wallet.createRandom();
const privateKey = randomWallet.signingKey.privateKey;
const privateKey = randomWallet._signingKey().privateKey;
console.log("🔐 WALLET Generated as " + randomWallet.address + "");
const url = taskArgs.url ? taskArgs.url : "http://localhost:3000";

Expand All @@ -287,13 +291,13 @@ task("fundedwallet", "Create a wallet (pk) link and fund it with deployer?")
const amount = taskArgs.amount ? taskArgs.amount : "0.01";
const tx = {
to: randomWallet.address,
value: utils.parseEther(amount),
value: ethers.utils.parseEther(amount),
};

// SEND USING LOCAL DEPLOYER MNEMONIC IF THERE IS ONE
// IF NOT SEND USING LOCAL HARDHAT NODE:
if (localDeployerMnemonic) {
let deployerWallet = ethers.Wallet.fromPhrase(localDeployerMnemonic);
let deployerWallet = ethers.Wallet.fromMnemonic(localDeployerMnemonic);
const signers = await ethers.getSigners();
deployerWallet = deployerWallet.connect(signers[0].provider);
console.log(
Expand Down Expand Up @@ -458,12 +462,12 @@ task(
for (const n in hardhatConfig.networks) {
// console.log(networks[n],n)
try {
const provider = new ethers.JsonRpcProvider(
const provider = new ethers.providers.JsonRpcProvider(
(hardhatConfig.networks[n] as HttpNetworkUserConfig).url
);
const balance = await provider.getBalance(address);
console.log(" -- " + n + " -- -- -- 📡 ");
console.log(" balance: " + utils.formatEther(balance));
console.log(" balance: " + ethers.utils.formatEther(balance));
console.log(
" nonce: " + (await provider.getTransactionCount(address))
);
Expand All @@ -477,8 +481,8 @@ task(
);

async function addr(ethers, addr) {
if (isAddress(addr)) {
return getAddress(addr);
if (ethers.isAddress(addr)) {
return ethers.getAddress(addr);
}
const accounts = await ethers.provider.listAccounts();
if (accounts[addr] !== undefined) {
Expand All @@ -503,7 +507,7 @@ task("balance", "Prints an account's balance")
const balance = await ethers.provider.getBalance(
await addr(ethers, taskArgs.account)
);
console.log(formatUnits(balance, "ether"), "ETH");
console.log(ethers.utils.formatUnits(balance, "ether"), "ETH");
});

function send(signer, txparams) {
Expand Down Expand Up @@ -538,9 +542,12 @@ task("send", "Send ETH")
const txRequest = {
from: signerAddress,
to,
value: parseUnits(taskArgs.amount ? taskArgs.amount : "0", "ether"),
value: ethers.utils.parseUnits(
taskArgs.amount ? taskArgs.amount : "0",
"ether"
),
nonce: await ethers.provider.getTransactionCount(signerAddress),
gasPrice: parseUnits(
gasPrice: ethers.utils.parseUnits(
taskArgs.gasPrice ? taskArgs.gasPrice : "1.001",
"gwei"
),
Expand All @@ -555,7 +562,8 @@ task("send", "Send ETH")
}

debug(
BigNumber.from(txRequest.gasPrice).div(1000000000).toHexString() + " gwei"
ethers.BigNumber.from(txRequest.gasPrice).div(1000000000).toHexString() +
" gwei"
);
debug(JSON.stringify(txRequest, null, 2));

Expand Down Expand Up @@ -1067,7 +1075,7 @@ task("deployAll:goerli")
.setAction(deployAll);

task("grantGovernQueue").setAction(
async (_args, { web3, getNamedAccounts }) => {
async (_args, { ethers, getNamedAccounts }) => {
const { owner } = await getNamedAccounts();
const publicQueueFonctions = [
"schedule",
Expand All @@ -1086,11 +1094,12 @@ task("grantGovernQueue").setAction(
console.log("GovernQueue roles:");
const publicGrant = "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF";
let roles = [];
var governQueueAbiInterface = new ethers.utils.Interface(GovernQueueAbi);
for (const obj of GovernQueueAbi) {
if (obj.type !== "function" || !queueFonctions.includes(obj.name)) {
continue;
}
let signature = web3.eth.abi.encodeFunctionSignature(obj as any);
let signature = governQueueAbiInterface.getSighash(obj.name);
roles.push({
signature,
address: ownerOnlyQueueFonctions.includes(obj.name)
Expand All @@ -1104,11 +1113,12 @@ task("grantGovernQueue").setAction(
`[${roles.map((x) => `[0,"${x.signature}","${x.address}"]`).join(",")}]`
);
console.log("Govern roles:");
var governAbiInterface = new ethers.utils.Interface(GovernAbi);
for (const obj of GovernAbi) {
if (obj.type !== "function" || !aclGovernFunctions.includes(obj.name)) {
continue;
}
let signature = web3.eth.abi.encodeFunctionSignature(obj as any);
let signature = governAbiInterface.getSighash(obj.name);
roles.push({
signature,
address: owner,
Expand Down Expand Up @@ -1136,7 +1146,7 @@ task("deployCeleste:goerli")
const { deployer, owner } = await getNamedAccounts();
const constructorArguments = [
args.feeToken,
utils.parseEther(args.feeAmount.toString()),
ethers.utils.parseEther(args.feeAmount.toString()),
];
const result = await deployments.deploy("OwnableCeleste", {
from: deployer,
Expand Down
167 changes: 85 additions & 82 deletions packages/hardhat/package.json
Original file line number Diff line number Diff line change
@@ -1,84 +1,87 @@
{
"name": "@1hive/quests-hardhat",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.10",
"@types/chai": "^4.2.21",
"@types/mocha": "^9.0.0",
"@types/node": "^14.14.22",
"@types/ramda": "^0.27.38",
"chai": "^4.2.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.23.1",
"eslint-plugin-react-hooks": "^4.2.0",
"mocha": "^9.1.1",
"prettier": "^2.3.1",
"prettier-plugin-solidity": "^1.0.0-beta.14",
"ts-generator": "^0.1.1",
"ts-node": "^10.2.1",
"typescript": "^4.2.2"
},
"dependencies": {
"@eth-optimism/hardhat-ovm": "0.2.2",
"@ethersproject/hardware-wallets": "^5.0.14",
"@ethersproject/solidity": "^5.0.9",
"@nomicfoundation/hardhat-network-helpers": "^1.0.6",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/contracts": "^4.9.2",
"@tenderly/hardhat-tenderly": "1.0.10",
"@typechain/ethers-v5": "^5.0.0",
"chalk": "^4.1.0",
"cross-var": "^1.1.0",
"dotenv": "^10.0.0",
"dotenv-cli": "^4.0.0",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.6",
"ganache-cli": "^6.12.2",
"hardhat": "2.9.5",
"hardhat-deploy": "^0.9.0",
"hardhat-typechain": "^0.3.5",
"node-watch": "^0.7.0",
"qrcode-terminal": "^0.12.0",
"ramda": "^0.27.1",
"solidity-coverage": "0.8.2",
"typechain": "^4.0.0"
},
"scripts": {
"chain": "hardhat node --hostname 0.0.0.0 --network hardhat --no-deploy --show-accounts",
"fork": "dotenv -- cross-var hardhat node --no-deploy --network hardhat --fork https://mainnet.infura.io/v3/%INFURA_ID%",
"test": "hardhat test --network hardhat",
"test-coverage": "hardhat coverage --network localhost --testfiles \"test/*.test.ts\" --solcoverjs ./test/coverage.solcover.ts",
"compile": "hardhat compile",
"deploy": "hardhat deploy",
"deploy:rinkeby": "hardhat deploy --network rinkeby",
"deploy:goerli": "hardhat deploy --network goerli",
"deploy:gnosis": "hardhat deploy --network xdai",
"deploy:local": "hardhat deploy",
"deploy-all:goerli": "hardhat deployAll:goerli --network goerli",
"deploy-all:gnosis": "hardhat deployAll:goerli --network xdai",
"queue-config:goerli": "hardhat generateGovernQueueConfig:goerli",
"queue-config:gnosis": "hardhat generateGovernQueueConfig:gnosis",
"queue-grant:gnosis": "hardhat grantGovernQueue --network xdai",
"queue-grant:goerli": "hardhat grantGovernQueue --network goerli",
"deploy-all:local": "hardhat deployAll:goerli",
"console": "hardhat console",
"watch": "node scripts/watch.js",
"accounts": "hardhat accounts",
"balance": "hardhat balance",
"send": "hardhat send",
"generate": "hardhat generate",
"account": "hardhat account",
"verify:rinkeby": "hardhat verify-quests-contracts --network rinkeby",
"verify:goerli": "hardhat verify-quests-contracts --network goerli",
"ci": "yarn install --pure-lockfile --immutable --skip-builds"
}
"name": "@1hive/quests-hardhat",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.0.0",
"@types/chai": "^4.2.21",
"@types/mocha": "^9.0.0",
"@types/node": "^14.14.22",
"@types/ramda": "^0.27.38",
"chai": "^4.2.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.23.1",
"eslint-plugin-react-hooks": "^4.2.0",
"mocha": "^9.1.1",
"prettier": "^2.3.1",
"prettier-plugin-solidity": "^1.0.0-beta.14",
"ts-generator": "^0.1.1",
"ts-node": "^10.2.1",
"typechain-target-ethers-v5": "^5.0.1",
"typescript": "^4.2.2"
},
"dependencies": {
"@eth-optimism/hardhat-ovm": "0.2.2",
"@ethersproject/hardware-wallets": "^5.0.14",
"@ethersproject/solidity": "^5.0.9",
"@nomicfoundation/hardhat-network-helpers": "^1.0.6",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/contracts": "^4.9.2",
"@openzeppelin/contracts-upgradeable": "^4.9.3",
"@openzeppelin/hardhat-upgrades": "^1.0.0",
"@tenderly/hardhat-tenderly": "1.0.10",
"@typechain/ethers-v5": "^5.0.0",
"chalk": "^4.1.0",
"cross-var": "^1.1.0",
"dotenv": "^10.0.0",
"dotenv-cli": "^4.0.0",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.0.0",
"ganache-cli": "^6.12.2",
"hardhat": "2.17.0",
"hardhat-deploy": "^0.9.0",
"hardhat-typechain": "^0.3.5",
"node-watch": "^0.7.0",
"qrcode-terminal": "^0.12.0",
"ramda": "^0.27.1",
"solidity-coverage": "0.8.2",
"typechain": "^4.0.0"
},
"scripts": {
"chain": "hardhat node --hostname 0.0.0.0 --network hardhat --no-deploy --show-accounts",
"fork": "dotenv -- cross-var hardhat node --no-deploy --network hardhat --fork https://mainnet.infura.io/v3/%INFURA_ID%",
"test": "hardhat test --network hardhat",
"test-coverage": "hardhat coverage --network localhost --testfiles \"test/*.test.ts\" --solcoverjs ./test/coverage.solcover.ts",
"compile": "hardhat compile",
"deploy": "hardhat deploy",
"deploy:rinkeby": "hardhat deploy --network rinkeby",
"deploy:goerli": "hardhat deploy --network goerli",
"deploy:gnosis": "hardhat deploy --network xdai",
"deploy:local": "hardhat deploy",
"deploy-all:goerli": "hardhat deployAll:goerli --network goerli",
"deploy-all:gnosis": "hardhat deployAll:goerli --network xdai",
"queue-config:goerli": "hardhat generateGovernQueueConfig:goerli",
"queue-config:gnosis": "hardhat generateGovernQueueConfig:gnosis",
"queue-grant:gnosis": "hardhat grantGovernQueue --network xdai",
"queue-grant:goerli": "hardhat grantGovernQueue --network goerli",
"deploy-all:local": "hardhat deployAll:goerli",
"console": "hardhat console",
"watch": "node scripts/watch.js",
"accounts": "hardhat accounts",
"balance": "hardhat balance",
"send": "hardhat send",
"generate": "hardhat generate",
"account": "hardhat account",
"verify:rinkeby": "hardhat verify-quests-contracts --network rinkeby",
"verify:goerli": "hardhat verify-quests-contracts --network goerli",
"ci": "yarn install --pure-lockfile --immutable --skip-builds"
}
}
5 changes: 2 additions & 3 deletions packages/hardhat/test/Quest.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import { ethers, network } from "hardhat";
import { use, expect } from "chai";
import { solidity } from "ethereum-waffle";
Expand All @@ -9,8 +8,8 @@ import {
fromNumber,
} from "./test-helper";
import { TokenMock, TokenMock__factory } from "../typechain";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signers";
import { time } from "@nomicfoundation/hardhat-network-helpers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address";

use(solidity);

Expand Down Expand Up @@ -937,7 +936,7 @@ describe("[Contract] Quest", function () {
);
});
});
describe.only("constructor()", () => {
describe("constructor()", () => {
it("SHOULD revert if max players greater than 0 and isWhiteList", async () => {
//Arrange
const maxPlayers = 3;
Expand Down
Loading

0 comments on commit feba0e7

Please sign in to comment.