Skip to content

Commit

Permalink
fix(core): log warning to the user if a contract deployment is being …
Browse files Browse the repository at this point in the history
…skipped
  • Loading branch information
sam-goldman committed Jul 19, 2023
1 parent 4a97c8f commit b93b5a9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-dingos-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sphinx/core': patch
---

Log warning to the user if a contract deployment is being skipped
37 changes: 14 additions & 23 deletions packages/core/src/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export const getParsedOrgConfig = async (
)

await postParsingValidation(
provider,
projectConfigs,
configArtifacts,
cre,
Expand Down Expand Up @@ -359,6 +360,7 @@ export const readParsedOwnerConfig = async (
)

await postParsingValidation(
provider,
projectConfigs,
configArtifacts,
cre,
Expand Down Expand Up @@ -2514,6 +2516,7 @@ export const assertNoUpgradableContracts = (
}

export const projectPostParsingValidation = async (
provider: providers.JsonRpcProvider,
parsedProjectConfig: ParsedProjectConfig,
projectConfigArtifacts: ProjectConfigArtifacts,
projectName: string,
Expand All @@ -2534,7 +2537,8 @@ export const projectPostParsingValidation = async (

assertValidBlockGasLimit(blockGasLimit)

assertAvailableCreate3Addresses(
await assertAvailableCreate3Addresses(
provider,
parsedProjectConfig,
projectConfigArtifacts,
cre,
Expand Down Expand Up @@ -2583,6 +2587,7 @@ export const projectPostParsingValidation = async (
}

export const postParsingValidation = async (
provider: providers.JsonRpcProvider,
projectConfigs: ParsedProjectConfigs,
configArtifacts: ConfigArtifacts,
cre: SphinxRuntimeEnvironment,
Expand All @@ -2593,6 +2598,7 @@ export const postParsingValidation = async (
projectConfigs
)) {
await projectPostParsingValidation(
provider,
parsedProjectConfig,
configArtifacts[projectName],
projectName,
Expand Down Expand Up @@ -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<void> => {
for (const [referenceName, contractConfig] of Object.entries(
parsedConfig.contracts
)) {
Expand All @@ -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 (
Expand Down
3 changes: 3 additions & 0 deletions packages/plugins/contracts/foundry/Sphinx.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ contract Sphinx is Script {
ConfigCache memory configCache = abi.decode(retdata, (ConfigCache));

BundleInfo memory bundleInfo = getBundleInfo(
_rpcUrl,
configCache,
_projectName,
configs.userConfigStr,
Expand Down Expand Up @@ -256,6 +257,7 @@ contract Sphinx is Script {
}

function getBundleInfo(
string memory _rpcUrl,
ConfigCache memory _configCache,
string memory _projectName,
string memory _userConfigStr,
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion packages/plugins/contracts/foundry/SphinxUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ 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,
string memory _rootFfiPath,
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");
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ interface ISphinxUtils {
) external returns (OptionalString memory);

function ffiGetEncodedBundleInfo(
string memory _rpcUrl,
ConfigCache memory _configCache,
string memory _projectName,
string memory _userConfigStr,
Expand Down
5 changes: 5 additions & 0 deletions packages/plugins/src/foundry/get-bundle-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -95,6 +99,7 @@ const ownerAddress = args[4]
)

await projectPostParsingValidation(
provider,
parsedProjectConfig,
projectConfigArtifacts,
projectName,
Expand Down

0 comments on commit b93b5a9

Please sign in to comment.