Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:chugsplash/chugsplash into sg/al…
Browse files Browse the repository at this point in the history
…low-blanks
  • Loading branch information
sam-goldman committed Feb 16, 2023
2 parents c8af97c + 51642ff commit ea49829
Show file tree
Hide file tree
Showing 74 changed files with 3,619 additions and 1,987 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-donuts-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chugsplash/contracts': patch
'@chugsplash/plugins': patch
---

Use JSON bundle in contract unit tests
6 changes: 0 additions & 6 deletions .changeset/early-fans-walk.md

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ If you want to use ChugSplash in production, ask a question, or request a featur
## Documentation

- [ChugSplash File](https://github.com/chugsplash/chugsplash/blob/develop/docs/chugsplash-file.md): Detailed explanation of the file where you define your deployments and upgrades.
- [Variables Reference](https://github.com/chugsplash/chugsplash/blob/develop/docs/variables.md): Explains how to assign values to every variable type in a ChugSplash file.
- [Variables Reference](https://github.com/chugsplash/chugsplash/blob/develop/docs/variables.md): Reference describing how to assign values to every variable type in a ChugSplash file.
- [Immutable Variables](https://github.com/chugsplash/chugsplash/blob/develop/docs/immutable-variables.md): How to define immutable variables with ChugSplash.
- [Storage Layout Safety Checker](https://github.com/chugsplash/chugsplash/blob/develop/docs/storage-checker.md): Explains the type of storage layout errors that ChugSplash automatically detects.
- [Using ChugSplash on Live Networks](https://github.com/chugsplash/chugsplash/blob/develop/docs/live-network.md): Instructions for using ChugSplash to deploy or upgrade a project on a live network.
- [Import Contracts from the OpenZeppelin Hardhat Upgrades API](https://github.com/chugsplash/chugsplash/blob/develop/docs/import-openzeppelin.md).
- [Importing Contracts from the OpenZeppelin Hardhat Upgrades API](https://github.com/chugsplash/chugsplash/blob/develop/docs/import-openzeppelin.md): Upgrade your existing OpenZeppelin proxies using ChugSplash.

## Supported Networks

Expand Down
15 changes: 9 additions & 6 deletions docs/hardhat/setup-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ If your repository has an existing Hardhat project, you can skip to [here](#inst
## Table of Contents

- [Initialize Node.js](#initialize-nodejs)
- [Setup Hardhat](#setup-hardhat)
- [Install Hardhat](#install-hardhat)
- [Initialize Hardhat](#initialize-hardhat)
- [Install ChugSplash](#install-chugsplash)
- Setup ChugSplash:
- [In a JavaScript Project](#setup-chugsplash-using-javascript)
Expand All @@ -28,7 +29,7 @@ With npm:
npm init -y
```

## Setup Hardhat
## Install Hardhat

Install Hardhat in your repository if it isn't already installed.

Expand All @@ -42,7 +43,7 @@ With npm:
npm install --save-dev hardhat
```

Then, initialize Hardhat:
## Initialize Hardhat

```
npx hardhat
Expand All @@ -52,11 +53,11 @@ npx hardhat

With Yarn:
```
yarn add --dev @chugsplash/plugins @chugsplash/core
yarn add --dev @chugsplash/plugins
```
With npm:
```
npm install --save-dev @chugsplash/plugins @chugsplash/core
npm install --save-dev @chugsplash/plugins
```

## Setup ChugSplash using JavaScript
Expand Down Expand Up @@ -171,4 +172,6 @@ npx hardhat test test/HelloChugSplash.spec.ts

## Learn More

Once you've set up a ChugSplash project, the next step is to learn about the [ChugSplash file](https://github.com/chugsplash/chugsplash/blob/develop/docs/chugsplash-file.md), which is where you define deployments and upgrades.
Once you've set up a ChugSplash project, the next step is to learn about the [ChugSplash
file](https://github.com/chugsplash/chugsplash/blob/develop/docs/chugsplash-file.md), which is where
you define deployments and upgrades.
94 changes: 94 additions & 0 deletions docs/immutable-variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Defining Immutable Variables

There are two ways to assign values to immutable variables when using ChugSplash.

## 1. Direct assignment

The first option is to directly assign the immutable variable to its value in your contract. For example:

```sol
uint public immutable myNum = block.timestamp;
```

You don't need to create a variable definition in your ChugSplash file if you do this.

## 2. Define `constructorArgs` in your ChugSplash file

The other option is to define a `constructorArgs` field in your ChugSplash file. For example, say you have the following contract:

```sol
contract MyContract {
uint public immutable myNum;
constructor(uint _num) {
myNum = _num;
}
}
```

Your ChugSplash file would be:
```ts
{
options: { ... },
contracts: {
MyToken: {
contract: 'MyContract',
variables: {},
// Define constructor arguments:
constructorArgs: {
_num: 2
}
}
}
}
```

Notice that we assign a value to the constructor argument, `_num`, instead of the variable `myNum`.

### Why not use the `variables` field in the ChugSplash file to define immutable variables?

It might seem natural to define immutable variables in the same manner that you define mutable state variables in your ChugSplash file (via the `variables` section).

However, you **cannot** use the `variables` section in your ChugSplash file to define immutable variables. For example, say you have an immutable variable, `myNum`, in your contract. ChugSplash would throw an error if you attempted to do:

```ts
{
options: { ... },
contracts: {
MyToken: {
contract: 'MyContract',
variables: {
myNum: 2 // Not allowed!
}
}
}
}
```

ChugSplash does not allow this because of a restriction imposed by the Solidity compiler. Specifically, the Solidity compiler requires that immutable variables are either assigned to a value inline (as seen in the [direct assignment section](#1-direct-assignment)), or in the body of the constructor. It will throw an error otherwise. For example, consider the following contract:

```sol
contract MyContract {
// Variable is never initialized
uint public immutable myNum;
}
```

Compiling this contract will result in the following error thrown by the Solidity compiler:
```
TypeError: Construction control flow ends without initializing all immutable state variables.
```

To resolve this error, you must create a constructor to initialize the variable:
```sol
contract MyContract {
uint public immutable myNum;
constructor(uint _num) {
myNum = _num;
}
}
```

Since a constructor is required in this situation, the most straightforward solution is for users to pass in their constructor arguments via a `constructorArgs` section in the ChugSplash file. We chose to make this a separate section from `variables` to avoid confusion between the two ways of assigning variables.

17 changes: 17 additions & 0 deletions packages/contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @chugsplash/contracts

## 0.5.1

### Patch Changes

- ca6d384: Bump contracts

## 0.5.0

### Minor Changes

- fa3f420: Add support for UUPS proxies

### Patch Changes

- 263b34d: Add logic for claiming bundles
- 57a327d: Temporarily allow anyone to propose bundles

## 0.4.3

### Patch Changes
Expand Down
20 changes: 0 additions & 20 deletions packages/contracts/contracts/ChugSplashBootLoader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ pragma solidity ^0.8.9;
import { ChugSplashRegistry } from "./ChugSplashRegistry.sol";
import { ChugSplashManager } from "./ChugSplashManager.sol";
import { ChugSplashManagerProxy } from "./ChugSplashManagerProxy.sol";
import { ProxyUpdater } from "./ProxyUpdater.sol";
import { Reverter } from "./Reverter.sol";
import { Create2 } from "./libraries/Create2.sol";
import { Proxy } from "./libraries/Proxy.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Expand All @@ -20,16 +18,6 @@ contract ChugSplashBootLoader is Initializable {
address public constant DETERMINISTIC_DEPLOYMENT_PROXY_ADDRESS =
0x4e59b44847b379578588920cA78FbF26c0B4956C;

/**
* @notice The ProxyUpdater.
*/
ProxyUpdater public proxyUpdater;

/**
* @notice The Reverter.
*/
Reverter public reverter;

/**
* @notice Address of the ChugSplashRegistry implementation contract.
*/
Expand Down Expand Up @@ -66,12 +54,6 @@ contract ChugSplashBootLoader is Initializable {
address _registryProxy,
bytes32 _salt
) external initializer {
// Deploy the ProxyUpdater.
proxyUpdater = new ProxyUpdater{ salt: _salt }();

// Deploy the Reverter.
reverter = new Reverter{ salt: _salt }();

// Deploy the root ChugSplashManager's proxy.
rootManagerProxy = new ChugSplashManagerProxy{ salt: _salt }(
ChugSplashRegistry(_registryProxy),
Expand All @@ -89,8 +71,6 @@ contract ChugSplashBootLoader is Initializable {

// Deploy and initialize the ChugSplashRegistry's implementation contract.
registryImplementation = new ChugSplashRegistry{ salt: _salt }(
address(proxyUpdater),
address(reverter),
_ownerBondAmount,
_executionLockTime,
_executorPaymentPercentage,
Expand Down
26 changes: 25 additions & 1 deletion packages/contracts/contracts/ChugSplashDataTypes.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

/**
* @notice Struct representing an entire ChugSplash bundle.
*/
struct ChugSplashBundle {
ChugSplashActionWithProof[] actions;
bytes32 root;
}

/**
* @notice Struct representing a single ChugSplash action along with its Merkle proof.
*/
struct ChugSplashActionWithProof {
ChugSplashAction action;
ChugSplashProof proof;
}

/**
* @notice Struct representing a Merkle proof for a single ChugSplash action.
*/
struct ChugSplashProof {
uint256 actionIndex;
bytes32[] siblings;
}

/**
* @notice Struct representing the state of a ChugSplash bundle.
*/
Expand All @@ -17,9 +41,9 @@ struct ChugSplashBundleState {
* @notice Struct representing a ChugSplash action.
*/
struct ChugSplashAction {
string referenceName;
ChugSplashActionType actionType;
bytes data;
string referenceName;
}

/**
Expand Down
Loading

0 comments on commit ea49829

Please sign in to comment.