Skip to content

Commit

Permalink
add initial local dev env for builder
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityblast committed Oct 25, 2023
1 parent 4947edc commit f8ca862
Show file tree
Hide file tree
Showing 12 changed files with 789 additions and 219 deletions.
58 changes: 58 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: '3.8'

# Ports
# Builder: 3000
# Explorer: 3001
# Manager: 3002
# Pinata: 3003
# Indexer: 3004
# Dev chain 1: 3005
# Subgraph dev chain 1: 3006
# Dev chain 2: 3007
# Subgraph dev chain 2: 3008

services:
pinata:
image: ghcr.io/gitcoinco/pina:init
ports:
- '127.0.0.1:3003:8000'

localchain-1:
image: ghcr.io/gitcoinco/allo-contracts-v1:pr-1
ports:
- '127.0.0.1:3005:8545'
environment:
- DEV_CHAIN_ID=313371

localchain-1-init:
image: ghcr.io/gitcoinco/allo-contracts-v1:pr-1
depends_on:
- pinata
- localchain-1
environment:
- PINATA_HOST=pinata
- PINATA_PORT=8000
- DEV_CHAIN_HOST=localchain-1
- DEV_CHAIN_ID=313371
restart: "no"
entrypoint: [ "bash", "-c", "sleep 2 && corepack enable && exec ./docker/deploy-contracts.sh"]

localchain-2:
image: ghcr.io/gitcoinco/allo-contracts-v1:pr-1
ports:
- '127.0.0.1:3007:8545'
environment:
- DEV_CHAIN_ID=313372

localchain-2-init:
image: ghcr.io/gitcoinco/allo-contracts-v1:pr-1
depends_on:
- pinata
- localchain-2
environment:
- PINATA_HOST=pinata
- PINATA_PORT=8000
- DEV_CHAIN_HOST=localchain-2
- DEV_CHAIN_ID=313372
restart: "no"
entrypoint: [ "bash", "-c", "sleep 2 && corepack enable && exec ./docker/deploy-contracts.sh"]
6 changes: 3 additions & 3 deletions packages/builder/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ REACT_APP_INFURA_ID=
REACT_APP_WALLETCONNECT_ID=
REACT_APP_WALLETCONNECT_PROJECT_ID=

# Get your credentials at https://www.pinata.cloud/
REACT_APP_PINATA_GATEWAY=
REACT_APP_PINATA_JWT=
REACT_APP_IPFS_BASE_URL=http://localhost:3003
REACT_APP_PINATA_BASE_URL=http://localhost:3003
REACT_APP_PINATA_JWT=development-token

