Skip to content

Commit

Permalink
feat(pg): Install Sphinx fork during sphinx install
Browse files Browse the repository at this point in the history
  • Loading branch information
RPate97 committed Feb 7, 2024
1 parent 0adf30f commit 52e2f59
Show file tree
Hide file tree
Showing 6 changed files with 385 additions and 72 deletions.
61 changes: 23 additions & 38 deletions docs/cli-existing-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ In this guide, you'll propose the deployment on the command line and then approv
## Table of Contents

1. [Prerequisites](#1-prerequisites)
2. [Install Sphinx Foundry Fork](#2-install-sphinx-foundry-fork)
3. [Install Sphinx CLI](#3-install-sphinx-cli)
4. [Install Sphinx Foundry library](#4-install-sphinx-foundry-library)
5. [Update `.gitignore`](#5-update-gitignore)
6. [Add remapping](#6-add-remapping)
7. [Update your deployment script](#7-update-your-deployment-script)\
2. [Install Sphinx CLI](#2-install-sphinx-cli)
3. [Install Sphinx Foundry library](#3-install-sphinx-foundry-library)
4. [Update `.gitignore`](#4-update-gitignore)
5. [Add remapping](#5-add-remapping)
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. [Handle new sender address](#e-handle-new-sender-address)\
f. [Add configuration options](#e-add-configuration-options)
8. [Add environment variables](#8-add-environment-variables)
9. [Update RPC endpoints](#9-update-rpc-endpoints)
10. [Update `foundry.toml` settings](#10-update-foundrytoml-settings)
11. [Run tests](#11-run-tests)
12. [Propose on testnets](#12-propose-on-testnets)
13. [Next steps](#13-next-steps)
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)

## 1. Prerequisites

Expand All @@ -44,22 +43,7 @@ In this guide, you'll propose the deployment on the command line and then approv
* [Node Version >=16.16.0](https://nodejs.org/en/download). (Run `node -v` to see your current version).
* [Rust Compiler](https://www.rust-lang.org/tools/install)

## 2. Install Sphinx Foundry Fork
For now, Sphinx requires a [fork of Foundry](https://github.com/sphinx-labs/foundry) that resolves several bugs that conflict with Sphinx. We're working on getting these fixed in the official Foundry repo.

If you are using macOS, you will first need to install the Xcode Command Line Tools:
```
xcode-select --install
```

Then, install the Sphinx Foundry fork with the following command. The installation process may take several minutes to complete.
```
foundryup --repo sphinx-labs/foundry --branch sphinx-patch-v0.1.0
```

> If you run into problems installing our Foundry fork, [try steps in the troubleshooting guide](https://github.com/sphinx-labs/sphinx/blob/main/docs/troubleshooting-guide.md#installing-sphinxs-foundry-fork). If you are still unable to resolve the issue, please reach out in the [Discord](https://discord.gg/7Gc3DK33Np). We're always happy to help.
## 3. Install Sphinx CLI
## 2. Install Sphinx CLI

Navigate to your smart contract workspace. In a standard repo, this is the root of your project. In a monorepo, you should move to your contracts package.

Expand All @@ -80,7 +64,8 @@ pnpm:
pnpm add -D @sphinx-labs/plugins
```

## 4. Install Sphinx Foundry Library

## 3. Install Sphinx Foundry Library

Use the `sphinx install` command to install the Sphinx Foundry library.

Expand All @@ -99,22 +84,22 @@ pnpm:
pnpm sphinx install
```

## 5. Update `.gitignore`
## 4. Update `.gitignore`

Add the following to your `.gitignore` file:
```
node_modules/
```

## 6. Add remapping
## 5. Add remapping

Configure the following remapping in either your `foundry.toml` file or `remappings.txt` file:

```
@sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry
```

## 7. Update your deployment script
## 6. Update your deployment script

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

Expand Down Expand Up @@ -187,7 +172,7 @@ You'll need to update the following fields in this template:
* 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'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).

## 8. Add environment variables
## 7. Add environment variables

Get your Sphinx API Key from the Sphinx UI, then enter it as an environment variable:
```
Expand All @@ -199,7 +184,7 @@ Also, if you haven't added your node provider API key as an environment variable
ALCHEMY_API_KEY=<your_api_key>
```

## 9. Update RPC endpoints
## 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.

Expand All @@ -212,7 +197,7 @@ optimism_sepolia = "https://opt-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
arbitrum_sepolia = "https://arb-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
```

## 10. Update `foundry.toml` settings
## 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]`.

Expand All @@ -223,13 +208,13 @@ fs_permissions = [{ access = "read-write", path = "./"}]
always_use_create_2_factory = true
```

## 11. Run tests
## 10. Run tests

You've finished integrating Sphinx! Your next step is to check that your existing tests are passing. Go ahead and run your Forge tests.

If you can't get your test suite to pass, we're more than happy to help! Reach out to us in our [Discord](https://discord.gg/7Gc3DK33Np).

## 12. Propose on testnets
## 11. Propose on testnets

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.

Expand All @@ -252,6 +237,6 @@ Here are the steps that occur when you run this command:

When the proposal is finished, go to the [Sphinx UI](https://sphinx.dev) to approve the deployment. After you approve it, you can monitor the deployment's status in the UI while it's executed.

## 13. Next steps
## 12. Next steps

Before you use Sphinx in production, we recommend reading the [Writing Deployment Scripts with Sphinx guide](https://github.com/sphinx-labs/sphinx/blob/main/docs/writing-scripts.md), which covers essential information for using Sphinx.
32 changes: 8 additions & 24 deletions docs/cli-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ In this guide, you'll create a sample project, propose it on the command line, a
1. [Prerequisites](#1-prerequisites)
2. [Create a new directory](#2-create-a-new-directory)
3. [Install dependencies](#3-install-dependencies)
4. [Install Sphinx Foundry Fork](#4-install-sphinx-foundry-fork)
5. [Initialize a project](#5-initialize-a-project)
6. [Test the deployment](#6-test-the-deployment)
7. [Propose on testnets](#7-propose-on-testnets)
8. [Next steps](#8-next-steps)
4. [Initialize a project](#4-initialize-a-project)
5. [Test the deployment](#5-test-the-deployment)
6. [Propose on testnets](#6-propose-on-testnets)
7. [Next steps](#7-next-steps)

## 1. Prerequisites

Expand Down Expand Up @@ -62,22 +61,7 @@ pnpm:
pnpm add -D @sphinx-labs/plugins https://github.com/foundry-rs/forge-std.git#v1.7.1 https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0
```

## 4. Install Sphinx Foundry Fork
For now, Sphinx requires a [fork of Foundry](https://github.com/sphinx-labs/foundry) that resolves several bugs that conflict with Sphinx. We're working on getting these fixed in the official Foundry repo.

If you are using macOS, you will first need to install the Xcode Command Line Tools:
```
xcode-select --install
```

Then, install the Sphinx Foundry fork with the following command. The installation process may take several minutes to complete.
```
foundryup --repo sphinx-labs/foundry --branch sphinx-patch-v0.1.0
```

> If you run into problems installing our Foundry fork, [try steps in the troubleshooting guide](https://github.com/sphinx-labs/sphinx/blob/main/docs/troubleshooting-guide.md#installing-sphinxs-foundry-fork). If you are still unable to resolve the issue, please reach out in the [Discord](https://discord.gg/7Gc3DK33Np). We're always happy to help.
## 5. Initialize a project
## 4. Initialize a project

Run one of the following commands on your command line, replacing the placeholders with your values. We've included a description of each command line argument below.

Expand Down Expand Up @@ -108,13 +92,13 @@ After you run the command, you'll notice several new files:
- `.env`: A sample `.env` file that contains your credentials.
- `.gitignore`: A sample `.gitignore` file that contains files and directories generated by Sphinx, Foundry, and Node.

## 6. Test the deployment
## 5. Test the deployment

```
forge test
```

## 7. Propose on testnets
## 6. Propose on testnets

Copy and paste one of the following commands to propose your deployment with the DevOps Platform.

Expand All @@ -137,7 +121,7 @@ Here are the steps that occur when you run this command:

When the proposal is finished, go to the [Sphinx UI](https://sphinx.dev) to approve the deployment. After you approve it, you can monitor the deployment's status in the UI while it's executed.

## 8. Next steps
## 7. Next steps

Congrats, you've finished your first deployment with Sphinx!

Expand Down
26 changes: 20 additions & 6 deletions packages/plugins/src/cli/install/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { execSync } from 'child_process'

import { CONTRACTS_LIBRARY_VERSION } from '@sphinx-labs/contracts'
import { spawnAsync } from '@sphinx-labs/core'
import { spawnAsync, userConfirmation } from '@sphinx-labs/core'
import ora from 'ora'

const installWithUpdate = async () => {
import { sphinxUp } from './sphinxup'

const installWithUpdate = async (spinner: ora.Ora, skipLibrary: boolean) => {
await userConfirmation(
'Would you like to install the Sphinx Foundry fork? This is required to use Sphinx and will replace your existing foundry instllation.\nConfirm? (y\\n):'
)
execSync(sphinxUp, { stdio: 'inherit' })

if (skipLibrary) {
return
}

spinner.start('Installing Sphinx Solidity library...')

const args = [
'install',
`sphinx-labs/sphinx@${CONTRACTS_LIBRARY_VERSION}`,
Expand Down Expand Up @@ -69,10 +82,11 @@ const installWithUpdate = async () => {
}
}

export const handleInstall = async (spinner: ora.Ora) => {
spinner.start('Installing Sphinx Solidity library...')

await installWithUpdate()
export const handleInstall = async (spinner: ora.Ora, skipLibrary: boolean) => {
await installWithUpdate(spinner, skipLibrary)
if (skipLibrary) {
return
}

// Foundry doesn't consistently install our subdependency, so we make sure it's installed ourselves.
// We should test this out later and remove if possible.
Expand Down
Loading

0 comments on commit 52e2f59

Please sign in to comment.