Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #108

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.git
.github
.husky
.openzeppelin*
.upgradable
.vscode
52 changes: 26 additions & 26 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ on:
branches:
- "**"
jobs:
tests:
concurrency: ci-contract-${{ github.head_ref || github.run_id }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
# tests:
# concurrency: ci-contract-${{ github.head_ref || github.run_id }}
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# with:
# fetch-depth: 1

- uses: pnpm/action-setup@v2
with:
version: 8
# - uses: pnpm/action-setup@v2
# with:
# version: 8

- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'pnpm'
# - uses: actions/setup-node@v3
# with:
# node-version: '16'
# cache: 'pnpm'

- name: Install dependencies
run: |
pnpm install
# - name: Install dependencies
# run: |
# pnpm install

- name: Compile contract
run: |
pnpm compile
# - name: Compile contract
# run: |
# pnpm compile

- name: Test contract
env:
FORK_RPC_URL: ${{ secrets.FORK_RPC_URL }}
run: |
pnpm test
# - name: Test contract
# env:
# FORK_RPC_URL: ${{ secrets.FORK_RPC_URL }}
# run: |
# pnpm test

# slither:
# runs-on: ubuntu-latest
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Create and publish a Docker image

on:
push:
branches:
- '**'
pull_request:
branches:
- "**"


env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}


- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64

42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM node:20-slim as base
RUN apt-get update && \
apt-get install -y python3 curl git build-essential psmisc && \
apt-get clean

COPY . /app
WORKDIR /app


# Check when foundry supports dumping events
# https://github.com/foundry-rs/foundry/issues/5906
RUN curl -L https://foundry.paradigm.xyz | bash

RUN ~/.foundry/bin/foundryup

ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable
RUN pnpm install

FROM node:16-bullseye-slim as prod
RUN apt-get update && \
apt-get install -y curl git && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*

COPY . /app
WORKDIR /app

COPY --from=base /app/node_modules /app/node_modules
COPY --from=base /root/.foundry/bin/anvil /root/.foundry/bin/anvil

ENV DEV_CHAIN_ID=313371
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

RUN pnpm hardhat compile

EXPOSE 8545/tcp

ENTRYPOINT ./docker/start-chain.sh
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: docker-build docker-run docker-kill docker-stop docker-logs docker-deploy-contracts docker-all

IMAGE_NAME=allo
CONTAINER_NAME=allo

docker-all: docker-kill docker-build docker-run docker-deploy-contracts

docker-build:
docker build . -t $(IMAGE_NAME) --no-cache --progress=plain

docker-run:
docker run --name $(CONTAINER_NAME) --rm -d -p 127.0.0.1:8545:8545/tcp $(IMAGE_NAME)

docker-kill:
-docker kill $(CONTAINER_NAME)

docker-stop:
docker stop $(CONTAINER_NAME)

docker-logs:
docker logs -f $(CONTAINER_NAME)

