Skip to content

Commit

Permalink
Add zksync mainnet & testnet support (#2726)
Browse files Browse the repository at this point in the history
* feat: add zksync mainnet & testnet support

* fix: build issues

* fix: build issues

* wip: test era-testnet

* wip: mainnet contract

* wip: mainnet contract

* feat: add usdt and other tokens

* fix: build issues

* chore: fix builder

* chore: update ChainId

* chore: update .env.test

* fix: build issues

* fix: build issues

* chore: fix issues

* fix: failing test

* upgrade custom lit sdk version

* rename lit chain for zksync and upgrade lit js version

* feat: add chainIdToChainName

* fix: build issues

* chore: address engg feedback

* update lit version in manager

* upgrade lit version

* chore: update payoutTokens

* feat: add mrc contract for zksync

* chore: fix usdt logo

---------

Co-authored-by: Aditya Anand M C <[email protected]>
Co-authored-by: Andrea Franz <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2023
1 parent a39f457 commit 793aee9
Show file tree
Hide file tree
Showing 34 changed files with 471 additions and 80 deletions.
2 changes: 2 additions & 0 deletions packages/builder/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ REACT_APP_SUBGRAPH_PGN_API="https://graph-gitcoin-mainnet.hirenodes.io/subgraphs
REACT_APP_SUBGRAPH_PGN_TESTNET_API="https://graph-gitcoin-testnet.hirenodes.io/subgraphs/name/gitcoin/allo"
REACT_APP_SUBGRAPH_POLYGON_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-polygon"
REACT_APP_SUBGRAPH_POLYGON_MUMBAI_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-mumbai"
REACT_APP_SUBGRAPH_ZKSYNC_TESTNET_API="https://api.thegraph.com/subgraphs/name/gitcoinco/grants-round-zkync-era-testnet"
REACT_APP_SUBGRAPH_ZKSYNC_MAINNET_API="https://api.studio.thegraph.com/query/45391/grants-round-zkera/v0.0.2"

# Variables below are optional for local development
REACT_APP_DATADOG_APPLICATION_ID=
Expand Down
2 changes: 2 additions & 0 deletions packages/builder/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ REACT_APP_SUBGRAPH_PGN_API="https://graph-gitcoin-mainnet.hirenodes.io/subgraphs
REACT_APP_SUBGRAPH_PGN_TESTNET_API="https://graph-gitcoin-testnet.hirenodes.io/subgraphs/name/gitcoin/allo"
REACT_APP_SUBGRAPH_POLYGON_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-polygon"
REACT_APP_SUBGRAPH_POLYGON_MUMBAI_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-mumbai"
REACT_APP_SUBGRAPH_ZKSYNC_TESTNET_API="https://api.thegraph.com/subgraphs/name/gitcoinco/grants-round-zkync-era-testnet"
REACT_APP_SUBGRAPH_ZKSYNC_MAINNET_API="https://api.studio.thegraph.com/query/45391/grants-round-zkera/v0.0.2"
REACT_APP_GRANTS_STACK_SEARCH_API_BASE_URL="https://gitcoin-search-dev.fly.dev"

REACT_APP_PINATA_GATEWAY="https://pinata-gateway.com"
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dompurify": "^2.4.3",
"ethers": "^5.7.2",
"framer-motion": "^6",
"gitcoin-lit-js-sdk": "^1.2.2",
"gitcoin-lit-js-sdk": "^1.2.6",
"history": "^5.3.0",
"https-browserify": "^1.0.0",
"jest": "^27.0",
Expand Down
30 changes: 16 additions & 14 deletions packages/builder/src/actions/roundApplication.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { datadogLogs } from "@datadog/browser-logs";
import { datadogRum } from "@datadog/browser-rum";
import { ChainId } from "common";
import { ChainId, isJestRunning } from "common";
import { ethers } from "ethers";
import { Dispatch } from "redux";
import { getConfig } from "common/src/config";
import RoundABI from "../contracts/abis/RoundImplementation.json";
import { chains } from "../contracts/deployments";
import { global } from "../global";
import { RootState } from "../reducers";
import { Status } from "../reducers/roundApplication";
Expand All @@ -19,6 +18,8 @@ import { getProjectURIComponents, metadataToProject } from "../utils/utils";
import { fetchProjectApplications } from "./projects";
import { graphqlFetch } from "../utils/graphql";

const LitJsSdk = isJestRunning() ? null : require("gitcoin-lit-js-sdk");

// FIXME: rename to ROUND_APPLICATION_APPLYING
export const ROUND_APPLICATION_LOADING = "ROUND_APPLICATION_LOADING";
interface RoundApplicationLoadingAction {
Expand Down Expand Up @@ -132,6 +133,17 @@ const dispatchAndLogApplicationError = (
dispatch(applicationError(roundAddress, error, step));
};

export function chainIdToChainName(chainId: number): string {
// eslint-disable-next-line no-restricted-syntax
for (const name in LitJsSdk.LIT_CHAINS) {
if (LitJsSdk.LIT_CHAINS[name].chainId === chainId) {
return name;
}
}

throw new Error(`couldn't find LIT chain name for chainId ${chainId}`);
}

export const submitApplication =
(roundAddress: string, formInputs: RoundApplicationAnswers) =>
async (dispatch: Dispatch, getState: () => RootState) => {
Expand Down Expand Up @@ -211,7 +223,7 @@ export const submitApplication =
);
return;
}
const chainName = chains[chainID];
const chainName = chainIdToChainName(chainID);

dispatch({
type: ROUND_APPLICATION_LOADING,
Expand All @@ -222,23 +234,13 @@ export const submitApplication =
let application: RoundApplication;
let deterministicApplication: string;

let chain: string = "";

if (chainName === "mainnet") {
chain = "ethereum";
} else if (chainName === "pgn") {
chain = "publicGoodsNetwork";
} else {
chain = chainName;
}

try {
const builder = new RoundApplicationBuilder(
true,
project,
roundApplicationMetadata,
roundAddress,
chain
chainName
);

application = await builder.build(roundAddress, formInputs);
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 @@ -4,6 +4,8 @@ export const chains = {
1: "mainnet",
10: "optimism",
250: "fantom",
280: "zkSyncEraTestnet",
324: "zkSyncEraMainnet",
424: "pgn",
4002: "fantomTestnet",
31337: "localhost",
Expand Down Expand Up @@ -80,6 +82,12 @@ export const addresses: DeploymentAddressesMap = {
polygonMumbai: {
projectRegistry: "0x545B282A50EaeA01A619914d44105437036CbB36",
},
zkSyncEraMainnet: {
projectRegistry: "0xe6CCEe93c97E20644431647B306F48e278aFFdb9",
},
zkSyncEraTestnet: {
projectRegistry: "0xb0F4882184EB6e3ed120c5181651D50719329788",
},
};

export const addressesByChainID = (chainId: ChainId): DeploymentAddresses => {
Expand Down
7 changes: 7 additions & 0 deletions packages/builder/src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { publicProvider } from "wagmi/providers/public";
import {
pgn,
pgnTestnet,
zkSyncEraMainnet,
zkSyncEraTestnet,
devChain1,
devChain2,
avalanche,
Expand Down Expand Up @@ -34,6 +36,8 @@ const availableChains: { [key: string]: Chain } = {
arbitrumGoerli,
polygonMumbai,
avalancheFuji,
zkSyncEraMainnet,
zkSyncEraTestnet,
};

const stagingChains = [
Expand All @@ -51,6 +55,8 @@ const stagingChains = [
polygonMumbai,
avalanche,
avalancheFuji,
zkSyncEraMainnet,
zkSyncEraTestnet,
];

const productionChains = [
Expand All @@ -61,6 +67,7 @@ const productionChains = [
arbitrum,
avalanche,
customPolygon,
zkSyncEraMainnet,
];

export function getEnabledChainsAndProviders() {
Expand Down
7 changes: 7 additions & 0 deletions packages/builder/src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ethers } from "ethers";
import PGNIcon from "common/src/icons/PublicGoodsNetwork.svg";
import AVAXIcon from "common/src/icons/AVAX.svg";
import POLIcon from "common/src/icons/pol-logo.svg";
import ZkSyncIcon from "common/src/icons/zksync-logo.svg";
import FantomFTMLogo from "common/src/assets/fantom-ftm-logo.png";
import {
EthDiamondGlyph,
Expand Down Expand Up @@ -44,6 +45,8 @@ export const networkPrettyNames: { [key in ChainName]: string } = {
fuji: "Fuji (Avalanche Testnet)",
polygon: "Polygon PoS",
polygonMumbai: "Polygon Mumbai",
zkSyncEraMainnet: "zkSync Era Mainnet",
zkSyncEraTestnet: "zkSync Era Testnet",
};

export const networkIcon: { [key in ChainName]: string } = {
Expand All @@ -62,6 +65,8 @@ export const networkIcon: { [key in ChainName]: string } = {
fuji: AVAXIcon,
polygon: POLIcon,
polygonMumbai: POLIcon,
zkSyncEraMainnet: ZkSyncIcon,
zkSyncEraTestnet: ZkSyncIcon,
};

export const payoutIcon: { [key in ChainName]: string } = {
Expand All @@ -80,6 +85,8 @@ export const payoutIcon: { [key in ChainName]: string } = {
polygonMumbai: POLIcon,
avalanche: AVAXIcon,
fuji: AVAXIcon,
zkSyncEraMainnet: ZkSyncIcon,
zkSyncEraTestnet: ZkSyncIcon,
};

export function getNetworkIcon(chainId: ChainId): string {
Expand Down
2 changes: 2 additions & 0 deletions packages/common/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ REACT_APP_SUBGRAPH_PGN_API="https://graph-gitcoin-mainnet.hirenodes.io/subgraphs
REACT_APP_SUBGRAPH_PGN_TESTNET_API="https://graph-gitcoin-testnet.hirenodes.io/subgraphs/name/gitcoin/allo"
REACT_APP_SUBGRAPH_POLYGON_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-polygon"
REACT_APP_SUBGRAPH_POLYGON_MUMBAI_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-mumbai"
REACT_APP_SUBGRAPH_ZKSYNC_TESTNET_API="https://api.thegraph.com/subgraphs/name/gitcoinco/grants-round-zkync-era-testnet"
REACT_APP_SUBGRAPH_ZKSYNC_MAINNET_API="https://api.studio.thegraph.com/query/45391/grants-round-zkera/v0.0.2"
REACT_APP_GRANTS_STACK_SEARCH_API_BASE_URL="https://gitcoin-search-dev.fly.dev"
2 changes: 2 additions & 0 deletions packages/common/src/chain-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export enum ChainId {
OPTIMISM_MAINNET_CHAIN_ID = 10,
FANTOM_MAINNET_CHAIN_ID = 250,
FANTOM_TESTNET_CHAIN_ID = 4002,
ZKSYNC_ERA_TESTNET_CHAIN_ID = 280,
ZKSYNC_ERA_MAINNET_CHAIN_ID = 324,
PGN = 424,
PGN_TESTNET = 58008,
ARBITRUM = 42161,
Expand Down
29 changes: 29 additions & 0 deletions packages/common/src/chains.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Chain } from "@rainbow-me/rainbowkit";
import PublicGoodsNetworkIcon from "./icons/PublicGoodsNetwork.svg";
import zkSyncIcon from "./icons/zksync-logo.svg";
import {
avalanche as avalancheOriginal,
avalancheFuji as avalancheFujiOriginal,
fantom as fantomOriginal,
fantomTestnet as fantomTestnetOriginal,
zkSyncTestnet as zkSyncTestnetOriginal,
zkSync as zkSyncOriginal,
} from "wagmi/chains";
import FantomFTMLogo from "./assets/fantom-ftm-logo.png";
import { ChainId } from "./chain-ids";
Expand Down Expand Up @@ -64,6 +67,32 @@ export const avalanche: Chain = {
},
};

export const zkSyncEraTestnet: Chain = {
...zkSyncTestnetOriginal,
iconUrl: zkSyncIcon,
rpcUrls: {
default: {
http: ["https://testnet.era.zksync.dev"],
},
public: {
http: ["https://testnet.era.zksync.dev"],
},
},
};

export const zkSyncEraMainnet: Chain = {
...zkSyncOriginal,
iconUrl: zkSyncIcon,
rpcUrls: {
default: {
http: ["https://mainnet.era.zksync.io"],
},
public: {
http: ["https://mainnet.era.zksync.io"],
},
},
};

export const pgnTestnet: Chain = {
id: 58008,
name: "PGN Testnet",
Expand Down
6 changes: 6 additions & 0 deletions packages/common/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export function getConfig(): Config {
[ChainId.POLYGON_MUMBAI]: z
.string()
.parse(process.env.REACT_APP_SUBGRAPH_POLYGON_MUMBAI_API),
[ChainId.ZKSYNC_ERA_TESTNET_CHAIN_ID]: z
.string()
.parse(process.env.REACT_APP_SUBGRAPH_ZKSYNC_TESTNET_API),
[ChainId.ZKSYNC_ERA_MAINNET_CHAIN_ID]: z
.string()
.parse(process.env.REACT_APP_SUBGRAPH_ZKSYNC_MAINNET_API),
},
},
pinata: {
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/icons/zksync-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export const graphQlEndpoints: Record<ChainId, string> = {
[ChainId.AVALANCHE]: process.env.REACT_APP_SUBGRAPH_AVALANCHE_API!,
[ChainId.POLYGON]: process.env.REACT_APP_SUBGRAPH_POLYGON_API!,
[ChainId.POLYGON_MUMBAI]: process.env.REACT_APP_SUBGRAPH_POLYGON_MUMBAI_API!,
[ChainId.ZKSYNC_ERA_TESTNET_CHAIN_ID]:
process.env.REACT_APP_SUBGRAPH_ZKSYNC_TESTNET_API!,
[ChainId.ZKSYNC_ERA_MAINNET_CHAIN_ID]:
process.env.REACT_APP_SUBGRAPH_ZKSYNC_MAINNET_API!,
};

/**
Expand Down Expand Up @@ -323,6 +327,9 @@ export const RedstoneTokenIds = {
MATIC: "MATIC",
AVAX: "AVAX",
CVP: "CVP",
USDT: "USDT",
LUSD: "LUSD",
MUTE: "MUTE",
} as const;

export const useTokenPrice = (tokenId: string | undefined) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/grant-explorer/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ REACT_APP_SUBGRAPH_PGN_API="https://graph-gitcoin-mainnet.hirenodes.io/subgraphs
REACT_APP_SUBGRAPH_PGN_TESTNET_API="https://graph-gitcoin-testnet.hirenodes.io/subgraphs/name/gitcoin/allo"
REACT_APP_SUBGRAPH_POLYGON_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-polygon"
REACT_APP_SUBGRAPH_POLYGON_MUMBAI_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-mumbai"
REACT_APP_SUBGRAPH_ZKSYNC_TESTNET_API="https://api.thegraph.com/subgraphs/name/gitcoinco/grants-round-zkync-era-testnet"
REACT_APP_SUBGRAPH_ZKSYNC_MAINNET_API="https://api.thegraph.com/subgraphs/name/gitcoinco/grants-round-zkync-era-mainnet"

# Variables below are optional for local development
REACT_APP_DATADOG_APPLICATION_ID=
Expand Down
2 changes: 2 additions & 0 deletions packages/grant-explorer/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ REACT_APP_SUBGRAPH_PGN_API="https://graph-gitcoin-mainnet.hirenodes.io/subgraphs
REACT_APP_SUBGRAPH_PGN_TESTNET_API="https://graph-gitcoin-testnet.hirenodes.io/subgraphs/name/gitcoin/allo"
REACT_APP_SUBGRAPH_POLYGON_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-polygon"
REACT_APP_SUBGRAPH_POLYGON_MUMBAI_API="https://api.thegraph.com/subgraphs/name/allo-protocol/grants-round-mumbai"
REACT_APP_SUBGRAPH_ZKSYNC_TESTNET_API="https://api.thegraph.com/subgraphs/name/gitcoinco/grants-round-zkync-era-testnet"
REACT_APP_SUBGRAPH_ZKSYNC_MAINNET_API="https://api.studio.thegraph.com/query/45391/grants-round-zkera/v0.0.2"
REACT_APP_GRANTS_STACK_SEARCH_API_BASE_URL="https://gitcoin-search-dev.fly.dev"
REACT_APP_ENV="test"
17 changes: 17 additions & 0 deletions packages/grant-explorer/public/logos/lusd-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

5 comments on commit 793aee9

@vercel
Copy link

@vercel vercel bot commented on 793aee9 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder – ./packages/builder

builder-grants-stack.vercel.app
builder.gitcoin.co
builder-kappa-one.vercel.app
builder-git-main-grants-stack.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 793aee9 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

manager-staging – ./packages/round-manager

manager-staging-grants-stack.vercel.app
grants-stack-manager-staging.vercel.app
manager-staging-git-main-grants-stack.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 793aee9 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

explorer-staging – ./packages/grant-explorer

grants-stack-explorer-staging.vercel.app
explorer-staging-grants-stack.vercel.app
explorer-staging-git-main-grants-stack.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 793aee9 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

manager – ./packages/round-manager

manager-git-main-grants-stack.vercel.app
grants-stack-round-manager.vercel.app
manager-grants-stack.vercel.app
manager.gitcoin.co

@vercel
Copy link

@vercel vercel bot commented on 793aee9 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-staging – ./packages/builder

builder-staging-grants-stack.vercel.app
builder-staging-git-main-grants-stack.vercel.app
grants-stack-builder-staging.vercel.app

Please sign in to comment.