From b93b5a9115385944e628bf85ea98fa74ed654a00 Mon Sep 17 00:00:00 2001 From: Sam Goldman Date: Tue, 18 Jul 2023 23:41:31 -0400 Subject: [PATCH] fix(core): log warning to the user if a contract deployment is being skipped --- .changeset/wild-dingos-cry.md | 5 +++ packages/core/src/config/parse.ts | 37 +++++++------------ packages/plugins/contracts/foundry/Sphinx.sol | 3 ++ .../plugins/contracts/foundry/SphinxUtils.sol | 4 +- .../foundry/interfaces/ISphinxUtils.sol | 1 + .../plugins/src/foundry/get-bundle-info.ts | 5 +++ 6 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 .changeset/wild-dingos-cry.md diff --git a/.changeset/wild-dingos-cry.md b/.changeset/wild-dingos-cry.md new file mode 100644 index 000000000..b39010527 --- /dev/null +++ b/.changeset/wild-dingos-cry.md @@ -0,0 +1,5 @@ +--- +'@sphinx/core': patch +--- + +Log warning to the user if a contract deployment is being skipped diff --git a/packages/core/src/config/parse.ts b/packages/core/src/config/parse.ts index 25387ac00..7e91cffd3 100644 --- a/packages/core/src/config/parse.ts +++ b/packages/core/src/config/parse.ts @@ -205,6 +205,7 @@ export const getParsedOrgConfig = async ( ) await postParsingValidation( + provider, projectConfigs, configArtifacts, cre, @@ -359,6 +360,7 @@ export const readParsedOwnerConfig = async ( ) await postParsingValidation( + provider, projectConfigs, configArtifacts, cre, @@ -2514,6 +2516,7 @@ export const assertNoUpgradableContracts = ( } export const projectPostParsingValidation = async ( + provider: providers.JsonRpcProvider, parsedProjectConfig: ParsedProjectConfig, projectConfigArtifacts: ProjectConfigArtifacts, projectName: string, @@ -2534,7 +2537,8 @@ export const projectPostParsingValidation = async ( assertValidBlockGasLimit(blockGasLimit) - assertAvailableCreate3Addresses( + await assertAvailableCreate3Addresses( + provider, parsedProjectConfig, projectConfigArtifacts, cre, @@ -2583,6 +2587,7 @@ export const projectPostParsingValidation = async ( } export const postParsingValidation = async ( + provider: providers.JsonRpcProvider, projectConfigs: ParsedProjectConfigs, configArtifacts: ConfigArtifacts, cre: SphinxRuntimeEnvironment, @@ -2593,6 +2598,7 @@ export const postParsingValidation = async ( projectConfigs )) { await projectPostParsingValidation( + provider, parsedProjectConfig, configArtifacts[projectName], projectName, @@ -2715,15 +2721,13 @@ export const assertImmutableDeploymentsDoNotRevert = ( } } -const assertAvailableCreate3Addresses = ( +const assertAvailableCreate3Addresses = async ( + provider: providers.JsonRpcProvider, parsedConfig: ParsedProjectConfig, configArtifacts: ProjectConfigArtifacts, cre: SphinxRuntimeEnvironment, contractConfigCache: ContractConfigCache -): void => { - // List of reference names that correspond to the unavailable Create3 addresses - const unavailable: string[] = [] - +): Promise => { for (const [referenceName, contractConfig] of Object.entries( parsedConfig.contracts )) { @@ -2745,32 +2749,19 @@ const assertAvailableCreate3Addresses = ( BigNumber.from(currHash) ) : false - if (match) { + if (!match) { + const { chainId } = await provider.getNetwork() logValidationError( 'warning', - `Skipping deployment of ${referenceName} since it has already been deployed and has not changed. Add a new 'salt' value to re-deploy it at a new address.`, + `Skipping deployment of ${referenceName} on ${chainId} because a contract with this reference name has\n` + + `already been deployed. Add a new 'salt' value to re-deploy it at a new address.`, [], cre.silent, cre.stream ) - } else { - unavailable.push(referenceName) } } } - - if (unavailable.length > 0) { - logValidationError( - 'error', - `A contract has already been deployed at the Create3 address for the following contracts.\n` + - `Please add a new 'salt' field for each of these contracts in the config.`, - unavailable.map((referenceName) => { - return ` - ${referenceName}` - }), - cre.silent, - cre.stream - ) - } } export const getProjectConfigCache = async ( diff --git a/packages/plugins/contracts/foundry/Sphinx.sol b/packages/plugins/contracts/foundry/Sphinx.sol index 92e647a57..eb0cd0b83 100644 --- a/packages/plugins/contracts/foundry/Sphinx.sol +++ b/packages/plugins/contracts/foundry/Sphinx.sol @@ -136,6 +136,7 @@ contract Sphinx is Script { ConfigCache memory configCache = abi.decode(retdata, (ConfigCache)); BundleInfo memory bundleInfo = getBundleInfo( + _rpcUrl, configCache, _projectName, configs.userConfigStr, @@ -256,6 +257,7 @@ contract Sphinx is Script { } function getBundleInfo( + string memory _rpcUrl, ConfigCache memory _configCache, string memory _projectName, string memory _userConfigStr, @@ -264,6 +266,7 @@ contract Sphinx is Script { (bool success, bytes memory retdata) = address(utils).delegatecall( abi.encodeWithSelector( ISphinxUtils.ffiGetEncodedBundleInfo.selector, + _rpcUrl, _configCache, _projectName, _userConfigStr, diff --git a/packages/plugins/contracts/foundry/SphinxUtils.sol b/packages/plugins/contracts/foundry/SphinxUtils.sol index 81352f652..68493c9ba 100644 --- a/packages/plugins/contracts/foundry/SphinxUtils.sol +++ b/packages/plugins/contracts/foundry/SphinxUtils.sol @@ -192,6 +192,7 @@ contract SphinxUtils is causes an error to be thrown by Forge. */ function ffiGetEncodedBundleInfo( + string memory _rpcUrl, ConfigCache memory _configCache, string memory _projectName, string memory _userConfigStr, @@ -199,7 +200,7 @@ contract SphinxUtils is address _owner ) external returns (bytes memory) { (VmSafe.CallerMode callerMode, , ) = vm.readCallers(); - string[] memory cmds = new string[](8); + string[] memory cmds = new string[](9); cmds[0] = "npx"; cmds[1] = "node"; cmds[2] = string.concat(_rootFfiPath, "get-bundle-info.js"); @@ -208,6 +209,7 @@ contract SphinxUtils is cmds[5] = vm.toString(callerMode == VmSafe.CallerMode.RecurrentBroadcast); cmds[6] = _projectName; cmds[7] = vm.toString(_owner); + cmds[8] = _rpcUrl; bytes memory result = vm.ffi(cmds); return result; diff --git a/packages/plugins/contracts/foundry/interfaces/ISphinxUtils.sol b/packages/plugins/contracts/foundry/interfaces/ISphinxUtils.sol index 1a27d27f0..08c62889d 100644 --- a/packages/plugins/contracts/foundry/interfaces/ISphinxUtils.sol +++ b/packages/plugins/contracts/foundry/interfaces/ISphinxUtils.sol @@ -58,6 +58,7 @@ interface ISphinxUtils { ) external returns (OptionalString memory); function ffiGetEncodedBundleInfo( + string memory _rpcUrl, ConfigCache memory _configCache, string memory _projectName, string memory _userConfigStr, diff --git a/packages/plugins/src/foundry/get-bundle-info.ts b/packages/plugins/src/foundry/get-bundle-info.ts index 3665eb9bb..ca1aa1124 100644 --- a/packages/plugins/src/foundry/get-bundle-info.ts +++ b/packages/plugins/src/foundry/get-bundle-info.ts @@ -15,6 +15,7 @@ import { getDeployContractCosts, writeCanonicalConfig, } from '@sphinx/core/dist' +import { providers } from 'ethers/lib/ethers' import { createSphinxRuntime } from '../cre' import { getFoundryConfigOptions } from './options' @@ -33,6 +34,9 @@ const userConfig: UserSphinxConfig = JSON.parse(userConfigStr) const broadcasting = args[2] === 'true' const projectName = args[3] const ownerAddress = args[4] +const rpcUrl = args[5] + +const provider = new providers.JsonRpcProvider(rpcUrl) ;(async () => { process.stderr.write = validationStderrWrite @@ -95,6 +99,7 @@ const ownerAddress = args[4] ) await projectPostParsingValidation( + provider, parsedProjectConfig, projectConfigArtifacts, projectName,