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

[DADZ-287] automatic etherscan verification #8

Merged
merged 10 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PRIVATE_KEY=your_private_key
INFURA_API_KEY=infura_key

# ETHERSCAN
ETHERSCAN_API_KEY=XXXXX
OPTIMISM_API_KEY=XXXXX
2 changes: 1 addition & 1 deletion contracts/TestERC20.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.0;
pragma solidity ^0.7.0;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

Expand Down
54 changes: 47 additions & 7 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import "@nomicfoundation/hardhat-verify";
import "@nomiclabs/hardhat-waffle";
import "hardhat-typechain";
import "hardhat-watcher";
Expand All @@ -14,9 +14,20 @@ import "./tasks/deployPool";
import { resolve } from "path";

import { config as dotenvConfig } from "dotenv";
import {
MAUVE_CORE_COMPILER_SETTINGS,
MAUVE_PERIPHERY_LOWEST_COMPILER_SETTINGS,
MAUVE_PERIPHERY_LOW_COMPILER_SETTINGS,
MAUVE_PERIPHERY_DEFAULT_COMPILER_SETTINGS,
MAUVE_SWAP_ROUTER_COMPILER_SETTINGS,
} from "./src/compilerSettings";

dotenvConfig({ path: resolve(__dirname, "./.env") });

if (!process.env.INFURA_API_KEY) {
throw new Error("Missing Infura API KEY");
}

