Skip to content

Commit

Permalink
fix(pg): support IR compilation pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Dec 27, 2023
1 parent a9d7a1f commit 4a57beb
Show file tree
Hide file tree
Showing 27 changed files with 472 additions and 239 deletions.
8 changes: 8 additions & 0 deletions .changeset/tough-bags-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@sphinx-labs/contracts': patch
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
'@sphinx-labs/demo': patch
---

Support IR compilation pipeline
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Deployments with Sphinx are a three-step process:

## Key features:

* **Gasless Deployments**: You don't need to worry about securing a funded private key or getting native gas tokens on any chain. We'll bill you in fiat after your deployment is finished.
* **Gasless Deployments**: You don't need to worry about securing a funded private key or getting native gas tokens on any chain. We'll bill you in fiat after your deployment is finished. Deployments on testnets are completely free.

* **One-Click Multichain Deployments**: Approve deployments across 11 supported networks by signing a single meta transaction. Sphinx's backend will deploy on each network in parallel and verify your smart contracts on Etherscan.

Expand All @@ -19,7 +19,7 @@ Deployments with Sphinx are a three-step process:

* **Trustless**: It's impossible to execute anything your Gnosis Safe owners have not explicitly approved. Spearbit has audited our system; see our audit report [here](https://github.com/sphinx-labs/sphinx/blob/main/audit/spearbit.pdf).

* **Compatible with Forge Scripts**: You can integrate Sphinx with minimal changes to your existing Forge scripts. All you need to do is add a modifier to your `run()` function.
* **Compatible with Forge Scripts**: You can integrate Sphinx by adding a few lines of code to your existing Forge scripts.

## Request Access

Expand Down
4 changes: 2 additions & 2 deletions docs/ci-proposals.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Here is a list of things you may need to change in the template:
- Enter any RPC node provider API keys in the `env` section of the template.
- If your repository doesn't use Yarn, update the `yarn --frozen-lockfile` step under `jobs`.
- If your repository uses pnpm instead of Yarn or npm, change `npx sphinx propose` to `pnpm sphinx propose`.
- Make sure the path to your Sphinx deployment script in the `npx sphinx propose` command is correct.
- In the `sphinx propose` command, replace `<path/to/your/script.s.sol>` with the path to your Forge script.

## 6. Create the proposal workflow
Next, we'll create a workflow to propose the deployment when a pull request is merged.
Expand Down Expand Up @@ -130,7 +130,7 @@ Here is a list of things you may need to change in the template:
- If you want your target branch to be something other than `main`, update the `branches` section of the template.
- If your repository doesn't use Yarn, update the `yarn --frozen-lockfile` step under `jobs`.
- If your repository uses pnpm instead of Yarn or npm, change `npx sphinx propose` to `pnpm sphinx propose`.
- Make sure the path to your Sphinx deployment script in the `npx sphinx propose` command is correct.
- In the `sphinx propose` command, replace `<path/to/your/script.s.sol>` with the path to your Forge script.

## 7. Configure secret variables

Expand Down
128 changes: 68 additions & 60 deletions docs/cli-existing-project.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
# Getting Started with an Existing Foundry Project

In this guide, you'll integrate Sphinx's Foundry plugin with your existing Foundry project. Then, you'll deploy it on a few testnets.
In this guide, you'll integrate Sphinx with your existing Foundry project. Then, you'll deploy your project on a few testnets.

Deployments are a three-step process with the DevOps platform:

1. **Propose**: Initiate the deployment from your command line or CI process by submitting the transactions to Sphinx's backend.
2. **Approve**: Your Gnosis Safe owner(s) approve the deployment by signing a single meta transaction in the Sphinx UI.
3. **Execute**: Sphinx's backend trustlessly executes the deployment through your Gnosis Safe.

In this guide, you'll propose the deployment on the command line and then approve it in the Sphinx UI.
In this guide, you'll propose the deployment on the command line then approve it in the Sphinx UI.

## Table of Contents

