Skip to content

Commit

Permalink
feat(core): update diff to include constructor arg variables and post…
Browse files Browse the repository at this point in the history
…-deployment actions
  • Loading branch information
sam-goldman committed Sep 4, 2023
1 parent 5de8fa5 commit 2913976
Show file tree
Hide file tree
Showing 16 changed files with 999 additions and 265 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-guests-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sphinx-labs/core': minor
---

Update diff to include constructor arg variables and post-deployment actions
12 changes: 3 additions & 9 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# FAQ

### How do I deploy a contract when another contract already exists at its `CREATE3` address?
### Why is Sphinx skipping a contract deployment or function call?

Sphinx detects this situation and outputs the following message in the diff:
```bash
Skipping:
Reason: Contract already deployed at the Create3 address.
Contract(s):
...
```
With Sphinx, contract deployments and function calls are idempotent. This means that they'll only be executed once per chain, even if you re-deploy your config file.

To deploy a new contract, you must change its `CREATE3` address. There are two ways to do this:
If you'd like to re-deploy a contract instead of skipping it, you must change its `CREATE3` address. There are two ways to do this:
1. (Recommended): Add a `salt` to the contract definition in the Sphinx config file. For more info on the `salt`, see [here](https://github.com/sphinx-labs/sphinx/blob/develop/docs/config-file.md#contract-definitions).
2. Change the reference name of the contract. For more info on reference names, see [here](https://github.com/sphinx-labs/sphinx/blob/develop/docs/config-file.md#reference-names).
26 changes: 18 additions & 8 deletions packages/core/src/actions/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import {
getEmptyCanonicalConfig,
toHexString,
fromHexString,
getCallHash,
isSupportedChainId,
parseSemverVersion,
prettyFunctionCall,
skipCallAction,
} from '../utils'
import {
ApproveDeployment,
Expand Down Expand Up @@ -535,6 +536,12 @@ export const makeActionBundleFromConfig = (
const { isTargetDeployed } = configCache.contractConfigCache[referenceName]
const { kind, salt, constructorArgs } = contractConfig

const readableSignature = prettyFunctionCall(
referenceName,
'constructor',
constructorArgs
)

const deployContractCost = getEstDeployContractCost(
buildInfo.output.contracts[sourceName][contractName].evm.gasEstimates
)
Expand Down Expand Up @@ -570,7 +577,7 @@ export const makeActionBundleFromConfig = (

humanReadableActions[actionIndex] = {
actionIndex,
reason: referenceName,
reason: readableSignature,
actionType: SphinxActionType.DEPLOY_CONTRACT,
}

Expand Down Expand Up @@ -604,7 +611,7 @@ export const makeActionBundleFromConfig = (

humanReadableActions[actionIndex] = {
actionIndex,
reason: referenceName,
reason: readableSignature,
actionType: SphinxActionType.DEPLOY_CONTRACT,
}

Expand All @@ -618,9 +625,7 @@ export const makeActionBundleFromConfig = (
const postDeployActions = parsedConfig.postDeploy[chainId]
if (postDeployActions) {
for (const { to, data, nonce, readableSignature } of postDeployActions) {
const callHash = getCallHash(to, data)
const currentNonce = configCache.callNonces[callHash]
if (nonce >= currentNonce) {
if (!skipCallAction(to, data, nonce, configCache.callNonces)) {
actions.push({
to,
index: actionIndex,
Expand All @@ -631,7 +636,11 @@ export const makeActionBundleFromConfig = (

humanReadableActions[actionIndex] = {
actionIndex,
reason: readableSignature,
reason: prettyFunctionCall(
readableSignature.referenceNameOrAddress,
readableSignature.functionName,
readableSignature.variables
),
actionType: SphinxActionType.CALL,
}

Expand Down Expand Up @@ -676,6 +685,7 @@ export const makeActionBundleFromConfig = (

humanReadableActions[actionIndex] = {
actionIndex,
// TODO(upgrades): add reason
reason: '',
actionType: SphinxActionType.SET_STORAGE,
}
Expand Down Expand Up @@ -812,7 +822,7 @@ export const getAuthLeafsForChain = async (
const managerVersionString = `v${configCache.managerVersion.major}.${configCache.managerVersion.minor}.${configCache.managerVersion.patch}`
if (
managerVersionString !== parsedConfig.options.managerVersion &&
configCache.isManagerDeployed
!configCache.isManagerDeployed
) {
const version = parseSemverVersion(parsedConfig.options.managerVersion)
const upgradeLeaf: AuthLeaf = {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import {
getFunctionArgValueArray,
getCallActionAddressForNetwork,
isSupportedChainId,
prettyFunctionCall,
hyperlink,
} from '../utils'
import { SphinxJsonRpcProvider } from '../provider'
Expand Down Expand Up @@ -3589,10 +3588,11 @@ export const parsePostDeploymentActions = (
to: address,
data,
nonce,
readableSignature: `${referenceName ?? address}.${prettyFunctionCall(
callAction.functionName,
argValues
)}`,
readableSignature: {
referenceNameOrAddress: referenceName ?? address,
functionName: callAction.functionName,
variables: parsedArgs,
},
}

const parsedActions: Array<ParsedCallAction> | undefined =
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export type UserConfigVariable =
export type ParsedConfigVariable =
| boolean
| string
| number
| Array<ParsedConfigVariable>
| {
[name: string]: ParsedConfigVariable
Expand Down Expand Up @@ -140,7 +139,13 @@ export type ParsedCallAction = {
to: string
data: string
nonce: number
readableSignature: string
readableSignature: SphinxFunctionSignature
}

export type SphinxFunctionSignature = {
referenceNameOrAddress: string
functionName: string
variables: ParsedConfigVariables
}

export interface ParsedConfig {
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/config/validation-error-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ export const failedToEncodeFunctionCall = (
referenceName?: string
): string => {
return (
`Failed to encode data for the function call on ${
referenceName ?? callAction.address
}:\n` +
`Failed to encode data for:\n` +
`${prettyFunctionCall(
referenceName ?? callAction.address,
callAction.functionName,
callAction.functionArgs
)}\n` +
Expand Down
Loading

0 comments on commit 2913976

Please sign in to comment.