export default {
networks: {
localhost: {
Expand Down Expand Up @@ -52,15 +63,19 @@ export default {
optimismGoerli: {
accounts: [`0x${process.env.PRIVATE_KEY}`],
url: `https://opt-goerli.g.alchemy.com/v2/Ay4DBPd3SGpvm_8jJM-MS9MhHoqN8-dr`,
ra-phael marked this conversation as resolved.
Show resolved Hide resolved
gasPrice: 2000000000,
},
optimism: {
url: `https://optimism-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
},
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: process.env.ETHERSCAN_API_KEY,
apiKey: {
mainnet: process.env.ETHERSCAN_API_KEY || "",
optimisticEthereum: process.env.OPTIMISM_API_KEY || "",
optimisticGoerli: process.env.OPTIMISM_API_KEY || "",
goerli: process.env.ETHERSCAN_API_KEY || "",
},
},
contractSizer: {
runOnCompile: false,
Expand All @@ -70,10 +85,25 @@ export default {
{
version: "0.7.6",
},
{
version: "0.8.0",
},
],
overrides: {
"@violetprotocol/mauve-core/contracts/MauveFactory.sol":
MAUVE_CORE_COMPILER_SETTINGS,
"@violetprotocol/mauve-core/contracts/MauvePool.sol":
MAUVE_CORE_COMPILER_SETTINGS,
"@violetprotocol/mauve-periphery/contracts/libraries/NFTDescriptor.sol":
MAUVE_PERIPHERY_LOWEST_COMPILER_SETTINGS,
"@violetprotocol/mauve-periphery/contracts/NonfungiblePositionManager.sol":
MAUVE_PERIPHERY_LOW_COMPILER_SETTINGS,
"@violetprotocol/mauve-periphery/contracts/lens/MauveInterfaceMulticall.sol":
MAUVE_PERIPHERY_DEFAULT_COMPILER_SETTINGS,
"@violetprotocol/mauve-swap-router-contracts/contracts/MauveSwapRouter.sol":
MAUVE_SWAP_ROUTER_COMPILER_SETTINGS,
"@violetprotocol/mauve-swap-router-contracts/contracts/lens/Quoter.sol":
MAUVE_SWAP_ROUTER_COMPILER_SETTINGS,
"@violetprotocol/mauve-swap-router-contracts/contracts/lens/QuoterV2.sol":
MAUVE_SWAP_ROUTER_COMPILER_SETTINGS,
},
},
watcher: {
test: {
Expand All @@ -87,6 +117,16 @@ export default {
"@violetprotocol/ethereum-access-token/contracts/AccessTokenVerifier.sol",
"@violetprotocol/mauve-core/contracts/interfaces/IMauvePool.sol",
"@violetprotocol/mauve-core/contracts/interfaces/IMauveFactory.sol",
"@violetprotocol/mauve-core/contracts/MauveFactory.sol",
"@violetprotocol/mauve-swap-router-contracts/contracts/lens/Quoter.sol",
"@violetprotocol/mauve-swap-router-contracts/contracts/lens/QuoterV2.sol",
"@violetprotocol/mauve-swap-router-contracts/contracts/MauveSwapRouter.sol",
"@violetprotocol/mauve-periphery/contracts/libraries/NFTDescriptor.sol",
// TODO: Fix compilation of NonfungibleTokenPositionDescriptor
// See https://github.com/violetprotocol/mauve-deploy/issues/7
// "@violetprotocol/mauve-periphery/contracts/NonfungibleTokenPositionDescriptor.sol",
"@violetprotocol/mauve-periphery/contracts/NonfungiblePositionManager.sol",
"@violetprotocol/mauve-periphery/contracts/lens/MauveInterfaceMulticall.sol",
],
},
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"README.md"
],
"devDependencies": {
"@nomicfoundation/hardhat-verify": "^1.0.3",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^3.1.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@typechain/ethers-v5": "^4.0.0",
"@types/chai": "^4.1.7",
Expand Down Expand Up @@ -59,10 +59,10 @@
"hardhat": "^2.0.0"
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.2",
"@violetprotocol/mauve-swap-router-contracts": "1.5.2",
"@violetprotocol/mauve-core": "1.2.4",
"@violetprotocol/mauve-periphery": "1.8.6",
"@openzeppelin/contracts": "^3.4.2-solc-0.7",
"@violetprotocol/mauve-core": "1.2.5",
"@violetprotocol/mauve-periphery": "1.8.7",
"@violetprotocol/mauve-swap-router-contracts": "1.5.3",
"cli-table3": "^0.6.0"
}
}
20 changes: 12 additions & 8 deletions scripts/deployMauve.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { ethers } from "hardhat";
import * as hre from "hardhat";
import { deployMauve } from "../src/lib/deployMauve";

async function main() {
const [signer] = await ethers.getSigners();
const eatVerifier = "0x5Dbe2B4648FFAF2867F8Ad07d42003F5ce4b7d2C";
const violetId = "0x9A119a53cb065202d631ba01d55e3850eDcf3EAa";
const [signer] = await hre.ethers.getSigners();
const eatVerifier = "0x638734c011F68d2C6d65c7529E02e65C8Fd3B401";
const violetId = "0x4Bc70da1D9eF635949878E28e9940678af912540";

const {
factory,
mauveSwapRouter,
quoter,
quoterV2,
positionManager,
positionDescriptor,
nftDescriptorLibrary,
} = await deployMauve(
(signer as any) as SignerWithAddress,
(signer as any) as SignerWithAddress,
(signer as any) as SignerWithAddress,
hre,
signer as any as SignerWithAddress,
signer as any as SignerWithAddress,
signer as any as SignerWithAddress,
violetId,
eatVerifier
);

console.log(`----- ALL CONTRACTS DEPLOYED ------`);
console.log(`Factory deployed at: ${factory.address}`);
console.log(`Router deployed at: ${mauveSwapRouter.address}`);
console.log(`Mauve Swap Router deployed at: ${mauveSwapRouter.address}`);
console.log(`Quoter deployed at: ${quoter.address}`);
console.log(`Quoter V2 deployed at: ${quoterV2.address}`);
console.log(`PositionManager deployed at: ${positionManager.address}`);
console.log(`PositionDescriptor deployed at: ${positionDescriptor.address}`);
console.log(
Expand Down
6 changes: 3 additions & 3 deletions scripts/deployMauveInterfaceMulticall.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ethers } from "hardhat";
import * as hre from "hardhat";
import { MauveDeployer } from "../src/deployer/MauveDeployer";

async function main() {
const [signer] = await ethers.getSigners();
const [signer] = await hre.ethers.getSigners();

const deployer = new MauveDeployer(signer);
const deployer = new MauveDeployer(hre, signer);
const mauveInterfaceMulticall =
await deployer.deployMauveInterfaceMulticall();

Expand Down
6 changes: 3 additions & 3 deletions scripts/deployQuoterV2.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ethers } from "hardhat";
import * as hre from "hardhat";
import { MauveDeployer } from "../src/deployer/MauveDeployer";

async function main() {
const [signer] = await ethers.getSigners();
const [signer] = await hre.ethers.getSigners();
const factory = "0xC0cc4ca3f4EE58947256412d3AE35d90c1941D95";
const WETH9Address = "0x4200000000000000000000000000000000000006";

const deployer = new MauveDeployer(signer);
const deployer = new MauveDeployer(hre, signer);
const quoterV2 = await deployer.deployQuoterV2(factory, WETH9Address);

console.log(`QuoterV2 deployed at: ${quoterV2.address}`);
Expand Down
16 changes: 9 additions & 7 deletions scripts/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ async function main() {
await token0.connect(trader).mint(parseEther("1000000000000000"));
await token1.connect(trader).mint(parseEther("1000000000000000"));

const { factory, mauveSwapRouter, quoter, positionManager } = await deployMauve(
deployer,
mauveOwner,
poolAdmin,
VIOLET_ID_ADDRESS,
EATVerifier.address,
);
const { factory, mauveSwapRouter, quoter, positionManager } =
await deployMauve(
hre,
deployer,
mauveOwner,
poolAdmin,
VIOLET_ID_ADDRESS,
EATVerifier.address
);

console.log(`Factory: ${factory.address}`);
console.log(`Router: ${mauveSwapRouter.address}`);
Expand Down
71 changes: 71 additions & 0 deletions src/compilerSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export const MAUVE_CORE_COMPILER_SETTINGS = {
version: "0.7.6",
settings: {
optimizer: {
enabled: true,
runs: 850,
},
metadata: {
// do not include the metadata hash, since this is machine dependent
// and we want all generated code to be deterministic
// https://docs.soliditylang.org/en/v0.7.6/metadata.html
bytecodeHash: "none",
},
},
};

export const MAUVE_PERIPHERY_DEFAULT_COMPILER_SETTINGS = {
version: "0.7.6",
settings: {
evmVersion: "istanbul",
optimizer: {
enabled: true,
runs: 1_000_000,
},
metadata: {
bytecodeHash: "none",
},
},
};

export const MAUVE_PERIPHERY_LOW_COMPILER_SETTINGS = {
version: "0.7.6",
settings: {
evmVersion: "istanbul",
optimizer: {
enabled: true,
runs: 555,
},
metadata: {
bytecodeHash: "none",
},
},
};

export const MAUVE_PERIPHERY_LOWEST_COMPILER_SETTINGS = {
version: "0.7.6",
settings: {
evmVersion: "istanbul",
optimizer: {
enabled: true,
runs: 900,
},
metadata: {
bytecodeHash: "none",
},
},
};

export const MAUVE_SWAP_ROUTER_COMPILER_SETTINGS = {
version: "0.7.6",
settings: {
evmVersion: "istanbul",
optimizer: {
enabled: true,
runs: 49350,
},
metadata: {
bytecodeHash: "none",
},
},
};
40 changes: 32 additions & 8 deletions src/deployer/MauveDeployer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Signer, Contract, ContractFactory } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { linkLibraries } from "../util/linkLibraries";
import { positionManagerBytes32, swapRouterBytes32 } from "../util/roles";
import WETH9 from "../util/WETH9.json";
Expand All @@ -24,13 +25,13 @@ const WETH9Address = "0x4200000000000000000000000000000000000006";

export class MauveDeployer {
static async deploy(
hre: HardhatRuntimeEnvironment,
actor: Signer,
violetIdAddress: string,
eatVerifierAddress: string
): Promise<{ [name: string]: Contract }> {
const deployer = new MauveDeployer(actor);
const deployer = new MauveDeployer(hre, actor);

// const weth9 = await deployer.deployWETH9();
const factory = await deployer.deployFactory();
console.log(`Factory deployed at: ${factory.address}`);
const quoter = await deployer.deployQuoter(factory.address, WETH9Address);
Expand All @@ -51,7 +52,6 @@ export class MauveDeployer {
console.log(
`NFTPositionDescriptor deployed at: ${positionDescriptor.address}`
);

const positionManager = await deployer.deployNonfungiblePositionManager(
factory.address,
WETH9Address,
Expand All @@ -73,7 +73,6 @@ export class MauveDeployer {
await factory.setRole(positionManager.address, positionManagerBytes32);

return {
// weth9,
factory,
mauveSwapRouter,
quoter,
Expand All @@ -84,9 +83,11 @@ export class MauveDeployer {
};
}

hre: HardhatRuntimeEnvironment;
deployer: Signer;

constructor(deployer: Signer) {
constructor(hre: HardhatRuntimeEnvironment, deployer: Signer) {
this.hre = hre;
this.deployer = deployer;
}

Expand Down Expand Up @@ -194,7 +195,8 @@ export class MauveDeployer {
weth9Address,
"0x4554480000000000000000000000000000000000000000000000000000000000",
],
this.deployer
this.deployer,
{ NFTDescriptor: nftDescriptorLibraryAddress }
)) as Contract;
}

Expand Down Expand Up @@ -223,9 +225,31 @@ export class MauveDeployer {
abi: any,
bytecode: string,
deployParams: Array<any>,
actor: Signer
actor: Signer,
libraries?: Record<string, string>
) {
console.log(`------------`);
console.log(`Deploying contract...`);

const factory = new ContractFactory(abi, bytecode, actor);
return await factory.deploy(...deployParams);
const contract = await factory.deploy(...deployParams);

console.log(`πŸš€ Contract deployed! Waiting for 5 confirmations...`);
await contract.deployTransaction.wait(5);

try {
await this.hre.run("verify:verify", {
address: contract.address,
constructorArguments: deployParams,
libraries,
});
} catch (error) {
console.log(
`Error verifying contract at address ${contract.address}: ${error}`
);
}

console.log(`βœ… Done deploying contract.`);
return contract;
}
}
Loading