-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[contracts]: ChugSplash tooling to generate complete action bundl…
…es from config files (#749) * wip: Start chugsplash hardhat tooling * docs: add some comments * style: break storage slot compute line into two lines * test: Add tests for hardhat tooling * fix: use stricter env type
- Loading branch information
1 parent
8bd63e5
commit 1cad865
Showing
5 changed files
with
385 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
const storageLayout = await getStorageLayout(hre, contractConfig.source) | ||
|
||
// 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Oops, something went wrong.