# Get your own key at https://scorer.gitcoin.co
REACT_APP_PASSPORT_API_KEY=
Expand Down
3 changes: 2 additions & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"verify-env": "*",
"wagmi": "^0.12.19",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
"yup": "^0.32.11",
"zod": "^3.22.4"
},
"scripts": {
"start": "craco start",
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/components/base/ImageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function ImageInput({

// Fetch existing img path from Pinata for display
const pinataClient = new PinataClient();
const imgUrl = pinataClient.fileURL(ipfsCID);
const imgUrl = pinataClient.fileUrl(ipfsCID);

blobExistingImg(imgUrl);
return imgUrl;
Expand Down
8 changes: 8 additions & 0 deletions packages/builder/src/contracts/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const chains = {
424: "pgn",
4002: "fantomTestnet",
31337: "localhost",
313371: "dev1",
313372: "dev2",
58008: "pgnTestnet",
42161: "arbitrum",
421613: "arbitrumGoerli",
Expand All @@ -34,6 +36,12 @@ export type DeploymentAddressesMap = {
};

export const addresses: DeploymentAddressesMap = {
dev1: {
projectRegistry: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
},
dev2: {
projectRegistry: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
},
localhost: {
projectRegistry: "0x832c5391dc7931312CbdBc1046669c9c3A4A28d5",
},
Expand Down
50 changes: 28 additions & 22 deletions packages/builder/src/services/pinata.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
// eslint-disable-next-line
const JWT = process.env.REACT_APP_PINATA_JWT;
// eslint-disable-next-line
const GATEWAY = process.env.REACT_APP_PINATA_GATEWAY;
const PIN_JSON_TO_IPFS_URL = "https://api.pinata.cloud/pinning/pinJSONToIPFS";
const PIN_FILE_TO_IPFS_URL = "https://api.pinata.cloud/pinning/pinFileToIPFS";
import { z } from "zod";

export default class PinataClient {
private jwt: string;

private gateway: string;

private pinJSONToIPFSURL: string;
private pinataBaseUrl: string;

private pinFileToIPFSURL: string;
private pinJSONToIPFSUrl: string;

private pinFileToIPFSUrl: string;

constructor() {
if (JWT === undefined || GATEWAY === undefined) {
throw new Error(
"remember to set the REACT_APP_PINATA_JWT and REACT_APP_PINATA_GATEWAY env vars"
);
}
this.jwt = JWT!;
this.gateway = GATEWAY.replace(/\/$/, "");
this.pinJSONToIPFSURL = PIN_JSON_TO_IPFS_URL;
this.pinFileToIPFSURL = PIN_FILE_TO_IPFS_URL;
this.jwt = z
.string({
required_error: "REACT_APP_PINATA_JWT is required",
})
.parse(process.env.REACT_APP_PINATA_JWT);
this.gateway = z
.string({ required_error: "REACT_APP_IPFS_BASE_URL is required" })
.url()
.parse(process.env.REACT_APP_IPFS_BASE_URL)
.replace(/\/$/, "");
this.pinataBaseUrl = z
.string({ required_error: "REACT_APP_PINATA_BASE_URL" })
.url()
.parse(process.env.REACT_APP_PINATA_BASE_URL)
.replace(/\/$/, "");

this.pinJSONToIPFSUrl = `${this.pinataBaseUrl}/pinning/pinJSONToIPFS`;
this.pinFileToIPFSUrl = `${this.pinataBaseUrl}/pinning/pinFileToIPFS`;
}

fileURL(cid: string) {
fileUrl(cid: string) {
return `${this.gateway}/ipfs/${cid}`;
}

fetchText(cid: string) {
const url = this.fileURL(cid);
const url = this.fileUrl(cid);
return fetch(url).then((resp) => resp.text());
}

fetchJson(cid: string) {
const url = this.fileURL(cid);
const url = this.fileUrl(cid);
return fetch(url).then((resp) => resp.json());
}

Expand All @@ -60,7 +66,7 @@ export default class PinataClient {
pinataContent: object,
};

return fetch(this.pinJSONToIPFSURL, {
return fetch(this.pinJSONToIPFSUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -84,7 +90,7 @@ export default class PinataClient {
fd.append("pinataOptions", JSON.stringify(requestData.pinataOptions));
fd.append("pinataMetadata", JSON.stringify(requestData.pinataMetadata));

return fetch(this.pinFileToIPFSURL, {
return fetch(this.pinFileToIPFSUrl, {
method: "POST",
headers: {
Authorization: `Bearer ${this.jwt}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/utils/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getProjectImage = (
}

const pinataClient = new PinataClient();
return pinataClient.fileURL(img);
return pinataClient.fileUrl(img);
};

export const formatDateFromMs = (ts: number) => {
Expand Down
54 changes: 3 additions & 51 deletions packages/builder/src/utils/wagmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import {
optimism,
goerli,
arbitrumGoerli,
hardhat,
avalancheFuji as avalancheFujiChain,
avalanche as avalancheChain,
} from "wagmi/chains";
import { alchemyProvider } from "wagmi/providers/alchemy";
import { infuraProvider } from "wagmi/providers/infura";
import { publicProvider } from "wagmi/providers/public";
import PublicGoodsNetworkIcon from "common/src/icons/PublicGoodsNetwork.svg";
import { pgn, pgnTestnet, devChain1, devChain2 } from "common/src/chains";
import { polygon, polygonMumbai } from "@wagmi/core/chains";
import { FantomFTMLogo } from "../assets";

Expand Down Expand Up @@ -82,56 +81,7 @@ export const fantomTestnet: Chain = {
iconUrl: FantomFTMLogo,
};

export const pgn: Chain = {
id: 424,
name: "PGN",
network: "pgn",
iconUrl: PublicGoodsNetworkIcon,
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: { http: ["https://rpc.publicgoods.network"] },
public: { http: ["https://rpc.publicgoods.network"] },
},
blockExplorers: {
default: {
name: "pgnscan",
url: "https://explorer.publicgoods.network",
},
},
};

const chainsAvailable: Chain[] = [];
export const pgnTestnet: Chain = {
id: 58008,
name: "PGN Testnet",
network: "pgn testnet",
iconUrl: PublicGoodsNetworkIcon,
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: { http: ["https://sepolia.publicgoods.network"] },
public: { http: ["https://sepolia.publicgoods.network"] },
},
blockExplorers: {
default: {
name: "pgnscan",
url: "https://explorer.sepolia.publicgoods.network",
},
},
testnet: true,
};

// todo: fix for rpc issue is with hardhat local chain calling rpc
if (process.env.REACT_APP_LOCALCHAIN === "true") {
chainsAvailable.push(hardhat);
}

if (process.env.REACT_APP_ENV === "production") {
chainsAvailable.push(
Expand All @@ -145,6 +95,8 @@ if (process.env.REACT_APP_ENV === "production") {
);
} else {
chainsAvailable.push(
devChain1,
devChain2,
optimism,
goerli,
fantomTestnet,
Expand Down
6 changes: 6 additions & 0 deletions packages/builder/src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function shortAddress(address: string): string {
}

export const networkPrettyNames: { [key in ChainName]: string } = {
dev1: "Development 1",
dev2: "Development 2",
mainnet: "Mainnet",
goerli: "Goerli",
fantomTestnet: "Fantom Testnet",
Expand All @@ -46,6 +48,8 @@ export const networkPrettyNames: { [key in ChainName]: string } = {
};

export const networkIcon: { [key in ChainName]: string } = {
dev1: EthDiamondGlyph,
dev2: EthDiamondGlyph,
mainnet: EthDiamondGlyph,
goerli: EthDiamondGlyph,
fantomTestnet: FTMTestnet,
Expand All @@ -63,6 +67,8 @@ export const networkIcon: { [key in ChainName]: string } = {
};

export const payoutIcon: { [key in ChainName]: string } = {
dev1: WhiteEthIconFilledCircle,
dev2: WhiteEthIconFilledCircle,
mainnet: WhiteEthIconFilledCircle,
goerli: WhiteEthIconFilledCircle,
fantomTestnet: FTMTestnet,
Expand Down
46 changes: 46 additions & 0 deletions packages/common/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum ChainId {
FUJI = 43113,
POLYGON = 137,
POLYGON_MUMBAI = 80001,
DEV = 313371,
}

export const pgnTestnet: Chain = {
Expand Down Expand Up @@ -90,3 +91,48 @@ export function parseChainId(input: string | number): ChainId {
// If the input is not a valid enum value, return undefined
throw "Invalid chainId " + input;
}

export const devChain1: Chain = {
id: 313371,
name: "Development 1",
network: "dev1",
iconUrl: PublicGoodsNetworkIcon,
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: { http: ["http://localhost:3005"] },
public: { http: ["http://localhost:3005"] },
},
blockExplorers: {
default: {
name: "dev1",
url: "",
},
},
};

export const devChain2: Chain = {
id: 313372,
name: "Development 2",
network: "dev2",
iconUrl: PublicGoodsNetworkIcon,
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: { http: ["http://localhost:3007"] },
public: { http: ["http://localhost:3007"] },
},
blockExplorers: {
default: {
name: "dev2",
url: "",
},
},
};
>>>>>>> 4612b889 (add initial local dev env for builder)
Loading

0 comments on commit f8ca862

Please sign in to comment.