docker-deploy-contracts:
docker exec allo bash ./docker/deploy-contracts.sh
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ To know the addresses are deployed on which network. refer [CHAINS.md](docs/CHAI

To contribute to this project, fork the project and follow the instructions at [DEV.md](docs/DEV.md)

You can run a local chain and deploy contracts using our docker configuration and tasks:

```
# Build the docker image with the project deps + anvil
make docker-build

# run a containerized chain with anvil
make docker-run

# deploy the contracts to the containerized chain
make docker-deploy-contracts
```

## Contract Documentation

The contract documentation has been generated using [primitive-dodoc](https://github.com/primitivefinance/primitive-dodoc) and can be found over at [docs/contracts](docs/contracts/)
35 changes: 35 additions & 0 deletions docker/deploy-contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export SKIP_CONFIRMATIONS=true

TIMEFORMAT='(🟢 %3R seconds)';

time pnpm run deploy-project-registry dev && \
time pnpm hardhat run scripts/dev/populate/projects.ts --network dev && \
\
time pnpm run deploy-program-factory dev && \
time pnpm run deploy-program-implementation dev && \
time pnpm run link-program-implementation dev && \
\
time pnpm run deploy-qf-factory dev && \
time pnpm run deploy-qf-implementation dev && \
time pnpm run link-qf-implementation dev && \
\
time pnpm run deploy-merkle-factory dev && \
time pnpm run deploy-merkle-implementation dev && \
time pnpm run link-merkle-implementation dev && \
\
time pnpm run deploy-direct-factory dev && \
time pnpm run deploy-direct-implementation dev && \
time pnpm run link-direct-implementation dev && \
\
time pnpm run deploy-allo-settings dev && \
time pnpm run set-protocol-fee dev && \
\
time pnpm run deploy-round-factory dev && \
time pnpm run deploy-round-implementation dev && \
time pnpm run link-round-implementation dev && \
time pnpm run link-allo-settings dev

# pnpm run create-program dev
# pnpm run create-qf-contract dev
# pnpm run create-merkle-contract dev
# pnpm run create-round dev
1 change: 1 addition & 0 deletions docker/start-chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
~/.foundry/bin/anvil --host 0.0.0.0 --chain-id $DEV_CHAIN_ID
29 changes: 23 additions & 6 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-solhint";
import "@nomiclabs/hardhat-waffle";
import "@openzeppelin/hardhat-upgrades";
import "@primitivefi/hardhat-dodoc";
import "@typechain/hardhat";
import "hardhat-abi-exporter";
import "hardhat-contract-sizer";
Expand All @@ -15,9 +14,19 @@ import "solidity-coverage";

dotenv.config();

function getEnvVarNumber(name: string, defaultValue: number): number {
const value = process.env[name];
if (value !== undefined) {
return parseInt(value);
}

return defaultValue;
}

const chainIds = {
// local
localhost: 31337,
dev: getEnvVarNumber("DEV_CHAIN_ID", 313371),
// testnet
goerli: 5,
"optimism-goerli": 420,
Expand Down Expand Up @@ -48,7 +57,7 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
});

let deployPrivateKey = process.env.DEPLOYER_PRIVATE_KEY as string;
if (!deployPrivateKey) {
if (deployPrivateKey === undefined) {
// default first account deterministically created by local nodes like `npx hardhat node` or `anvil`
deployPrivateKey =
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
Expand All @@ -65,13 +74,14 @@ const alchemyKey = process.env.ALCHEMY_API_KEY as string;
*/
function createTestnetConfig(
network: keyof typeof chainIds,
url?: string
url?: string,
mnemonic?: string
): NetworkUserConfig {
if (!url) {
if (url === undefined) {
url = `https://${network}.infura.io/v3/${infuraIdKey}`;
}
return {
accounts: [deployPrivateKey],
accounts: mnemonic ? { mnemonic } : [deployPrivateKey],
chainId: chainIds[network],
allowUnlimitedContractSize: true,
url,
Expand Down Expand Up @@ -196,6 +206,13 @@ const config: HardhatUserConfig = {
},

localhost: createTestnetConfig("localhost", "http://localhost:8545"),
// dev is still a local chain but it's based on our dev environment
// with hardcoded deterministic addresses for deployed contracts
dev: createTestnetConfig(
"dev",
`http://${process.env.DEV_CHAIN_HOST ?? "127.0.0.1"}:8545`,
"test test test test test test test test test test test junk"
),
hardhat: {
forking: {
url: `${process.env.FORK_RPC_URL}`,
Expand Down Expand Up @@ -295,4 +312,4 @@ const config: HardhatUserConfig = {
dodoc: dodoc,
};

export default config;
export default config;
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"deploy-allo-settings": "pnpm hardhat run scripts/settings/deployAlloSettings.ts --network",
"set-protocol-fee": "pnpm hardhat run scripts/settings/setProtocolFeeDetails.ts --network",
"// project-registry-deploy-scripts": "echo '//-- Project Registry deploy Script --//'",
"deploy-project-registry": "yarn hardhat run scripts/projectRegistry/deployProjectRegistry.ts --network",
"upgrade-project-registry": "yarn hardhat run scripts/projectRegistry/upgradeProjectRegistry.ts --network",
"deploy-project-registry": "hardhat run scripts/projectRegistry/deployProjectRegistry.ts --network",
"upgrade-project-registry": "hardhat run scripts/projectRegistry/upgradeProjectRegistry.ts --network",
"// progam-deploy-scripts": "echo '//-- Program deploy Script --//'",
"deploy-program-factory": "pnpm hardhat run scripts/program/deployProgramFactory.ts --network",
"deploy-program-implementation": "pnpm hardhat run scripts/program/deployProgramImplementation.ts --network",
Expand Down Expand Up @@ -61,6 +61,11 @@
"link-direct-implementation": "pnpm hardhat run scripts/payoutStrategy/direct/linkDirectPayoutStrategyImplementation.ts --network",
"create-direct-contract": "pnpm hardhat run scripts/payoutStrategy/direct/createDirectPayoutStrategy.ts --network"
},
"pnpm": {
"overrides": {
"node-hid": "^2"
}
},
"devDependencies": {
"@ethersproject/constants": "^5.7.0",
"@gnosis.pm/safe-contracts": "^1.3.0",
Expand All @@ -73,7 +78,7 @@
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-solhint": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.5",
"@openzeppelin/hardhat-upgrades": "^1.22.1",
"@openzeppelin/hardhat-upgrades": "^1.28.0",
"@primitivefi/hardhat-dodoc": "^0.2.3",
"@typechain/ethers-v5": "^7.2.0",
"@typechain/hardhat": "^2.3.1",
Expand Down
Loading
Loading