Skip to content

Commit

Permalink
Feat: adding export of smart contract variables for cluster deployment (
Browse files Browse the repository at this point in the history
#242)

Co-authored-by: Ivan Vandot <[email protected]>
  • Loading branch information
0xCardinalError and vandot authored Apr 9, 2024
1 parent 4fdb26e commit 1bd03c0
Show file tree
Hide file tree
Showing 25 changed files with 1,740 additions and 2,157 deletions.
42 changes: 42 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# @nomiclabs/hardhat
cache/
artifacts/
dist/

# solidity-coverage
coverage*

# vscode
.vscode*

# Node
node_modules/
*/node_modules/

# Idea
.idea/
.idea/*

# Env
.env

# hardhat-deploy
deployments/hardhat
deployments/localhost
deployments/localcluster
deployedContracts.sh

# deployment files for mainnet and testnet and an example file
*_deployed.json
!mainnet_deployed.json
!testnet_deployed.json

# Misc
contractsInfo.json
.DS_Store

# Gas reports
gas-report.txt

# Tenderly
tenderly.log
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches:
- '**'
env:
NODEJS_VERSION: '16'
NODEJS_VERSION: '20'
jobs:
check:
runs-on: ubuntu-latest
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release

on:
push:
branches-ignore:
- '**'
tags:
- 'v*.*.*'

jobs:
docker_release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

- name: Docker Hub and Quay Login
run: |
printf ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
printf ${{ secrets.QUAY_PASSWORD }} | docker login --username ${{ secrets.QUAY_USERNAME }} quay.io --password-stdin
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ethersphere/bee-localchain
quay.io/ethersphere/bee-localchain
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64,arm

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

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ethersphere/bee-localchain:buildcache
cache-to: type=registry,ref=ethersphere/bee-localchain:buildcache,mode=max
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ node_modules/
# hardhat-deploy
deployments/hardhat
deployments/localhost
deployments/localcluster
deployedContracts.sh

# deployment files for mainnet and testnet and an example file
*_deployed.json
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "s3"]
path = s3
url = https://github.com/ethersphere/swap-swear-and-swindle.git
4 changes: 4 additions & 0 deletions deploy/local/001_deploy_postage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const { deploy, log, get } = deployments;
const { deployer } = await getNamedAccounts();

log('----------------------------------------------------');
log('Deployer address at ', deployer);
log('----------------------------------------------------');

const token = await get('TestToken');

const argsStamp = [token.address, 16];
Expand Down
46 changes: 46 additions & 0 deletions deploy/local/010_deploy_cluster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, ethers }) {
const { get, log, execute } = deployments;
const { deployer } = await getNamedAccounts();

// Access the BZZACCOUNTS environment variable
const bzzAccountsRaw = process.env.BZZACCOUNTS
? process.env.BZZACCOUNTS
: '0xbf4f9637c281ddfb1fbd3be5a1dae6531d408f11 0xc45d64d8f9642a604db93c59fd38492b262391ca';
const bzzAccounts = bzzAccountsRaw.split(' ');

// Transfer tokens to accounts used in cluster deployment
const amount = ethers.utils.parseUnits('10', 18); // "10" is the token amount; adjust the decimal accordingly
for (const account of bzzAccounts) {
await execute('TestToken', { from: deployer }, 'transfer', ethers.utils.getAddress(account), amount);
}

log(`Sent BZZ tokens to ` + bzzAccountsRaw);
log('----------------------------------------------------');

const Token = await get('TestToken');
const StakeRegistry = await get('StakeRegistry');
const PostageStamp = await get('PostageStamp');
const PriceOracle = await get('PriceOracle');
const Redistribution = await get('Redistribution');

// Generate content for the environment file
let content = '';

content += `echo "----- USE THE COMMANDS BELOW TO SETUP YOUR TERMINALS -----" >&2\n\n`;
content += `export BEE_TOKEN_ADDRESS=${Token.address}\n`;
content += `export BEE_POSTAGE_STAMP_ADDRESS=${PostageStamp.address}\n`;
content += `export BEE_INCENTIVES_PRICE_ORACLE_ADDRESS=${PriceOracle.address}\n`;
content += `export BEE_STAKING_ADDRESS=${StakeRegistry.address}\n`;
content += `export BEE_REDISTRIBUTION_ADDRESS=${Redistribution.address}\n`;

// Output the content to the terminal
log(content);
log(`Exported contract addresses to console`);

log('----------------------------------------------------');
};

export default func;
func.tags = ['variables'];
6 changes: 5 additions & 1 deletion deploy/main/000_deploy_token.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, ethers, network }) {
const func: DeployFunction = async function ({ deployments, getNamedAccounts }) {
const { log, get } = deployments;
const { deployer } = await getNamedAccounts();
let token = null;

log('----------------------------------------------------');
log('Deployer address at ', deployer);
log('----------------------------------------------------');

// We ONLY use already deployed token for MAINNET
if (!(token = await get('Token'))) {
// we have problem as there is not token, error out
Expand Down
7 changes: 6 additions & 1 deletion deploy/tenderly/000_deploy_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, ethers, network }) {
const func: DeployFunction = async function ({ deployments, getNamedAccounts }) {
const { log, get } = deployments;
const { deployer } = await getNamedAccounts();
let token = null;

log('----------------------------------------------------');
log('Deployer address at ', deployer);
log('----------------------------------------------------');

// We ONLY use already deployed token for MAINNET FORKS
if (!(token = await get('Token'))) {
// we have problem as there is not token, error out
Expand Down
4 changes: 4 additions & 0 deletions deploy/test/000_deploy_test_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const func: DeployFunction = async function ({ deployments, getNamedAccounts, ne
const { deploy, log, getOrNull } = deployments;
const { deployer } = await getNamedAccounts();

log('----------------------------------------------------');
log('Deployer address at ', deployer);
log('----------------------------------------------------');

let token = null;

// We deploy new token if there is no token
Expand Down
30 changes: 30 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:20.11.1-alpine as build

ENV NODE_ENV=production

WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn install --prod --frozen-lockfile --verbose

COPY s3/package.json s3/yarn.lock ./s3/
RUN cd s3 && yarn install --prod --frozen-lockfile --verbose

COPY . ./
RUN yarn hardhat compile
RUN cd s3 && yarn hardhat compile

FROM node:20.11.1-alpine

ENV NODE_ENV=production
ENV WALLET_SECRET=4663c222787e30c1994b59044aa5045377a6e79193a8ead88293926b535c722d

RUN apk add --no-cache curl bash

WORKDIR /app

COPY --from=build /app .

RUN ln -s /app/docker/deploy.sh /app/deploy.sh

CMD ["sh", "-c", "/app/docker/deploy.sh"]
13 changes: 13 additions & 0 deletions docker/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env sh

set -x
while ! curl -m 1 http://geth-swap:8545; do sleep 1; done
echo connected to geth >&2
sleep 2

npx hardhat deploy --network localcluster

cd ./s3
npx hardhat deploy --network localcluster

echo deployed
26 changes: 17 additions & 9 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'dotenv/config';
import { HardhatUserConfig } from 'hardhat/types';
import 'solidity-coverage';
import 'hardhat-deploy';
import 'hardhat-deploy-ethers';
import 'hardhat-tracer';
import '@nomiclabs/hardhat-etherscan';
import '@nomicfoundation/hardhat-verify';
import 'hardhat-contract-sizer';
import 'hardhat-gas-reporter';
import 'solidity-coverage';
import { removeConsoleLog } from 'hardhat-preprocessor';
import './tasks';

Expand Down Expand Up @@ -43,7 +42,9 @@ const config: HardhatUserConfig = {
timeout: Number.MAX_SAFE_INTEGER,
},
preprocess: {
eachLine: removeConsoleLog((hre) => hre.network.name !== 'hardhat' && hre.network.name !== 'localhost'),
eachLine: removeConsoleLog(
(hre) => hre.network.name !== 'hardhat' && hre.network.name !== 'localhost' && hre.network.name !== 'localcluster'
),
},
namedAccounts: {
deployer: 0,
Expand All @@ -64,11 +65,12 @@ const config: HardhatUserConfig = {
defaultNetwork: 'hardhat',
networks: {
hardhat: {
chainId: 12345,
initialBaseFeePerGas: 0,
accounts: [
// deployer 0x3c8F39EE625fCF97cB6ee22bCe25BE1F1E5A5dE8
// deployer 0x62cab2b3b55f341f10348720ca18063cdb779ad5
{
privateKey: '0x0d8f0a76e88539c4ceaa6ad01372cce44fb621b56b34b2cc614b4c77fb081f20',
privateKey: '4663c222787e30c1994b59044aa5045377a6e79193a8ead88293926b535c722d',
balance: '10000000000000000000000',
},
// admin 0x7E71bA1aB8AF3454a01CFafe358BEbb7691d02f8
Expand Down Expand Up @@ -136,7 +138,7 @@ const config: HardhatUserConfig = {
privateKey: '0x9d715c14789abdc4c97fd775cf620196bebe991c60c614ba00fedbac943a5e67',
balance: '10000000000000000000000',
},
// other_1
// other_1 0x626178434A88c3c8809D136d500b9707D749EA9B
{
privateKey: 'f09baf4a06da707abeb96568a1419b4eec094774eaa85ef85517457ffe25b515',
balance: '10000000000000000000000',
Expand All @@ -147,12 +149,18 @@ const config: HardhatUserConfig = {
balance: '10000000000000000000000',
},
],
hardfork: 'merge',
deploy: ['deploy/local/'],
},
localhost: {
url: 'http://localhost:8545',
chainId: 31337,
// accounts, if not defined uses the same as above hardhat
chainId: 12345,
deploy: ['deploy/local/'],
},
localcluster: {
url: 'http://geth-swap:8545',
// accounts, if not defined uses the same as above hardhat
chainId: 12345,
deploy: ['deploy/local/'],
},
pretestnet: {
Expand Down
5 changes: 3 additions & 2 deletions helper-hardhat-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export interface networkConfigInfo {
}

export const networkConfig: networkConfigInfo = {
localhost: { swarmNetworkId: 0, multisig: '0x3c8F39EE625fCF97cB6ee22bCe25BE1F1E5A5dE8' },
hardhat: { swarmNetworkId: 0, multisig: '0x3c8F39EE625fCF97cB6ee22bCe25BE1F1E5A5dE8' },
localhost: { swarmNetworkId: 0, multisig: '0x62cab2b3b55f341f10348720ca18063cdb779ad5' },
hardhat: { swarmNetworkId: 0, multisig: '0x62cab2b3b55f341f10348720ca18063cdb779ad5' },
localcluster: { swarmNetworkId: 0, multisig: '0x62cab2b3b55f341f10348720ca18063cdb779ad5' },
pretestnet: {
blockConfirmations: 6,
swarmNetworkId: 333,
Expand Down
Loading

0 comments on commit 1bd03c0

Please sign in to comment.