Skip to content

Commit

Permalink
Merge pull request #114 from liquity/dev-instructions
Browse files Browse the repository at this point in the history
README: Add development instructions

Also:

- Makes the second parameter of deployment-artifacts-to-app-env.ts optional and emit on stdout when missing, so that people can use the script to copy & paste into their env file easily.
- In the .env example file, make the hardhat env the default (one less thing to do for contributors).
  • Loading branch information
bpierre authored Apr 13, 2024
2 parents db6c99d + ee3960b commit 74a2791
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 20 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# BOLD
# Liquity v2

## Requirements

- [Node.js](https://nodejs.org/)
- [pnpm](https://pnpm.io/)
- [Foundry](https://book.getfoundry.sh/getting-started/installation)

## Setup

```sh
git clone git@github.com:liquity/bold.git
cd bold
pnpm install
```

## How to develop

```sh
# Run the anvil local node (keep it running in a separate terminal):
anvil

# First, the contracts:
cd contracts

# Build & deploy the contracts:
./deploy local --open-demo-troves # optionally open troves for the first 8 anvil accounts

# Print the addresses of the deployed contracts:
pnpm tsx utils/deployment-artifacts-to-app-env.ts deployment-context-latest.json

# We are now ready to pass the deployed contracts to the app:
cd ../frontend

# Copy the example .env file:
cp .env .env.local

# Edit the .env.local file:
# - Make sure the Hardhat / Anvil section is uncommented.
# - Copy into it the addresses printed by command above.

# Run the app development server:
pnpm dev

# You can now open https://localhost:3000 in your browser.
```
25 changes: 19 additions & 6 deletions contracts/utils/deployment-artifacts-to-app-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import { z } from "zod";
import { argv, echo, fs } from "zx";

const HELP = `
converts the deployment artifacts created by ./deploy into environment
variables to be used by the Next.js app located in frontend/.
Converts the deployment artifacts created by ./deploy into environment variables
to be used by the Next.js app located in frontend/.
Usage:
./deployment-artifacts-to-app-env.ts <INPUT_JSON> <OUTPUT_ENV> [OPTIONS]
./deployment-artifacts-to-app-env.ts <INPUT_JSON> [OUTPUT_ENV] [OPTIONS]
Arguments:
INPUT_JSON Path to the deployment artifacts
JSON file.
OUTPUT_ENV Path to the environment variables
file to write. If not provided, it
writes to stdout.
Options:
--help, -h Show this help message.
--append Append to the output file instead of overwriting it.
--append Append to the output file instead of
overwriting it (requires OUTPUT_ENV).
`;

const ZAddress = z.string().regex(/^0x[0-9a-fA-F]{40}$/);
Expand All @@ -35,8 +43,8 @@ export async function main() {
process.exit(0);
}

if (!options.inputJsonPath || !options.outputEnvPath) {
console.error("\nInvalid number of arguments provided (--help for instructions).\n");
if (!options.inputJsonPath) {
console.error("\nPlease provide the path to the deployment artifacts JSON file.\n");
process.exit(1);
}

Expand All @@ -48,6 +56,11 @@ export async function main() {
deployedContractsToAppEnvVariables(deployedContracts),
);

if (!options.outputEnvPath) {
console.log(outputEnv);
process.exit(0);
}

await fs.ensureFile(options.outputEnvPath);
if (options.append) {
await fs.appendFile(options.outputEnvPath, `\n${outputEnv}\n`);
Expand Down
26 changes: 13 additions & 13 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=1

# Ethereum
NEXT_PUBLIC_CHAIN_ID=1
NEXT_PUBLIC_CHAIN_NAME=Ethereum
NEXT_PUBLIC_CHAIN_CURRENCY=Ether|ETH|18
NEXT_PUBLIC_CHAIN_RPC_URL=https://cloudflare-eth.com
NEXT_PUBLIC_CHAIN_BLOCK_EXPLORER=Etherscan|https://etherscan.io
NEXT_PUBLIC_CHAIN_CONTRACT_ENS_REGISTRY=0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
NEXT_PUBLIC_CHAIN_CONTRACT_ENS_RESOLVER=0xce01f8eee7E479C928F8919abD53E553a36CeF67|19258213
NEXT_PUBLIC_CHAIN_CONTRACT_MULTICALL=0xca11bde05977b3631167028862be2a173976ca11|14353601

# Hardhat
# NEXT_PUBLIC_CHAIN_ID=31337
# NEXT_PUBLIC_CHAIN_NAME=Hardhat
# NEXT_PUBLIC_CHAIN_ID=1
# NEXT_PUBLIC_CHAIN_NAME=Ethereum
# NEXT_PUBLIC_CHAIN_CURRENCY=Ether|ETH|18
# NEXT_PUBLIC_CHAIN_RPC_URL=http://127.0.0.1:8545
# NEXT_PUBLIC_CHAIN_RPC_URL=https://cloudflare-eth.com
# NEXT_PUBLIC_CHAIN_BLOCK_EXPLORER=Etherscan|https://etherscan.io
# NEXT_PUBLIC_CHAIN_CONTRACT_ENS_REGISTRY=0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
# NEXT_PUBLIC_CHAIN_CONTRACT_ENS_RESOLVER=0xce01f8eee7E479C928F8919abD53E553a36CeF67|19258213
# NEXT_PUBLIC_CHAIN_CONTRACT_MULTICALL=0xca11bde05977b3631167028862be2a173976ca11|14353601

# Hardhat / Anvil
NEXT_PUBLIC_CHAIN_ID=31337
NEXT_PUBLIC_CHAIN_NAME=Hardhat
NEXT_PUBLIC_CHAIN_CURRENCY=Ether|ETH|18
NEXT_PUBLIC_CHAIN_RPC_URL=http://127.0.0.1:8545

# Liquity Testnet
# NEXT_PUBLIC_CHAIN_ID=1337
Expand Down

0 comments on commit 74a2791

Please sign in to comment.