Skip to content
Merged
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
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GroupResponse, SemaphoreEthers, SemaphoreSubgraph } from "@semaphore-protocol/data"
import { GroupResponse, SemaphoreEthers, SemaphoreSubgraph, getSupportedNetworks } from "@semaphore-protocol/data"
import chalk from "chalk"
import { program } from "commander"
import figlet from "figlet"
Expand All @@ -16,7 +16,7 @@ import Spinner from "./spinner.js"
const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`
const { description, version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"))

const supportedNetworks = ["sepolia", "goerli", "mumbai", "optimism-goerli", "arbitrum", "arbitrum-goerli"]
const supportedNetworks = getSupportedNetworks()

const supportedTemplates = [
{
Expand Down
8 changes: 7 additions & 1 deletion packages/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ yarn add @semaphore-protocol/data

## 📜 Usage

\# **new SemaphoreSubgraph**(networkOrSubgraphURL: _Network_ | _string_ = "goerli"): _SemaphoreSubgraph_
\# **getSupportedNetworks**(): _string[]_

```typescript
const supportedNetworks = getSupportedNetworks()
```

\# **new SemaphoreSubgraph**(networkOrSubgraphURL: SupportedNetwork | ValueOf\<SupportedNetwork> | string = "sepolia"): _SemaphoreSubgraph_

```typescript
import { SemaphoreSubgraph } from "@semaphore-protocol/data"
Expand Down
8 changes: 4 additions & 4 deletions packages/data/src/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
import checkParameter from "./checkParameter"
import getEvents from "./getEvents"
import SemaphoreABI from "./semaphoreABI.json"
import { EthersOptions, GroupResponse, Network } from "./types"
import { EthersOptions, GroupResponse, EthersNetwork } from "./types"

export default class SemaphoreEthers {
private _network: Network | string
private _network: EthersNetwork | string
private _options: EthersOptions
private _contract: Contract

Expand All @@ -24,7 +24,7 @@ export default class SemaphoreEthers {
* @param networkOrEthereumURL Ethereum network or custom URL.
* @param options Ethers options.
*/
constructor(networkOrEthereumURL: Network | string = "sepolia", options: EthersOptions = {}) {
constructor(networkOrEthereumURL: EthersNetwork | string = "sepolia", options: EthersOptions = {}) {
checkParameter(networkOrEthereumURL, "networkOrSubgraphURL", "string")

if (options.provider) {
Expand Down Expand Up @@ -114,7 +114,7 @@ export default class SemaphoreEthers {
* Returns the Ethereum network or custom URL.
* @returns Ethereum network or custom URL.
*/
get network(): Network | string {
get network(): EthersNetwork | string {
return this._network
}

Expand Down
9 changes: 9 additions & 0 deletions packages/data/src/getSupportedNetworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { SupportedNetwork } from "./types"

/**
* Returns the list of Semaphore supported networks.
* @returns Semaphore supported networks.
*/
export default function getSupportedNetworks(): string[] {
return Object.values(SupportedNetwork)
}
13 changes: 7 additions & 6 deletions packages/data/src/getURL.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Network } from "./types"
import { SupportedNetwork } from "./types"

/**
* Returns the subgraph URL related to the network passed as a parameter.
* @param network Semaphore supported network.
* @param supportedNetwork Semaphore supported network.
* @returns Subgraph URL.
*/
export default function getURL(network: Network): string {
switch (network) {
export default function getURL(supportedNetwork: SupportedNetwork | string): string {
switch (supportedNetwork) {
case "sepolia":
case "goerli":
case "mumbai":
case "optimism-goerli":
case "arbitrum-goerli":
case "arbitrum":
return `https://api.studio.thegraph.com/query/14377/semaphore-${network}/v3.6.1`
return `https://api.studio.thegraph.com/query/14377/semaphore-${supportedNetwork}/v3.6.1`
default:
throw new TypeError(`Network '${network}' is not supported`)
throw new TypeError(`Network '${supportedNetwork}' is not supported`)
}
}
5 changes: 3 additions & 2 deletions packages/data/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SemaphoreSubgraph from "./subgraph"
import SemaphoreEthers from "./ethers"
import getSupportedNetworks from "./getSupportedNetworks"
import SemaphoreSubgraph from "./subgraph"

export { SemaphoreSubgraph, SemaphoreEthers }
export * from "./types"
export { SemaphoreSubgraph, SemaphoreEthers, getSupportedNetworks }
2 changes: 1 addition & 1 deletion packages/data/src/subgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("SemaphoreSubgraph", () => {
semaphore = new SemaphoreSubgraph()
const semaphore1 = new SemaphoreSubgraph("arbitrum")

expect(semaphore.url).toContain("goerli")
expect(semaphore.url).toContain("sepolia")
expect(semaphore1.url).toContain("arbitrum")
})

Expand Down
8 changes: 4 additions & 4 deletions packages/data/src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AxiosRequestConfig } from "axios"
import checkParameter from "./checkParameter"
import getURL from "./getURL"
import request from "./request"
import { GroupResponse, GroupOptions, Network } from "./types"
import { GroupOptions, GroupResponse, SupportedNetwork } from "./types"
import { jsDateToGraphqlDate } from "./utils"

export default class SemaphoreSubgraph {
Expand All @@ -12,15 +12,15 @@ export default class SemaphoreSubgraph {
* Initializes the subgraph object with one of the supported networks or a custom URL.
* @param networkOrSubgraphURL Supported Semaphore network or custom Subgraph URL.
*/
constructor(networkOrSubgraphURL: Network | string = "goerli") {
constructor(networkOrSubgraphURL: SupportedNetwork | string = SupportedNetwork.SEPOLIA) {
checkParameter(networkOrSubgraphURL, "networkOrSubgraphURL", "string")

if (networkOrSubgraphURL.startsWith("http")) {
if (typeof networkOrSubgraphURL === "string" && networkOrSubgraphURL.startsWith("http")) {
this._url = networkOrSubgraphURL
return
}

this._url = getURL(networkOrSubgraphURL as Network)
this._url = getURL(networkOrSubgraphURL)
}

/**
Expand Down
11 changes: 10 additions & 1 deletion packages/data/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
export type Network =
export enum SupportedNetwork {
SEPOLIA = "sepolia",
GOERLI = "goerli",
MUMBAI = "mumbai",
OPTIMISM_GOERLI = "optimism-goerli",
ARBITRUM_GOERLI = "arbitrum-goerli",
ARBITRUM = "arbitrum"
}

export type EthersNetwork =
| "homestead"
| "matic"
| "goerli"
Expand Down