Skip to content

Commit

Permalink
Merge pull request sphinx-labs#545 from chugsplash/sg/prev-artifacts
Browse files Browse the repository at this point in the history
refactor: get previous storage layout in OpenZeppelin format
  • Loading branch information
sam-goldman authored Mar 3, 2023
2 parents 90dc6f4 + 03463a7 commit dfbccc7
Show file tree
Hide file tree
Showing 24 changed files with 624 additions and 460 deletions.
7 changes: 7 additions & 0 deletions .changeset/two-wombats-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@chugsplash/executor': patch
'@chugsplash/plugins': patch
'@chugsplash/core': patch
---

Get previous storage layout using OpenZeppelin's format
4 changes: 1 addition & 3 deletions packages/core/src/actions/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
} from '../languages/solidity/types'
import { Integration } from '../constants'
import {
addEnumMembersToStorageLayout,
createDeploymentFolderForNetwork,
getConstructorArgs,
readBuildInfo,
readContractArtifact,
writeDeploymentArtifact,
} from '../utils'

import 'core-js/features/array/at'

/**
Expand All @@ -33,8 +33,6 @@ export const readStorageLayout = (
const [sourceName, contractName] = contractFullyQualifiedName.split(':')
const contractOutput = buildInfo.output.contracts[sourceName][contractName]

addEnumMembersToStorageLayout(contractOutput.storageLayout, buildInfo.output)

return contractOutput.storageLayout
}

Expand Down
45 changes: 25 additions & 20 deletions packages/core/src/actions/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { fromHexString, toHexString } from '@eth-optimism/core-utils'
import { ethers, providers } from 'ethers'
import MerkleTree from 'merkletreejs'

import { ParsedChugSplashConfig } from '../config/types'
import {
CanonicalConfigArtifacts,
ParsedChugSplashConfig,
} from '../config/types'
import { Integration } from '../constants'
import { computeStorageSlots } from '../languages/solidity/storage'
import {
ArtifactPaths,
SolidityStorageLayout,
} from '../languages/solidity/types'
import { ArtifactPaths } from '../languages/solidity/types'
import {
getImplAddress,
readContractArtifact,
getCreationCodeWithConstructorArgs,
readBuildInfo,
} from '../utils'
import { readStorageLayout } from './artifacts'
import {
ChugSplashAction,
ChugSplashActionBundle,
Expand Down Expand Up @@ -230,16 +230,15 @@ export const bundleLocal = async (
artifactPaths: ArtifactPaths,
integration: Integration
): Promise<ChugSplashActionBundle> => {
const artifacts = {}
const artifacts: CanonicalConfigArtifacts = {}
for (const [referenceName, contractConfig] of Object.entries(
parsedConfig.contracts
)) {
const storageLayout = readStorageLayout(
artifactPaths[referenceName].buildInfoPath,
contractConfig.contract
const { input, output } = readBuildInfo(
artifactPaths[referenceName].buildInfoPath
)

const { abi, bytecode } = readContractArtifact(
const { abi, bytecode, sourceName, contractName } = readContractArtifact(
artifactPaths[referenceName].contractArtifactPath,
integration
)
Expand All @@ -250,8 +249,12 @@ export const bundleLocal = async (
abi
)
artifacts[referenceName] = {
compilerInput: input,
compilerOutput: output,
creationCodeWithConstructorArgs,
storageLayout,
abi,
sourceName,
contractName,
}
}

Expand All @@ -268,19 +271,21 @@ export const bundleLocal = async (
export const makeActionBundleFromConfig = async (
provider: providers.Provider,
parsedConfig: ParsedChugSplashConfig,
artifacts: {
[name: string]: {
creationCodeWithConstructorArgs: string
storageLayout: SolidityStorageLayout
}
}
artifacts: CanonicalConfigArtifacts
): Promise<ChugSplashActionBundle> => {
const actions: ChugSplashAction[] = []
for (const [referenceName, contractConfig] of Object.entries(
parsedConfig.contracts
)) {
const { storageLayout, creationCodeWithConstructorArgs } =
artifacts[referenceName]
const {
creationCodeWithConstructorArgs,
compilerOutput,
sourceName,
contractName,
} = artifacts[referenceName]

const storageLayout =
compilerOutput.contracts[sourceName][contractName].storageLayout

// Skip adding a `DEPLOY_IMPLEMENTATION` action if the implementation has already been deployed.
if (
Expand Down
15 changes: 14 additions & 1 deletion packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
REGISTRY_PROXY_TYPE_HASH,
} from '@chugsplash/contracts'
import { constants } from 'ethers'
import { Fragment } from 'ethers/lib/utils'
import { CompilerInput } from 'hardhat/types'

import { CompilerInput } from '../languages/solidity/types'
import { CompilerOutput } from '../languages/solidity/types'

export const externalProxyTypes = [
'oz-transparent',
Expand Down Expand Up @@ -131,3 +133,14 @@ export type ChugSplashInput = {
solcLongVersion: string
input: CompilerInput
}

export type CanonicalConfigArtifacts = {
[referenceName: string]: {
compilerInput: CompilerInput
compilerOutput: CompilerOutput
creationCodeWithConstructorArgs: string
abi: Array<Fragment>
sourceName: string
contractName: string
}
}
189 changes: 0 additions & 189 deletions packages/core/src/deployed.ts

This file was deleted.

Loading

0 comments on commit dfbccc7

Please sign in to comment.