-
Notifications
You must be signed in to change notification settings - Fork 4k
feat[contracts]: ChugSplash tooling to generate complete action bundles from config files #749
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
Changes from all commits
36e4e44
12ad10b
9d066c5
5a56e0c
3126fa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the hardhat artifacts do expose a |
||
| const storageLayout = await getStorageLayout(hre, contractConfig.source) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| // 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) | ||
|
smartcontracts marked this conversation as resolved.
|
||
| } | ||
| 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' |
There was a problem hiding this comment.
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?