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

Add arbitrum and optimism support #77

Merged
merged 3 commits into from
Nov 9, 2022
Merged
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
14 changes: 9 additions & 5 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (PK) {
}

if (
["rinkeby", "mainnet", "goerli", "ropsten"].includes(network) &&
["mainnet", "goerli", "ropsten"].includes(network) &&
INFURA_KEY === undefined
) {
throw new Error(
Expand All @@ -57,10 +57,6 @@ export default {
...sharedNetworkConfig,
url: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
},
rinkeby: {
...sharedNetworkConfig,
url: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
},
ropsten: {
...sharedNetworkConfig,
url: `https://ropsten.infura.io/v3/${INFURA_KEY}`,
Expand All @@ -85,6 +81,14 @@ export default {
...sharedNetworkConfig,
url: "https://arb1.arbitrum.io/rpc",
},
optimism: {
...sharedNetworkConfig,
url: "https://mainnet.optimism.io",
},
avalanche: {
...sharedNetworkConfig,
url: "https://rpc.ankr.com/avalanche",
},
},
namedAccounts: {
deployer: 0,
Expand Down
72 changes: 35 additions & 37 deletions src/factory/constants.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,68 @@
import { KnownContracts } from "./types";

/*
* 1 - Mainnet
* 4 - Rinkeby
* 5 - Goerli
* 56 - Binance smart chain
* 100 - Gnosis chain (Previously xdai)
* 137 - Polygon
* 31337 - hardhat network
* 80001 - Mumbai
*/
export const SUPPORTED_NETWORKS = [1, 4, 56, 100, 137, 31337, 80001];
export enum SUPPORTED_NETWORKS {
Mainnet = 1,
Goerli = 5,
BinanceSmartChain = 56,
GnosisChain = 100,
Polygon = 137,
Mumbai = 80001, // not supported yet
ArbitrumOne = 42161,
Optimism = 10,
Avalanche = 43114,
HardhatNetwork = 31337,
}

const MasterCopyAddresses: Record<KnownContracts, string> = {
[KnownContracts.META_GUARD]: "0xe2847462a574bfd43014d1c7BB6De5769C294691",
[KnownContracts.REALITY_ETH]: "0x72d453a685c27580acDFcF495830EB16B7E165f8",
[KnownContracts.REALITY_ERC20]: "0x6f628F0c3A3Ff75c39CF310901f10d79692Ed889",
[KnownContracts.BRIDGE]: "0x457042756F2B1056487173003D27f37644C119f3",
[KnownContracts.DELAY]: "0xeD2323128055cE9539c6C99e5d7EBF4CA44A2485",
[KnownContracts.FACTORY]: "0x00000000000DC7F163742Eb4aBEf650037b1f588",
[KnownContracts.EXIT_ERC20]: "0x33bCa41bda8A3983afbAd8fc8936Ce2Fb29121da",
[KnownContracts.EXIT_ERC721]: "0xD3579C14a4181EfC3DF35C3103D20823A8C8d718",
[KnownContracts.SCOPE_GUARD]: "0xfDc921764b88A889F9BFa5Ba874f77607a63b832",
[KnownContracts.META_GUARD]: "0xe2847462a574bfd43014d1c7BB6De5769C294691", // missing: optimism, arbitrum, bsc
[KnownContracts.REALITY_ETH]: "0x72d453a685c27580acDFcF495830EB16B7E165f8", // missing: optimism, arbitrum, mumbai
[KnownContracts.REALITY_ERC20]: "0x6f628F0c3A3Ff75c39CF310901f10d79692Ed889", // missing: optimism, arbitrum, mumbai
[KnownContracts.BRIDGE]: "0x457042756F2B1056487173003D27f37644C119f3", // missing: i
[KnownContracts.DELAY]: "0xeD2323128055cE9539c6C99e5d7EBF4CA44A2485", // missing: optimism, goerli, bsc
[KnownContracts.FACTORY]: "0x00000000000DC7F163742Eb4aBEf650037b1f588", // missing: optimism
[KnownContracts.EXIT_ERC20]: "0x33bCa41bda8A3983afbAd8fc8936Ce2Fb29121da", // missing: mumbai, optimism, arbitrum,
[KnownContracts.EXIT_ERC721]: "0xD3579C14a4181EfC3DF35C3103D20823A8C8d718", // missing: mumbai, arbitrum, optimism
[KnownContracts.SCOPE_GUARD]: "0xfDc921764b88A889F9BFa5Ba874f77607a63b832", // missing: goerli, bsc, mumbai, arbitrum, optimism
[KnownContracts.CIRCULATING_SUPPLY_ERC20]:
"0xb50fab2e2892E3323A5300870C042B428B564FE3",
"0xb50fab2e2892E3323A5300870C042B428B564FE3", // missing: mumbai, arbitrum, optimism
[KnownContracts.CIRCULATING_SUPPLY_ERC721]:
"0x71530ec830CBE363bab28F4EC52964a550C0AB1E",
[KnownContracts.ROLES]: "0x85388a8cd772b19a468F982Dc264C238856939C9",
"0x71530ec830CBE363bab28F4EC52964a550C0AB1E", // missing: mumbai, arbitrum, optimism
[KnownContracts.ROLES]: "0x85388a8cd772b19a468F982Dc264C238856939C9", // missing: mumbai, arbitrum, optimism
tellor: "",
optimisticGovernor: "",
};

export const CONTRACT_ADDRESSES: Record<
number,
SUPPORTED_NETWORKS,
Record<KnownContracts, string>
> = {
1: {
[SUPPORTED_NETWORKS.Mainnet]: {
...MasterCopyAddresses,
[KnownContracts.TELLOR]: "0x7D5f5EaF541AC203Ee1424895b6997041C886FBE",
[KnownContracts.OPTIMISTIC_GOVERNOR]:
"0x56C11dE61e249cbBf337027B53Ed3b1dFA8a4e6F",
},
4: {
...MasterCopyAddresses,
[KnownContracts.TELLOR]: "0x2b0bfeBCDFE2228cAbA56dfDE9F067643B357343",
[KnownContracts.OPTIMISTIC_GOVERNOR]:
"0x82C60B22Ee1A814a14122c7Bd78652Fbc3fD8CB2",
},
5: {
[SUPPORTED_NETWORKS.Goerli]: {
...MasterCopyAddresses,
[KnownContracts.OPTIMISTIC_GOVERNOR]:
"0x1340229DCF6e0bed7D9c2356929987C2A720F836",
},
56: { ...MasterCopyAddresses },
100: { ...MasterCopyAddresses },
137: {
[SUPPORTED_NETWORKS.BinanceSmartChain]: { ...MasterCopyAddresses },
[SUPPORTED_NETWORKS.GnosisChain]: { ...MasterCopyAddresses },
[SUPPORTED_NETWORKS.Polygon]: {
...MasterCopyAddresses,
[KnownContracts.TELLOR]: "0xEAB27A2Dc46431B96126f20bFC3197eD8247ed79",
[KnownContracts.OPTIMISTIC_GOVERNOR]:
"0x923b1AfF7D67507A5Bdf528bD3086456FEba10cB",
},
31337: { ...MasterCopyAddresses },
80001: {
[SUPPORTED_NETWORKS.HardhatNetwork]: { ...MasterCopyAddresses },
[SUPPORTED_NETWORKS.Mumbai]: {
...MasterCopyAddresses,
[KnownContracts.TELLOR]: "0xBCc265bDbc5a26D9279250b6e9CbD5527EEf4FAD",
},
[SUPPORTED_NETWORKS.ArbitrumOne]: { ...MasterCopyAddresses }, //TODO: figure out what to change
[SUPPORTED_NETWORKS.Optimism]: { ...MasterCopyAddresses }, //TODO: figure out what to change
[SUPPORTED_NETWORKS.Avalanche]: { ...MasterCopyAddresses }, //TODO: figure out what to change
};

export const CONTRACT_ABIS: Record<KnownContracts, string[]> = {
Expand Down
37 changes: 29 additions & 8 deletions src/factory/factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ethers, Contract, Signer, BigNumber } from "ethers";
import { ABI } from "hardhat-deploy/dist/types";

import { CONTRACT_ADDRESSES, CONTRACT_ABIS } from "./constants";
import {
CONTRACT_ADDRESSES,
CONTRACT_ABIS,
SUPPORTED_NETWORKS,
} from "./constants";
import { KnownContracts } from "./types";

export const deployAndSetUpModule = (
Expand All @@ -13,7 +17,14 @@ export const deployAndSetUpModule = (
provider: ethers.providers.JsonRpcProvider,
chainId: number,
saltNonce: string
) => {
): {
transaction: {
data: string;
to: string;
value: ethers.BigNumber;
};
expectedModuleAddress: string;
} => {
const { factory, module } = getFactoryAndMasterCopy(
contractName,
provider,
Expand All @@ -32,8 +43,15 @@ export const deployAndSetUpCustomModule = (
provider: ethers.providers.JsonRpcProvider,
chainId: number,
saltNonce: string
) => {
const chainContracts = CONTRACT_ADDRESSES[chainId];
): {
transaction: {
data: string;
to: string;
value: ethers.BigNumber;
};
expectedModuleAddress: string;
} => {
const chainContracts = CONTRACT_ADDRESSES[chainId as SUPPORTED_NETWORKS];
const factoryAddress = chainContracts.factory;
const factory = new Contract(factoryAddress, CONTRACT_ABIS.factory, provider);
const module = new Contract(masterCopyAddress, abi, provider);
Expand Down Expand Up @@ -86,7 +104,7 @@ export const calculateProxyAddress = (
masterCopy: string,
initData: string,
saltNonce: string
) => {
): string => {
const masterCopyAddress = masterCopy.toLowerCase().replace(/^0x/, "");
const byteCode =
"0x602d8060093d393df3363d3d373d3d3d363d73" +
Expand All @@ -109,7 +127,7 @@ export const getModuleInstance = (
moduleName: KnownContracts,
address: string,
provider: ethers.providers.JsonRpcProvider | Signer
) => {
): ethers.Contract => {
const moduleIsNotSupported = !Object.keys(CONTRACT_ABIS).includes(moduleName);
if (moduleIsNotSupported) {
throw new Error("Module " + moduleName + " not supported");
Expand All @@ -121,8 +139,11 @@ export const getFactoryAndMasterCopy = (
moduleName: KnownContracts,
provider: ethers.providers.JsonRpcProvider,
chainId: number
) => {
const chainContracts = CONTRACT_ADDRESSES[chainId];
): {
factory: ethers.Contract;
module: ethers.Contract;
} => {
const chainContracts = CONTRACT_ADDRESSES[chainId as SUPPORTED_NETWORKS];
const masterCopyAddress = chainContracts[moduleName];
const factoryAddress = chainContracts.factory;
const module = getModuleInstance(moduleName, masterCopyAddress, provider);
Expand Down