Skip to content
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
2 changes: 1 addition & 1 deletion packages/contracts/src/chugsplash/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* External Imports */
/* Imports: External */
import { fromHexString, toHexString } from '@eth-optimism/core-utils'
import { ethers } from 'ethers'
import MerkleTree from 'merkletreejs'
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/chugsplash/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Handlebars from 'handlebars'
import { ethers } from 'ethers'

type SolidityVariable =
| boolean

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like a bit of an antipattern to have this sort of type that we are maintaining. Probably an area for future work, but a quick search yielded that maybe something in here could be used in place?

| string
| number
| Array<SolidityVariable>
Expand Down
56 changes: 56 additions & 0 deletions packages/contracts/src/chugsplash/hardhat-tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Imports: External */
import { HardhatRuntimeEnvironment } from 'hardhat/types'

/* Imports: Internal */
import { computeStorageSlots, getStorageLayout } from './storage'
import { ChugSplashConfig, parseChugSplashConfig } from './config'
import {
ChugSplashAction,
ChugSplashActionBundle,
getChugSplashActionBundle,
} from './actions'

/**
* Generates a ChugSplash action bundle from a config file.
* @param hre Hardhat runtime environment, used to load artifacts + storage layouts.
* @param config Config file to convert into a bundle.
* @param env Environment variables to inject into the config file.
* @returns Action bundle generated from the parsed config file.
*/
export const makeActionBundleFromConfig = async (
hre: HardhatRuntimeEnvironment,
config: ChugSplashConfig,
env: {
[key: string]: string | number | boolean
} = {}
): Promise<ChugSplashActionBundle> => {
// Parse the config to replace any template variables.
const parsed = parseChugSplashConfig(config, env)

const actions: ChugSplashAction[] = []
for (const [contractName, contractConfig] of Object.entries(
parsed.contracts
)) {
const artifact = hre.artifacts.readArtifactSync(contractConfig.source)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the hardhat artifacts do expose a deployedLinkReferences if we want to assert here that none exist. Not sure if that's even relevant for our solidity version, but thought worth sharing.

const storageLayout = await getStorageLayout(hre, contractConfig.source)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it could be possible to pull this asynchronous call out of the critical path in some way? It might make it easier to test this function if it was entirely synchronous. It might require some intermediate representation of the config.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is particularly easy without adding some ugly code. Source of the async nature of this function comes from a single call to hre.artifacts.getBuildInfo specifically here in getStorageLayout. If we want to make this sync we'd have to duplicate most of the logic of getBuildInfo and remove the async calls made within.


// Add a SET_CODE action for each contract first.
actions.push({
target: contractConfig.address,
code: artifact.deployedBytecode,
})

// Add SET_STORAGE actions for each storage slot that we want to modify.
const slots = computeStorageSlots(storageLayout, contractConfig.variables)
for (const slot of slots) {
actions.push({
target: contractConfig.address,
key: slot.key,
value: slot.val,
})
}
}

// Generate a bundle from the list of actions.
return getChugSplashActionBundle(actions)
Comment thread
smartcontracts marked this conversation as resolved.
}
1 change: 1 addition & 0 deletions packages/contracts/src/chugsplash/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './actions'
export * from './config'
export * from './storage'
export * from './hardhat-tools'
Loading