1. [Prerequisites](#1-prerequisites)
2. [Update Foundry](#2-update-foundry)
3. [Install Sphinx](#3-install-sphinx)
4. [Update `.gitignore`](#4-update-gitignore)
5. [Add environment variables](#5-add-environment-variables)
6. [Update `foundry.toml` settings](#6-update-foundrytoml-settings)
7. [Update RPC endpoints](#7-update-rpc-endpoints)
8. [Add remappings](#8-add-remappings)
9. [Update your deployment script](#9-update-your-deployment-script)
5. [Add remappings](#5-add-remappings)
6. [Update your deployment script](#6-update-your-deployment-script)\
a. [Import Sphinx](#a-import-sphinx)\
b. [Inherit from `Sphinx`](#b-inherit-from-sphinx)\
c. [Update your `run()` function](#c-update-your-run-function)\
d. [Remove broadcasts](#d-remove-broadcasts)\
e. [Add configuration options](#e-add-configuration-options)
7. [Add environment variables](#7-add-environment-variables)
8. [Update RPC endpoints](#8-update-rpc-endpoints)
9. [Update `foundry.toml` settings](#9-update-foundrytoml-settings)
10. [Run tests](#10-run-tests)
11. [Propose on testnets](#11-propose-on-testnets)
12. [Next steps](#12-next-steps)
Expand All @@ -29,12 +34,12 @@ In this guide, you'll propose the deployment on the command line and then approv

* You must have an invite link to the DevOps platform because it's currently invite-only. [Request access on Sphinx's website.](https://sphinx.dev)
* You must have an existing Foundry project that includes a Forge script. If you don't, we recommend following the [Getting Started in a New Repository guide](https://github.com/sphinx-labs/sphinx/blob/main/docs/cli-quickstart.md) instead.
* You must have an RPC node provider API key. If you don't already have one, we recommend [Alchemy](https://www.alchemy.com/) or [Infura](https://www.infura.io/).
* You must have an account that exists on live networks. This account will own your Gnosis Safe.
* The following must be installed on your machine:
* [Foundry](https://book.getfoundry.sh/getting-started/installation)
* [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/), [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or [pnpm](https://pnpm.io/installation)
* [Node Version >=16.16.0](https://nodejs.org/en/download). (Run `node -v` to see your current version).
* You must have an RPC node provider API key. If you don't already have one, we recommend [Alchemy](https://www.alchemy.com/) or [Infura](https://www.infura.io/).
* You must have an account that exists on live networks. This account will own your Gnosis Safe.

## 2. Update Foundry

Expand Down Expand Up @@ -70,46 +75,7 @@ Add the following to your `.gitignore` file:
node_modules/
```

## 5. Add environment variables

Get your Sphinx API Key from the Sphinx UI, then enter it as an environment variable:
```
SPHINX_API_KEY=<your API key>
```

Also, if you haven't added your node provider API key as an environment variable, please do so now. For example:
```
RPC_API_KEY=<your API key>
```

## 6. Update `foundry.toml` settings

Update your `foundry.toml` file to include a few settings required by Sphinx. We recommend putting them in `[profile.default]`.

```
ffi = true
build_info = true
extra_output = ['storageLayout']
fs_permissions = [{ access = "read-write", path = "./"}]
allow_paths = ["../.."]
```

## 7. Update RPC endpoints

Include an RPC endpoint in the `[rpc_endpoints]` section of your `foundry.toml` for each testnet you'd like to deploy on. For example, if you're using Alchemy, your `foundry.toml` might look like this:

```toml
[rpc_endpoints]
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${RPC_API_KEY}"
optimism_sepolia = "https://opt-sepolia.g.alchemy.com/v2/${RPC_API_KEY}"
arbitrum_sepolia = "https://arb-sepolia.g.alchemy.com/v2/${RPC_API_KEY}"
```

If you'd like to deploy on different networks, see the [full list of testnets that Sphinx supports](https://github.com/sphinx-labs/sphinx/blob/main/docs/configuration-options.md#network-testnets).

> Note: The names of the RPC endpoints in your `foundry.toml` must match the testnet names in the [Sphinx Configuration Options reference](https://github.com/sphinx-labs/sphinx/blob/main/docs/configuration-options.md#network-testnets). For example, `optimism_sepolia` is a valid RPC endpoint name, but `optimism_testnet` is not.
## 8. Add remappings
## 5. Add remappings

Run the following command to generate remappings for the Sphinx packages.

Expand All @@ -127,19 +93,19 @@ pnpm sphinx remappings --pnpm

Add the remappings to your `remappings.txt` file or the `remappings` array in your `foundry.toml`.

## 9. Update your deployment script
## 6. Update your deployment script

Navigate to your deployment script. We'll adjust it slightly in this section.
Navigate to your deployment script. In this section, we'll update it to be compatible with Sphinx.

#### a. Import Sphinx
### a. Import Sphinx

Add the following import in your deployment script:

```sol
import "@sphinx-labs/plugins/SphinxPlugin.sol";
```

#### b. Inherit from `Sphinx`
### b. Inherit from `Sphinx`

Inherit from `Sphinx` in your deployment script.

Expand All @@ -150,7 +116,7 @@ contract MyDeploymentScript is
// ...
```

#### c. Update your `run()` function
### c. Update your `run()` function

The entry point of your deployment script must be a `run()` function; it cannot be named anything else. Please change its name if necessary.

Expand All @@ -164,7 +130,12 @@ function run() sphinx public override {

We'll explain the Sphinx modifier in a later guide.

#### d. Add configuration options

### d. Remove broadcasts

Remove any `vm.startBroadcast` and `vm.broadcast` calls from your deployment script. Broadcasting is no longer required because you aren't be executing your deployment from the CLI.

### e. Add configuration options

There are a few configuration options that you must specify inside the `setUp()` function or constructor in your deployment script. These options all exist on the `sphinxConfig` struct, which is inherited from `Sphinx.sol`.

Expand All @@ -178,15 +149,52 @@ sphinxConfig.testnets = [
Network.optimism_sepolia,
Network.arbitrum_sepolia
];
sphinxConfig.mainnets;
sphinxConfig.projectName = "My First Project";
sphinxConfig.threshold = 1;
```

You'll need to update the following fields in this template:
* Enter your address in the `owners` array.
* Enter your Sphinx Organization ID in the `orgId` field. It's a public field, so you don't need to keep it secret. You can find it in the Sphinx UI.
* If you're deploying on networks other than Sepolia, Optimism Sepolia, and Arbitrum Sepolia, update the `testnets` array. You can find a list of valid fields in the [Sphinx Configuration Options reference](https://github.com/sphinx-labs/sphinx/blob/main/docs/configuration-options.md#network-testnets).
* If you'd like to deploy on networks other than Sepolia, Optimism Sepolia, and Arbitrum Sepolia, update the `testnets` array. You can find a list of valid fields in the [Sphinx Configuration Options reference](https://github.com/sphinx-labs/sphinx/blob/main/docs/configuration-options.md#network-testnets).

## 7. Add environment variables

Get your Sphinx API Key from the Sphinx UI, then enter it as an environment variable:
```
SPHINX_API_KEY=<your_api_key>
```

Also, if you haven't added your node provider API key as an environment variable, please do so now. For example:
```
ALCHEMY_API_KEY=<your_api_key>
INFURA_API_KEY=<your_api_key>
```

## 8. Update RPC endpoints

Include an RPC endpoint in your `foundry.toml` for each testnet you'd like to deploy on. The names of the RPC endpoints in your `foundry.toml` must match the testnet names in the `sphinxConfig.testnets` array that you defined in your deployment script. For example, `sepolia` is a valid RPC endpoint name, but `ethereum_testnet` is not.

Here's what your `foundry.toml` might look like if you're using Alchemy:

```toml
[rpc_endpoints]
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${RPC_API_KEY}"
optimism_sepolia = "https://opt-sepolia.g.alchemy.com/v2/${RPC_API_KEY}"
arbitrum_sepolia = "https://arb-sepolia.g.alchemy.com/v2/${RPC_API_KEY}"
```

## 9. Update `foundry.toml` settings

Update your `foundry.toml` file to include a few settings required by Sphinx. We recommend putting them in `[profile.default]`.

```
ffi = true
build_info = true
extra_output = ['storageLayout']
fs_permissions = [{ access = "read-write", path = "./"}]
allow_paths = ["../.."]
```

## 10. Run tests

Expand All @@ -196,18 +204,18 @@ If you can't get your test suite to pass, we're more than happy to help! Reach o

## 11. Propose on testnets

Copy and paste one of the following commands to propose your deployment with the DevOps platform.
Copy and paste one of the following commands to propose your deployment with the DevOps platform. Make sure to replace `<path/to/your/script.s.sol>` with the path to your Forge script.

Using Yarn or npm:

```
npx sphinx propose script/HelloSphinx.s.sol --testnets
npx sphinx propose <path/to/your/script.s.sol> --testnets
```

Using pnpm:

```
pnpm sphinx propose script/HelloSphinx.s.sol --testnets
pnpm sphinx propose <path/to/your/script.s.sol> --testnets
```

Here are the steps that occur when you run this command:
Expand Down
2 changes: 1 addition & 1 deletion docs/cli-propose.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [Examples](#examples)

## Overview
The `propose` command proposes a deployment in the Sphinx DevOps platform.
The `propose` command proposes a deployment in the Sphinx DevOps Platform.

The following steps occur when this command is run:
1. **Simulation**: Sphinx simulates the deployment by invoking the script's `run()` function on a fork of each network. If a transaction reverts during the simulation, Sphinx will throw an error.
Expand Down
4 changes: 2 additions & 2 deletions docs/cli-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ In this guide, you'll create a sample project, propose it on the command line, a
* You must have a basic understanding of how to use Foundry and Forge scripts. Here are the relevant guides in the Foundry docs:
* [Getting Started with Foundry](https://book.getfoundry.sh/getting-started/first-steps)
* [Writing Deployment Scripts with Foundry](https://book.getfoundry.sh/tutorials/solidity-scripting)
* You must have an Alchemy API key, which you can get on [their website](https://www.alchemy.com/).
* You must have an account that exists on live networks. This account will own your Gnosis Safe.
* The following must be installed on your machine:
* [Foundry](https://book.getfoundry.sh/getting-started/installation)
* [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/), [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or [pnpm](https://pnpm.io/installation)
* [Node Version >=16.16.0](https://nodejs.org/en/download). (Run `node -v` to see your current version).
* You must have an Alchemy API key, which you can get on [their website](https://www.alchemy.com/).
* You must have an account that exists on live networks. This account will own your Gnosis Safe.

## 2. Create a new directory

Expand Down
8 changes: 4 additions & 4 deletions docs/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ Valid values:
| Ethereum | `Network.ethereum` |
| Optimism | `Network.optimism` |
| Arbitrum | `Network.arbitrum` |
| Polygon POS | `Network.polygon` |
| Polygon PoS | `Network.polygon` |
| Binance Smart Chain | `Network.bnb` |
| Gnosis Chain | `Network.gnosis` |
| Linea | `Network.linea` |
| Polygon ZKEVM | `Network.polygon_zkevm` |
| Avalanche C Chain | `Network.avalanche` |
| Polygon zkEVM | `Network.polygon_zkevm` |
| Avalanche C-Chain | `Network.avalanche` |
| Fantom | `Network.fantom` |
| Base | `Network.base` |

Expand All @@ -101,7 +101,7 @@ Valid values:
| Binance Smart Chain Testnet | `Network.bnb_testnet` |
| Gnosis Chiado | `Network.gnosis_chiado` |
| Linea Goerli | `Network.linea_goerli` |
| Polygon ZKEVM Goerli | `Network.polygon_zkevm_goerli` |
| Polygon zkEVM Goerli | `Network.polygon_zkevm_goerli` |
| Avalanche Fuji | `Network.avalanche_fuji` |
| Fantom Testnet | `Network.fantom_testnet` |
| Base Sepolia | `Network.base_sepolia` |
2 changes: 1 addition & 1 deletion docs/troubleshooting-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This guide covers some common issues you might encounter using Sphinx. If your q

## Labeling contracts

When Sphinx can't infer the contract corresponding to an address, you'll be asked to label it yourself. Labels allow Sphinx to write the contract's deployment artifact and verify it on Etherscan.
When Sphinx can't infer the contract corresponding to an address, you'll be asked to label it yourself. This makes it possible for Sphinx to verify the contract on Etherscan and create a deployment artifact for it.

You can label a contract in your deployment script with the `sphinxLabel` function, which is inherited from `Sphinx.sol`. For example:

Expand Down
Loading

0 comments on commit 4a57beb

Please sign in to comment.