Skip to content

Commit

Permalink
fix(pg,core): separate local canonical config files by network
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Apr 10, 2023
1 parent 5783fdd commit 2a0939a
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 54 deletions.
6 changes: 6 additions & 0 deletions .changeset/honest-pans-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chugsplash/plugins': patch
'@chugsplash/core': patch
---

Separate local canonical config files by network
2 changes: 1 addition & 1 deletion packages/core/src/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ permission to call the 'upgradeTo' function on each of them.

const isProxyDeployed =
(await provider.getCode(contractConfig.proxy)) !== '0x'
if (isProxyDeployed && canonicalConfigPath) {
if (isProxyDeployed) {
// If the deployment an upgrade, then the contract must be proxied and therfore upgradableContract
// will always be defined so we can safely assert it.
const newStorageLayout = upgradableContract!.layout
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,12 @@ IPFS_API_KEY_SECRET: ...

// Write the canonical config to the local file system if we aren't committing it to IPFS.
if (!commitToIpfs) {
writeCanonicalConfig(canonicalConfigPath, configUri, canonicalConfig)
await writeCanonicalConfig(
provider,
canonicalConfigPath,
configUri,
canonicalConfig
)
}

if (spinner) {
Expand Down Expand Up @@ -762,7 +767,8 @@ export const chugsplashDeployAbstractTask = async (
if (isSupportedNetworkOnEtherscan(await getChainId(provider))) {
const etherscanApiKey = process.env.ETHERSCAN_API_KEY
if (etherscanApiKey) {
const canonicalConfig = readCanonicalConfig(
const canonicalConfig = await readCanonicalConfig(
provider,
canonicalConfigPath,
configUri
)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ParsedContractConfig } from './config'

export type ChugSplashRuntimeEnvironment = {
configPath: string
canonicalConfigPath: string | undefined
canonicalConfigPath: string
remoteExecution: boolean
autoConfirm: boolean
stream: NodeJS.WritableStream
Expand Down
35 changes: 23 additions & 12 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,40 +428,50 @@ export const formatEther = (
return parseFloat(ethers.utils.formatEther(amount)).toFixed(decimals)
}

export const readCanonicalConfig = (
export const readCanonicalConfig = async (
provider: providers.Provider,
canonicalConfigFolderPath: string,
configUri: string
): CanonicalChugSplashConfig => {
): Promise<CanonicalChugSplashConfig> => {
const ipfsHash = configUri.replace('ipfs://', '')

const network = await provider.getNetwork()

// Check that the file containing the canonical config exists.
const canonicalConfigFilePath = path.join(
const configFilePath = path.join(
canonicalConfigFolderPath,
network.name,
`${ipfsHash}.json`
)
if (!fs.existsSync(canonicalConfigFilePath)) {
throw new Error(`Could not find cached canonical config file at:
${canonicalConfigFilePath}`)
if (!fs.existsSync(configFilePath)) {
throw new Error(`Could not find local canonical config file at:
${configFilePath}`)
}

return JSON.parse(fs.readFileSync(canonicalConfigFilePath, 'utf8'))
return JSON.parse(fs.readFileSync(configFilePath, 'utf8'))
}

export const writeCanonicalConfig = (
export const writeCanonicalConfig = async (
provider: providers.Provider,
canonicalConfigFolderPath: string,
configUri: string,
canonicalConfig: CanonicalChugSplashConfig
) => {
const ipfsHash = configUri.replace('ipfs://', '')

// Create the canonical config folder if it doesn't already exist.
if (!fs.existsSync(canonicalConfigFolderPath)) {
fs.mkdirSync(canonicalConfigFolderPath)
const network = await provider.getNetwork()

const networkFolderPath = path.join(canonicalConfigFolderPath, network.name)

// Create the canonical config network folder if it doesn't already exist.
if (!fs.existsSync(networkFolderPath)) {
fs.mkdirSync(networkFolderPath, { recursive: true })
}

// Write the canonical config to the local file system. It will exist in a JSON file that has the
// config URI as its name.
fs.writeFileSync(
path.join(canonicalConfigFolderPath, `${ipfsHash}.json`),
path.join(networkFolderPath, `${ipfsHash}.json`),
JSON.stringify(canonicalConfig, null, 2)
)
}
Expand Down Expand Up @@ -1145,6 +1155,7 @@ export const getPreviousCanonicalConfig = async (
)
} else {
return readCanonicalConfig(
provider,
canonicalConfigFolderPath,
latestProposalEvent.args.configUri
)
Expand Down
77 changes: 45 additions & 32 deletions packages/plugins/src/foundry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ const command = args[0]
let owner = args[8]
const allowManagedProposals = args[9] === 'true'

const { artifactFolder, buildInfoFolder, canonicalConfigPath } =
fetchPaths(outPath, buildInfoPath)

const cre = await createChugSplashRuntime(
configPath,
args[3] !== 'localhost',
true,
canonicalConfigPath,
undefined,
silent,
process.stdout
Expand All @@ -55,10 +59,6 @@ const command = args[0]
const provider = new ethers.providers.JsonRpcProvider(rpcUrl, network)
const wallet = new ethers.Wallet(privateKey, provider)

const { artifactFolder, buildInfoFolder } = fetchPaths(
outPath,
buildInfoPath
)
const userConfig = await readUnvalidatedChugSplashConfig(configPath)
const artifactPaths = await getArtifactPaths(
userConfig.contracts,
Expand Down Expand Up @@ -103,17 +103,19 @@ const command = args[0]
const ipfsUrl = args[8] !== 'none' ? args[8] : ''
const remoteExecution = args[9] === 'true'

const { artifactFolder, buildInfoFolder, canonicalConfigPath } =
fetchPaths(outPath, buildInfoPath)

const cre = await createChugSplashRuntime(
configPath,
args[3] !== 'localhost',
true,
canonicalConfigPath,
undefined,
silent,
process.stdout
)

const { artifactFolder, buildInfoFolder, canonicalConfigPath } =
fetchPaths(outPath, buildInfoPath)
const userConfig = await readUnvalidatedChugSplashConfig(configPath)
const artifactPaths = await getArtifactPaths(
userConfig.contracts,
Expand Down Expand Up @@ -162,19 +164,19 @@ const command = args[0]
const amount = BigNumber.from(args[8])
const autoEstimate = args[9] === 'true'

const { artifactFolder, buildInfoFolder, canonicalConfigPath } =
fetchPaths(outPath, buildInfoPath)

const cre = await createChugSplashRuntime(
configPath,
args[3] !== 'localhost',
true,
canonicalConfigPath,
undefined,
silent,
process.stdout
)

const { artifactFolder, buildInfoFolder } = fetchPaths(
outPath,
buildInfoPath
)
const userConfig = await readUnvalidatedChugSplashConfig(configPath)
const artifactPaths = await getArtifactPaths(
userConfig.contracts,
Expand Down Expand Up @@ -221,21 +223,23 @@ const command = args[0]
const withdrawFunds = args[8] === 'true'
const skipMonitorStatus = args[9] === 'true'

const {
artifactFolder,
buildInfoFolder,
deploymentFolder,
canonicalConfigPath,
} = fetchPaths(outPath, buildInfoPath)

const cre = await createChugSplashRuntime(
configPath,
args[3] !== 'localhost',
true,
canonicalConfigPath,
undefined,
silent,
process.stdout
)

const {
artifactFolder,
buildInfoFolder,
deploymentFolder,
canonicalConfigPath,
} = fetchPaths(outPath, buildInfoPath)
const userConfig = await readUnvalidatedChugSplashConfig(configPath)
const artifactPaths = await getArtifactPaths(
userConfig.contracts,
Expand Down Expand Up @@ -296,21 +300,23 @@ const command = args[0]
`${logPath}/deploy-${now.getTime()}`
)

const {
artifactFolder,
buildInfoFolder,
deploymentFolder,
canonicalConfigPath,
} = fetchPaths(outPath, buildInfoPath)

const cre = await createChugSplashRuntime(
configPath,
args[3] !== 'localhost',
confirm,
canonicalConfigPath,
undefined,
silent,
logWriter
)

const {
artifactFolder,
buildInfoFolder,
deploymentFolder,
canonicalConfigPath,
} = fetchPaths(outPath, buildInfoPath)
const userConfig = await readUnvalidatedChugSplashConfig(configPath)
const artifactPaths = await getArtifactPaths(
userConfig.contracts,
Expand Down Expand Up @@ -370,21 +376,23 @@ const command = args[0]
const withdrawFunds = args[8] === 'true'
let newOwner = args[9]

const {
artifactFolder,
buildInfoFolder,
deploymentFolder,
canonicalConfigPath,
} = fetchPaths(outPath, buildInfoPath)

const cre = await createChugSplashRuntime(
configPath,
args[3] !== 'localhost',
true,
canonicalConfigPath,
undefined,
silent,
process.stdout
)

const {
artifactFolder,
buildInfoFolder,
deploymentFolder,
canonicalConfigPath,
} = fetchPaths(outPath, buildInfoPath)
const userConfig = await readUnvalidatedChugSplashConfig(configPath)
const artifactPaths = await getArtifactPaths(
userConfig.contracts,
Expand Down Expand Up @@ -442,6 +450,7 @@ const command = args[0]
configPath,
args[3] !== 'localhost',
true,
'',
undefined,
false,
process.stdout
Expand Down Expand Up @@ -473,6 +482,7 @@ const command = args[0]
configPath,
args[3] !== 'localhost',
true,
'',
undefined,
silent,
process.stdout
Expand Down Expand Up @@ -504,6 +514,7 @@ const command = args[0]
'',
args[3] !== 'localhost',
true,
'',
undefined,
false,
process.stdout
Expand Down Expand Up @@ -549,6 +560,7 @@ const command = args[0]
configPath,
args[3] !== 'localhost',
true,
'',
undefined,
false,
process.stdout
Expand All @@ -575,19 +587,19 @@ const command = args[0]
const buildInfoPath = cleanPath(args[7])
const referenceName = args[8]

const { artifactFolder, buildInfoFolder, canonicalConfigPath } =
fetchPaths(outPath, buildInfoPath)

const cre = await createChugSplashRuntime(
configPath,
args[3] !== 'localhost',
true,
canonicalConfigPath,
undefined,
silent,
process.stdout
)

const { artifactFolder, buildInfoFolder } = fetchPaths(
outPath,
buildInfoPath
)
const userConfig = await readUnvalidatedChugSplashConfig(configPath)
const artifactPaths = await getArtifactPaths(
userConfig.contracts,
Expand Down Expand Up @@ -639,6 +651,7 @@ const command = args[0]
configPath,
args[3] !== 'localhost',
true,
'',
undefined,
silent,
process.stdout
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const deployAllChugSplashConfigs = async (
configPath,
false,
true,
canonicalConfigPath,
hre,
silent
)
Expand Down
Loading

0 comments on commit 2a0939a

Please sign in to comment.