Skip to content

Commit

Permalink
fix(core): separate testnets and mainnets in the ChugSplash config
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Jul 17, 2023
1 parent 1357dc6 commit 8aad621
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .changeset/early-paws-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chugsplash/plugins': minor
'@chugsplash/core': minor
---

Separate testnets and mainnets in the ChugSplash config
1 change: 1 addition & 0 deletions packages/core/src/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export type IPFSCommitResponse = IPFSHash[]
export type ProposalRequest = {
apiKey: string
orgId: string
isTestnet: boolean
orgOwners: string[]
orgOwnerThreshold: number
authAddress: string
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { constants, utils } from 'ethers'
import {
CURRENT_CHUGSPLASH_MANAGER_VERSION,
LAYERZERO_ADDRESSES,
SUPPORTED_LIVE_NETWORKS,
SUPPORTED_NETWORKS,
} from './constants'

const [registryConstructorFragment] = ChugSplashRegistryABI.filter(
Expand Down Expand Up @@ -196,7 +196,7 @@ export const getLZSenderAddress = (
localLZEndpoint: boolean,
lzEndpointAddress: string
) => {
const destinationChains = Object.values(SUPPORTED_LIVE_NETWORKS).map(
const destinationChains = Object.values(SUPPORTED_NETWORKS).map(
(id) =>
[
id,
Expand Down
62 changes: 47 additions & 15 deletions packages/core/src/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ import {
import {
CONTRACT_SIZE_LIMIT,
Keyword,
SUPPORTED_LIVE_NETWORKS,
SUPPORTED_MAINNETS,
SUPPORTED_TESTNETS,
keywords,
} from '../constants'
import {
Expand Down Expand Up @@ -152,6 +153,7 @@ export const getParsedOrgConfig = async (
userConfig: UserChugSplashConfig,
projects: Array<Project> | Project,
deployerAddress: string,
isTestnet: boolean,
provider: providers.JsonRpcProvider,
cre: ChugSplashRuntimeEnvironment,
getConfigArtifacts: GetConfigArtifacts,
Expand All @@ -177,7 +179,10 @@ export const getParsedOrgConfig = async (

assertValidOrgConfigOptions(userConfig.options, cre, failureAction)

const parsedConfigOptions = parseOrgConfigOptions(userConfig.options)
const parsedConfigOptions = parseOrgConfigOptions(
userConfig.options,
isTestnet
)

const { projectConfigs, configArtifacts } = await getUnvalidatedParsedConfig(
userConfig,
Expand Down Expand Up @@ -3067,7 +3072,8 @@ export const assertValidOrgConfigOptions = (
): void => {
const {
owner,
networks,
mainnets,
testnets,
orgId,
orgOwners,
orgThreshold,
Expand Down Expand Up @@ -3119,7 +3125,8 @@ export const assertValidOrgConfigOptions = (
const duplicatedOrgOwners = getDuplicateElements(orgOwners)
const duplicatedProposers = getDuplicateElements(proposers)
const duplicatedManagers = getDuplicateElements(managers)
const duplicatedNetworks = getDuplicateElements(networks)
const duplicatedNetworks = getDuplicateElements(mainnets)
const duplicatedTestnets = getDuplicateElements(testnets)
if (duplicatedOrgOwners.length > 0) {
logValidationError(
'error',
Expand Down Expand Up @@ -3156,6 +3163,15 @@ export const assertValidOrgConfigOptions = (
cre.stream
)
}
if (duplicatedTestnets.length > 0) {
logValidationError(
'error',
`The following testnets are duplicated:`,
duplicatedTestnets,
cre.silent,
cre.stream
)
}

const invalidOrgOwnerAddresses = orgOwners.filter(
(address) => !ethers.utils.isAddress(address)
Expand All @@ -3166,16 +3182,18 @@ export const assertValidOrgConfigOptions = (
const invalidManagerAddresses = managers.filter(
(address) => !ethers.utils.isAddress(address)
)
const invalidNetworks = networks.filter(
(network) => !SUPPORTED_LIVE_NETWORKS[network]
const invalidMainnets = mainnets.filter(
(network) => !SUPPORTED_MAINNETS[network]
)
const invalidTestnets = testnets.filter(
(testnet) => !SUPPORTED_TESTNETS[testnet]
)
if (invalidOrgOwnerAddresses.length > 0) {
logValidationError(
'error',
`The following org owners are not valid addresses:`,
invalidOrgOwnerAddresses,
cre.silent,

cre.stream
)
}
Expand All @@ -3197,13 +3215,24 @@ export const assertValidOrgConfigOptions = (
cre.stream
)
}
if (invalidNetworks.length > 0) {
if (invalidMainnets.length > 0) {
logValidationError(
'error',
`The following networks in your ChugSplash config are not supported: ${invalidNetworks.join(
`The following networks in your ChugSplash config are not supported: ${invalidMainnets.join(
', '
)}.\nSupported networks are:`,
Object.keys(SUPPORTED_LIVE_NETWORKS).map((n) => `- ${n}`),
Object.keys(SUPPORTED_MAINNETS).map((n) => `- ${n}`),
cre.silent,
cre.stream
)
}
if (invalidTestnets.length > 0) {
logValidationError(
'error',
`The following testnets in your ChugSplash config are not supported: ${invalidTestnets.join(
', '
)}.\nSupported testnets are:`,
Object.keys(SUPPORTED_TESTNETS).map((n) => `- ${n}`),
cre.silent,
cre.stream
)
Expand All @@ -3219,10 +3248,10 @@ export const assertValidOrgConfigOptions = (
)
}

if (networks.length === 0) {
if (mainnets.length === 0 && testnets.length === 0) {
logValidationError(
'error',
`There must be at least one network in your ChugSplash config.`,
`There must be at least one network or testnet in your ChugSplash config.`,
[],
cre.silent,
cre.stream
Expand All @@ -3233,11 +3262,14 @@ export const assertValidOrgConfigOptions = (
}

export const parseOrgConfigOptions = (
options: UserOrgConfigOptions
options: UserOrgConfigOptions,
isTestnet: boolean
): ParsedOrgConfigOptions => {
const { networks, orgId, orgThreshold } = options
const { mainnets, testnets, orgId, orgThreshold } = options

const chainIds = networks.map((network) => SUPPORTED_LIVE_NETWORKS[network])
const chainIds = isTestnet
? testnets.map((network) => SUPPORTED_TESTNETS[network])
: mainnets.map((network) => SUPPORTED_MAINNETS[network])

// Converts addresses to checksummed addresses and sorts them in ascending order.
const orgOwners = options.orgOwners
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ export type UserProjectConfigs = {
}

/**
* @notice The `networks` field is an array of network names, e.g. 'mainnet'.
* @notice The `mainnets` field is an array of network names, e.g. ['mainnet', 'optimism'].
*/
export interface UserOrgConfigOptions extends OrgConfigOptions {
networks: Array<string>
mainnets: Array<string>
testnets: Array<string>
}

/**
Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ export const CONTRACT_SIZE_LIMIT = 24576 // bytes

export const WEBSITE_URL = `https://chugsplash.io`

export type SupportedChainId = 1 | 10 | 5 | 420
export type SupportedMainnetChainId = 1 | 10
export type SupportedTestnetChainId = 5 | 420
export type SupportedChainId = SupportedMainnetChainId | SupportedTestnetChainId

// Maps a live network name to its chain ID
export const SUPPORTED_LIVE_NETWORKS: {
[networkName: string]: SupportedChainId
// Maps a live network name to its chain ID. Does not include testnets.
export const SUPPORTED_MAINNETS: {
[networkName: string]: SupportedMainnetChainId
} = {
// Mainnets
mainnet: 1,
optimism: 10,
// Testnets
}
export const SUPPORTED_TESTNETS: {
[networkName: string]: SupportedTestnetChainId
} = {
goerli: 5,
'optimism-goerli': 420,
}
export const SUPPORTED_NETWORKS = {
...SUPPORTED_MAINNETS,
...SUPPORTED_TESTNETS,
}

// Etherscan constants
export const customChains: CustomChain[] = []
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/contract-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import {
} from './addresses'
import {
LAYERZERO_ADDRESSES,
SupportedChainId,
SUPPORTED_LIVE_NETWORKS,
SupportedMainnetChainId,
SUPPORTED_NETWORKS,
} from './constants'

export const getChugSplashConstants = (
Expand All @@ -61,10 +61,10 @@ export const getChugSplashConstants = (
const lzEndpointAddress =
localLZEndpoint || 31337
? getMockEndPointAddress(chainId)
: LAYERZERO_ADDRESSES[chainId as SupportedChainId].endpointAddress
: LAYERZERO_ADDRESSES[chainId as SupportedMainnetChainId].endpointAddress

// Get the set of destination chains based off the supported networks
const destinationChains = Object.values(SUPPORTED_LIVE_NETWORKS).map(
const destinationChains = Object.values(SUPPORTED_NETWORKS).map(
(id) =>
[
id,
Expand All @@ -88,7 +88,7 @@ export const getChugSplashConstants = (
// When running locally, we simulate multichain messaging by sending messages to multiple destination contracts
// So if we're deploying locally, then we need to deploy a receiver for each chainId we want to send too
const receivers = localLZEndpoint
? Object.values(SUPPORTED_LIVE_NETWORKS).map((id) => {
? Object.values(SUPPORTED_NETWORKS).map((id) => {
const mockAddress = getMockEndPointAddress(id)
return {
artifact: LZReceiverArtifact,
Expand All @@ -107,7 +107,7 @@ export const getChugSplashConstants = (
// B/c we simulate multichain messaging by sending messages to multiple destination contracts, we need to deploy
// a mock endpoint contract for each chain id when running locally
const mockEndpoints = localLZEndpoint
? Object.values(SUPPORTED_LIVE_NETWORKS).map((id) => {
? Object.values(SUPPORTED_NETWORKS).map((id) => {
return {
artifact: LZEndpointMockArtifact,
expectedAddress: getMockEndPointAddress(id),
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/languages/solidity/predeploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { ChugSplashSystemConfig } from './types'
import {
PROTOCOL_PAYMENT_RECIPIENT_ROLE,
REMOTE_EXECUTOR_ROLE,
SUPPORTED_LIVE_NETWORKS,
SUPPORTED_NETWORKS,
} from '../../constants'
import { resolveNetworkName } from '../../messages'
import { assertValidBlockGasLimit } from '../../config/parse'
Expand Down Expand Up @@ -487,7 +487,7 @@ export const initializeChugSplash = async (
signer
)

for (const id of Object.values(SUPPORTED_LIVE_NETWORKS)) {
for (const id of Object.values(SUPPORTED_NETWORKS)) {
const endpointAddress = getMockEndPointAddress(id)
await (
await srcEndpoint.setDestLzEndpoint(
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dotenv.config()

export const proposeAbstractTask = async (
configPath: string,
isTestnet: boolean,
projectName: string,
dryRun: boolean,
cre: ChugSplashRuntimeEnvironment,
Expand Down Expand Up @@ -112,6 +113,7 @@ export const proposeAbstractTask = async (
const { isNewConfig, chainIds, prevOrgConfig } = await getOrgConfigInfo(
userConfig,
projectName,
isTestnet,
apiKey,
cre,
failureAction
Expand Down Expand Up @@ -141,6 +143,7 @@ export const proposeAbstractTask = async (
userConfig,
projectName,
prevOrgConfig.deployer,
isTestnet,
provider,
cre,
getConfigArtifacts,
Expand Down Expand Up @@ -344,6 +347,7 @@ export const proposeAbstractTask = async (
const proposalRequest: ProposalRequest = {
apiKey,
orgId,
isTestnet,
chainIds,
deploymentName: projectName,
orgOwners: canonicalOrgConfig.options.orgOwners,
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ export const getDuplicateElements = (arr: Array<string>): Array<string> => {
export const getOrgConfigInfo = async (
userConfig: UserChugSplashConfig,
projectName: string,
isTestnet: boolean,
apiKey: string,
cre: ChugSplashRuntimeEnvironment,
failureAction: FailureAction
Expand All @@ -1232,10 +1233,14 @@ export const getOrgConfigInfo = async (
}

assertValidOrgConfigOptions(userConfig.options, cre, failureAction)
const parsedConfigOptions = parseOrgConfigOptions(userConfig.options)
const parsedConfigOptions = parseOrgConfigOptions(
userConfig.options,
isTestnet
)

const prevOrgConfig = await fetchCanonicalOrgConfig(
parsedConfigOptions.orgId,
isTestnet,
apiKey
)

Expand Down Expand Up @@ -1275,12 +1280,14 @@ export const getOrgConfigInfo = async (

export const fetchCanonicalOrgConfig = async (
orgId: string,
isTestnet: boolean,
apiKey: string
): Promise<CanonicalOrgConfig | undefined> => {
const response = await axios.post(
`${fetchChugSplashManagedBaseUrl()}/api/fetchCanonicalOrgConfig`,
{
apiKey,
isTestnet,
orgId,
}
)
Expand Down
2 changes: 1 addition & 1 deletion packages/executor/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const config: HardhatUserConfig = {
hardhat: {
// This must be the chain ID of a live network that ChugSplash supports. This allows us to
// test the remote executor against an org config, which can only contain supported live
// networks.For a list of supported networks, see the `SUPPORTED_LIVE_NETWORKS` object in the
// networks. For a list of supported networks, see the `SUPPORTED_NETWORKS` object in the
// `@chugsplash/core` package.
chainId: 5,
},
Expand Down
Loading

0 comments on commit 8aad621

Please sign in to comment.