Skip to content

Commit

Permalink
feat(pg): add foundry deploy task
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Jul 26, 2023
1 parent 1becd3c commit 48668b7
Show file tree
Hide file tree
Showing 65 changed files with 1,140 additions and 650 deletions.
9 changes: 9 additions & 0 deletions .changeset/forty-carrots-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@sphinx/plugins': minor
'@sphinx/contracts': patch
'@sphinx/executor': patch
'@sphinx/core': patch
'@sphinx/demo': patch
---

Add Foundry deploy task and update proposal, test, and init tasks
36 changes: 18 additions & 18 deletions packages/contracts/contracts/SphinxAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ contract SphinxAuth is AccessControlEnumerableUpgradeable, Semver {
event ProxyExported(bytes32 indexed authRoot, uint256 leafIndex);
event OwnerSet(bytes32 indexed authRoot, uint256 leafIndex);
event ThresholdSet(bytes32 indexed authRoot, uint256 leafIndex);
event DeployerOwnershipTransferred(bytes32 indexed authRoot, uint256 leafIndex);
event DeployerUpgraded(bytes32 indexed authRoot, uint256 leafIndex);
event ManagerOwnershipTransferred(bytes32 indexed authRoot, uint256 leafIndex);
event ManagerUpgraded(bytes32 indexed authRoot, uint256 leafIndex);
event AuthContractUpgraded(bytes32 indexed authRoot, uint256 leafIndex);
event DeployerAndAuthContractUpgraded(bytes32 indexed authRoot, uint256 leafIndex);
event ManagerAndAuthContractUpgraded(bytes32 indexed authRoot, uint256 leafIndex);
event ProposerSet(bytes32 indexed authRoot, uint256 leafIndex);
event DeploymentApproved(bytes32 indexed authRoot, uint256 leafIndex);
event ActiveDeploymentCancelled(bytes32 indexed authRoot, uint256 leafIndex);
Expand Down Expand Up @@ -333,7 +333,7 @@ contract SphinxAuth is AccessControlEnumerableUpgradeable, Semver {
emit ThresholdSet(_authRoot, _leaf.index);
}

function transferDeployerOwnership(
function transferManagerOwnership(
bytes32 _authRoot,
AuthLeaf memory _leaf,
bytes[] memory _signatures,
Expand All @@ -359,11 +359,11 @@ contract SphinxAuth is AccessControlEnumerableUpgradeable, Semver {
: managerOwnable.transferOwnership(newOwner);
SphinxManagerProxy(payable(address(manager))).changeAdmin(newOwner);

emit DeployerOwnershipTransferred(_authRoot, _leaf.index);
emit ManagerOwnershipTransferred(_authRoot, _leaf.index);
}

// Reverts if the SphinxManager is currently executing a deployment.
function upgradeDeployerImplementation(
function upgradeManagerImplementation(
bytes32 _authRoot,
AuthLeaf memory _leaf,
bytes[] memory _signatures,
Expand All @@ -384,14 +384,14 @@ contract SphinxAuth is AccessControlEnumerableUpgradeable, Semver {
_updateProposedAuthState(_authRoot);

(address impl, bytes memory data) = abi.decode(_leaf.data, (address, bytes));
SphinxManagerProxy deployerProxy = SphinxManagerProxy(payable(address(manager)));
SphinxManagerProxy managerProxy = SphinxManagerProxy(payable(address(manager)));
if (data.length > 0) {
deployerProxy.upgradeToAndCall(impl, data);
managerProxy.upgradeToAndCall(impl, data);
} else {
deployerProxy.upgradeTo(impl);
managerProxy.upgradeTo(impl);
}

emit DeployerUpgraded(_authRoot, _leaf.index);
emit ManagerUpgraded(_authRoot, _leaf.index);
}

function upgradeAuthImplementation(
Expand Down Expand Up @@ -425,7 +425,7 @@ contract SphinxAuth is AccessControlEnumerableUpgradeable, Semver {
}

// Reverts if the SphinxManager is currently executing a deployment.
function upgradeDeployerAndAuthImpl(
function upgradeManagerAndAuthImpl(
bytes32 _authRoot,
AuthLeaf memory _leaf,
bytes[] memory _signatures,
Expand All @@ -448,19 +448,19 @@ contract SphinxAuth is AccessControlEnumerableUpgradeable, Semver {
// Use scope here to prevent "Stack too deep" error
{
(
address deployerImpl,
bytes memory deployerData,
address managerImpl,
bytes memory managerData,
address authImpl,
bytes memory authData
) = abi.decode(_leaf.data, (address, bytes, address, bytes));

SphinxManagerProxy deployerProxy = SphinxManagerProxy(payable(address(manager)));
SphinxManagerProxy managerProxy = SphinxManagerProxy(payable(address(manager)));
SphinxManagerProxy authProxy = SphinxManagerProxy(payable(address(this)));

if (deployerData.length > 0) {
deployerProxy.upgradeToAndCall(deployerImpl, deployerData);
if (managerData.length > 0) {
managerProxy.upgradeToAndCall(managerImpl, managerData);
} else {
deployerProxy.upgradeTo(deployerImpl);
managerProxy.upgradeTo(managerImpl);
}

if (authData.length > 0) {
Expand All @@ -470,7 +470,7 @@ contract SphinxAuth is AccessControlEnumerableUpgradeable, Semver {
}
}

emit DeployerAndAuthContractUpgraded(_authRoot, _leaf.index);
emit ManagerAndAuthContractUpgraded(_authRoot, _leaf.index);
}

function setProposer(
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/SphinxManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { SphinxManagerEvents } from "./SphinxManagerEvents.sol";
* @notice This contract contains the logic for managing the entire lifecycle of a project's
deployments. It contains the functionality for approving and executing deployments and
exporting proxies out of the Sphinx system if desired. It exists as a single implementation
contract behind SphinxManagerProxy contracts.
contract behind SphinxManagerProxy contracts, which are each owned by a single project team.
After a deployment is approved, it is executed in the following steps, which must occur in order.
1. Execute all of the `DEPLOY_CONTRACT` actions using the `executeActions` function. This is
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const writeDeploymentArtifacts = async (
) => {
writeDeploymentFolderForNetwork(networkName, deploymentFolderPath)

const managerAddress = parsedConfig.deployer
const managerAddress = parsedConfig.manager

for (const deploymentEvent of deploymentEvents) {
if (!deploymentEvent.args) {
Expand Down
34 changes: 17 additions & 17 deletions packages/core/src/actions/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ export const getEncodedAuthLeafData = (leaf: AuthLeaf): string => {
case 'setThreshold':
return utils.defaultAbiCoder.encode(['uint256'], [leaf.newThreshold])

case 'transferDeployerOwnership':
case 'transferManagerOwnership':
return utils.defaultAbiCoder.encode(['address'], [leaf.newOwner])

case 'upgradeDeployerImplementation':
case 'upgradeManagerImplementation':
return utils.defaultAbiCoder.encode(
['address', 'bytes'],
[leaf.impl, leaf.data]
Expand All @@ -281,10 +281,10 @@ export const getEncodedAuthLeafData = (leaf: AuthLeaf): string => {
[leaf.impl, leaf.data]
)

case 'upgradeDeployerAndAuthImpl':
case 'upgradeManagerAndAuthImpl':
return utils.defaultAbiCoder.encode(
['address', 'bytes', 'address', 'bytes'],
[leaf.deployerImpl, leaf.deployerData, leaf.authImpl, leaf.authData]
[leaf.managerImpl, leaf.managerData, leaf.authImpl, leaf.authData]
)

case 'setProposer':
Expand Down Expand Up @@ -476,7 +476,7 @@ export const makeActionBundleFromConfig = (
configArtifacts: ConfigArtifacts,
configCache: ConfigCache
): SphinxActionBundle => {
const managerAddress = parsedConfig.deployer
const managerAddress = parsedConfig.manager
const actions: SphinxAction[] = []
for (const [referenceName, contractConfig] of Object.entries(
parsedConfig.contracts
Expand Down Expand Up @@ -588,7 +588,7 @@ export const makeTargetBundleFromConfig = (
parsedConfig: ParsedConfig,
configArtifacts: ConfigArtifacts
): SphinxTargetBundle => {
const { deployer } = parsedConfig
const { manager } = parsedConfig

const targets: SphinxTarget[] = []
for (const [referenceName, contractConfig] of Object.entries(
Expand All @@ -602,7 +602,7 @@ export const makeTargetBundleFromConfig = (
contractKindHash: contractKindHashes[contractConfig.kind],
addr: contractConfig.address,
implementation: getImplAddress(
deployer,
manager,
bytecode,
contractConfig.constructorArgs,
abi
Expand Down Expand Up @@ -634,7 +634,7 @@ export const getAuthLeafsForChain = async (
configCache: ConfigCache,
prevConfig: CanonicalConfig
): Promise<Array<AuthLeaf>> => {
const { options, project } = parsedConfig
const { options, projectName } = parsedConfig
const { proposers, chainIds } = options

// Get the previous config to use in the rest of this function. If the previous config
Expand All @@ -644,13 +644,13 @@ export const getAuthLeafsForChain = async (
? prevConfig
: getEmptyCanonicalConfig(
[chainId],
prevConfig.deployer,
prevConfig.manager,
prevConfig.options.orgId,
project
projectName
)

const {
deployer,
manager,
chainStates: prevChainStates,
options: prevOptions,
} = prevConfigForChain
Expand Down Expand Up @@ -707,7 +707,7 @@ export const getAuthLeafsForChain = async (
) {
const approvalLeaf: AuthLeaf = {
chainId,
to: deployer,
to: manager,
index,
approval: {
actionRoot: actionBundle.root,
Expand All @@ -730,7 +730,7 @@ export const getAuthLeafsForChain = async (
if (firstProposalOccurred && addProposalLeaf) {
const proposalLeaf: AuthLeaf = {
chainId,
to: deployer,
to: manager,
index: 0,
numLeafs: index,
leafType: 'propose',
Expand All @@ -740,7 +740,7 @@ export const getAuthLeafsForChain = async (
// We always add a Setup leaf if the first proposal hasn't occurred yet.
const setupLeaf: AuthLeaf = {
chainId,
to: deployer,
to: manager,
index: 0,
proposers: proposersToSet,
numLeafs: index,
Expand All @@ -752,7 +752,7 @@ export const getAuthLeafsForChain = async (
if (addProposalLeaf) {
const proposalLeaf: AuthLeaf = {
chainId,
to: deployer,
to: manager,
index: 1,
numLeafs: index,
leafType: 'propose',
Expand Down Expand Up @@ -809,7 +809,7 @@ export const findProposalRequestLeaf = (
export const getProjectDeploymentForChain = async (
leafs: Array<AuthLeaf>,
chainId: number,
project: string,
projectName: string,
configUri: string,
bundles: SphinxBundles
): Promise<ProjectDeployment | undefined> => {
Expand All @@ -830,7 +830,7 @@ export const getProjectDeploymentForChain = async (
return {
chainId,
deploymentId,
name: project,
name: projectName,
}
}

Expand Down
24 changes: 12 additions & 12 deletions packages/core/src/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ interface SetThreshold extends BaseAuthLeaf {
newThreshold: number
}

interface TransferDeployerOwnership extends BaseAuthLeaf {
leafType: 'transferDeployerOwnership'
interface TransferManagerOwnership extends BaseAuthLeaf {
leafType: 'transferManagerOwnership'
newOwner: string
}

interface UpgradeDeployerImplementation extends BaseAuthLeaf {
leafType: 'upgradeDeployerImplementation'
interface UpgradeManagerImplementation extends BaseAuthLeaf {
leafType: 'upgradeManagerImplementation'
impl: string
data: string
}
Expand All @@ -227,10 +227,10 @@ interface UpgradeAuthImplementation extends BaseAuthLeaf {
data: string
}

interface UpgradeAuthAndDeployerImpl extends BaseAuthLeaf {
leafType: 'upgradeDeployerAndAuthImpl'
deployerImpl: string
deployerData: string
interface UpgradeAuthAndManagerImpl extends BaseAuthLeaf {
leafType: 'upgradeManagerAndAuthImpl'
managerImpl: string
managerData: string
authImpl: string
authData: string
}
Expand Down Expand Up @@ -261,10 +261,10 @@ export type AuthLeaf =
| ExportProxy
| SetOwner
| SetThreshold
| TransferDeployerOwnership
| UpgradeDeployerImplementation
| TransferManagerOwnership
| UpgradeManagerImplementation
| UpgradeAuthImplementation
| UpgradeAuthAndDeployerImpl
| UpgradeAuthAndManagerImpl
| SetProposer
| ApproveDeployment
| CancelActiveDeployment
Expand All @@ -291,7 +291,7 @@ export type ProposalRequest = {
owners: string[]
threshold: number
authAddress: string
deployerAddress: string
managerAddress: string
deploymentName: string
chainIds: Array<number>
canonicalConfig: string
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getMinimalConfig = (
userConfig: UserSphinxConfig,
owner: string
): MinimalConfig => {
const deployer = getSphinxManagerAddress(owner, userConfig.project)
const manager = getSphinxManagerAddress(owner, userConfig.projectName)

const minimalContractConfigs: Array<MinimalContractConfig> = []
for (const [referenceName, contractConfig] of Object.entries(
Expand All @@ -29,7 +29,7 @@ export const getMinimalConfig = (
const { address, kind, salt } = contractConfig

const targetAddress =
address ?? getTargetAddress(deployer, referenceName, salt)
address ?? getTargetAddress(manager, referenceName, salt)

minimalContractConfigs.push({
referenceName,
Expand All @@ -39,9 +39,9 @@ export const getMinimalConfig = (
})
}
return {
deployer,
manager,
owner,
projectName: userConfig.project,
projectName: userConfig.projectName,
contracts: minimalContractConfigs,
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/config/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { CompilerConfig, ConfigArtifacts, ConfigCache } from './types'
import { makeBundlesFromConfig } from '../actions/bundle'
import { getConfigCache } from './parse'
import { Integration } from '../constants'

export const sphinxFetchSubtask = async (args: {
configUri: string
Expand Down Expand Up @@ -89,7 +90,8 @@ export const verifyDeployment = async (
*/
export const compileRemoteBundles = async (
provider: providers.JsonRpcProvider,
configUri: string
configUri: string,
integration: Integration
): Promise<{
bundles: SphinxBundles
compilerConfig: CompilerConfig
Expand All @@ -108,7 +110,8 @@ export const compileRemoteBundles = async (
compilerConfig.contracts,
configArtifacts,
getSphinxRegistryReadOnly(provider),
getSphinxManagerReadOnly(compilerConfig.deployer, provider)
getSphinxManagerReadOnly(compilerConfig.manager, provider),
integration
)

const bundles = makeBundlesFromConfig(
Expand Down
Loading

0 comments on commit 48668b7

Please sign in to comment.