From 3eaf20877b22759496b16ca8c145c08c6daad7b9 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 11 Aug 2023 12:21:10 +0530 Subject: [PATCH] Add deployment scripts for sushiswap contracts --- .../docker-compose-contract-sushiswap.yml | 33 ++++++++++++- .../deploy-core-contracts.sh | 34 ++++++++++++++ .../deploy-periphery-contracts.sh | 47 +++++++++++++++++++ .../contract-sushiswap/deployment-params.env | 11 +++++ .../cerc-sushiswap-v3-core/Dockerfile | 2 +- .../cerc-sushiswap-v3-periphery/Dockerfile | 2 +- 6 files changed, 125 insertions(+), 4 deletions(-) create mode 100755 app/data/config/contract-sushiswap/deploy-core-contracts.sh create mode 100755 app/data/config/contract-sushiswap/deploy-periphery-contracts.sh create mode 100644 app/data/config/contract-sushiswap/deployment-params.env diff --git a/app/data/compose/docker-compose-contract-sushiswap.yml b/app/data/compose/docker-compose-contract-sushiswap.yml index aad5c85a..f56e98cc 100644 --- a/app/data/compose/docker-compose-contract-sushiswap.yml +++ b/app/data/compose/docker-compose-contract-sushiswap.yml @@ -5,10 +5,39 @@ services: sushiswap-v3-core: image: cerc/sushiswap-v3-core:local env_file: - - ../config/watcher-sushiswap/lotus-params.env + - ../config/contract-sushiswap/deployment-params.env + environment: + ETH_RPC_ENDPOINT: ${ETH_RPC_ENDPOINT} + CHAIN_ID: ${CHAIN_ID} + ACCOUNT_PRIVATE_KEY: ${ACCOUNT_PRIVATE_KEY} + DEPLOY: ${DEPLOY} + volumes: + - ../config/network/wait-for-it.sh:/app/wait-for-it.sh + - ../config/contract-sushiswap/deploy-core-contracts.sh:/app/deploy-core-contracts.sh + - sushiswap_core_deployment:/app/deployments/docker + command: ["bash", "-c", "/app/deploy-core-contracts.sh && tail -f"] + extra_hosts: + - "host.docker.internal:host-gateway" # Deploys the periphery (NFPM, token, etc.) contracts sushiswap-v3-periphery: image: cerc/sushiswap-v3-periphery:local env_file: - - ../config/watcher-sushiswap/lotus-params.env + - ../config/contract-sushiswap/deployment-params.env + environment: + ETH_RPC_ENDPOINT: ${ETH_RPC_ENDPOINT} + CHAIN_ID: ${CHAIN_ID} + ACCOUNT_PRIVATE_KEY: ${ACCOUNT_PRIVATE_KEY} + DEPLOY: ${DEPLOY} + volumes: + - ../config/network/wait-for-it.sh:/app/wait-for-it.sh + - ../config/contract-sushiswap/deploy-periphery-contracts.sh:/app/deploy-periphery-contracts.sh + - sushiswap_core_deployment:/app/core-deployments/docker + - sushiswap_periphery_deployment:/app/deployments/docker + command: ["bash", "-c", "/app/deploy-periphery-contracts.sh && tail -f"] + extra_hosts: + - "host.docker.internal:host-gateway" + +volumes: + sushiswap_core_deployment: + sushiswap_periphery_deployment: diff --git a/app/data/config/contract-sushiswap/deploy-core-contracts.sh b/app/data/config/contract-sushiswap/deploy-core-contracts.sh new file mode 100755 index 00000000..707e7b38 --- /dev/null +++ b/app/data/config/contract-sushiswap/deploy-core-contracts.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +# Chain config +ETH_RPC_ENDPOINT="${ETH_RPC_ENDPOINT:-${DEFAULT_ETH_RPC_ENDPOINT}}" +CHAIN_ID="${CHAIN_ID:-${DEFAULT_CHAIN_ID}}" +ACCOUNT_PRIVATE_KEY="${ACCOUNT_PRIVATE_KEY:-${DEFAULT_ACCOUNT_PRIVATE_KEY}}" + +# Option +DEPLOY="${DEPLOY:-${DEFAULT_DEPLOY}}" + +# Create a .env file +echo "ETH_RPC_ENDPOINT=$ETH_RPC_ENDPOINT" > .env +echo "CHAIN_ID=$CHAIN_ID" >> .env +echo "ACCOUNT_PRIVATE_KEY=$ACCOUNT_PRIVATE_KEY" >> .env + +echo "Using RPC endpoint ${ETH_RPC_ENDPOINT}" + +# Wait for the RPC endpoint to be up +endpoint=${ETH_RPC_ENDPOINT#http://} +endpoint=${endpoint#https://} +RPC_HOST=$(echo "$endpoint" | awk -F'[:/]' '{print $1}') +RPC_PORT=$(echo "$endpoint" | awk -F'[:/]' '{print $2}') +./wait-for-it.sh -h "${RPC_HOST}" -p "${RPC_PORT}" -s -t 0 + +if [ "$DEPLOY" ]; then + echo "Performing core contract deployments..." + pnpm hardhat --network docker deploy --tags UniswapV3Factory +else + echo "Skipping contract deployments" +fi + +echo "Done" diff --git a/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh b/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh new file mode 100755 index 00000000..fc423251 --- /dev/null +++ b/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +# Chain config +ETH_RPC_ENDPOINT="${ETH_RPC_ENDPOINT:-${DEFAULT_ETH_RPC_ENDPOINT}}" +CHAIN_ID="${CHAIN_ID:-${DEFAULT_CHAIN_ID}}" +ACCOUNT_PRIVATE_KEY="${ACCOUNT_PRIVATE_KEY:-${DEFAULT_ACCOUNT_PRIVATE_KEY}}" + +# Option +DEPLOY="${DEPLOY:-${DEFAULT_DEPLOY}}" + +# Create a .env file +echo "ETH_RPC_ENDPOINT=$ETH_RPC_ENDPOINT" > .env +echo "CHAIN_ID=$CHAIN_ID" >> .env +echo "ACCOUNT_PRIVATE_KEY=$ACCOUNT_PRIVATE_KEY" >> .env + + +echo "Using RPC endpoint $ETH_RPC_ENDPOINT" + +# Wait for the RPC endpoint to be up +endpoint=${ETH_RPC_ENDPOINT#http://} +endpoint=${endpoint#https://} +RPC_HOST=$(echo "$endpoint" | awk -F'[:/]' '{print $1}') +RPC_PORT=$(echo "$endpoint" | awk -F'[:/]' '{print $2}') +./wait-for-it.sh -h "${RPC_HOST}" -p "${RPC_PORT}" -s -t 0 + +if [ "$DEPLOY" ]; then + # Loop until the factory deployment is detected + echo "Waiting for core deployments to occur" + while [ ! -f /app/core-deployments/docker/UniswapV3Factory.json ]; do + sleep 5 + done + + echo "Reading factory address from core deployments" + FACTORY_ADDRESS=$(jq -r '.address' /app/core-deployments/docker/UniswapV3Factory.json) + + echo "Using UniswapV3Factory at $FACTORY_ADDRESS" + echo "FACTORY_ADDRESS=$FACTORY_ADDRESS" >> .env + + echo "Performing periphery contract deployments..." + yarn hardhat --network docker deploy --tags NonfungiblePositionManager +else + echo "Skipping contract deployments" +fi + +echo "Done" diff --git a/app/data/config/contract-sushiswap/deployment-params.env b/app/data/config/contract-sushiswap/deployment-params.env new file mode 100644 index 00000000..f9854e88 --- /dev/null +++ b/app/data/config/contract-sushiswap/deployment-params.env @@ -0,0 +1,11 @@ +# Chain config + +DEFAULT_ETH_RPC_ENDPOINT="http://lotus-node-1:1234/rpc/v1" +DEFAULT_CHAIN_ID=31415926 + +# From app/data/config/fixturenet-lotus/fund-account.sh +DEFAULT_ACCOUNT_PRIVATE_KEY="0xc05fd3613bcd62a4f25e5eba1f464d0b76d74c3f771a7c2f13e26ad6439444b3" + +# Options + +DEFAULT_DEPLOY=true diff --git a/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile b/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile index 993897d4..8d85d602 100644 --- a/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile +++ b/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile @@ -1,6 +1,6 @@ FROM node:18.15.0-alpine3.16 -RUN apk --update --no-cache add git python3 alpine-sdk bash +RUN apk --update --no-cache add git python3 alpine-sdk bash jq RUN curl -L https://unpkg.com/@pnpm/self-installer | node WORKDIR /app diff --git a/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile b/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile index 4fcf712c..a033c39e 100644 --- a/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile +++ b/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile @@ -1,6 +1,6 @@ FROM node:18.15.0-alpine3.16 -RUN apk --update --no-cache add git python3 alpine-sdk bash +RUN apk --update --no-cache add git python3 alpine-sdk bash jq WORKDIR /app