Skip to content

Commit

Permalink
chore: migrate to TheGraph Studio (#95)
Browse files Browse the repository at this point in the history
Co-authored-by: MantisClone <david.huntmateo@request.network>
  • Loading branch information
alexandre-abrioux and MantisClone authored May 23, 2024
1 parent cb9e380 commit c9b43c4
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 792 deletions.
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NETWORK=goerli
WEB3_URL=https://goerli.infura.io/v3/xxx
NETWORK=sepolia
WEB3_URL=https://sepolia.infura.io/v3/xxx
20 changes: 7 additions & 13 deletions .github/actions/deploy/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@ inputs:
chain:
description: The chain to deploy the subgraph for
required: true
token:
description: Authentication token
deploy-key:
description: Graph Node deploy key
required: false
default: ""
runs:
using: composite
steps:
- uses: actions/checkout@v3
- name: Get yarn cache directory path
shell: sh
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v3
- uses: actions/setup-node@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
node-version: 20
cache: yarn
- name: install packages
shell: sh
run: yarn
Expand All @@ -31,5 +25,5 @@ runs:
shell: sh
run: yarn subgraph deploy ${{ inputs.chain }}
env:
TOKEN: ${{ inputs.token }}
VERSION: ${{ steps.short-sha.outputs.hash }}
DEPLOY_KEY: ${{ inputs.deploy-key }}
VERSION_LABEL: ${{ steps.short-sha.outputs.hash }}
41 changes: 29 additions & 12 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,52 @@ on:
workflow_dispatch:

jobs:
deploy-hosted-service:
deploy-thegraph-studio-rn:
runs-on: ubuntu-latest
strategy:
matrix:
chain:
- "arbitrum-one"
- "avalanche"
- "base"
- "bsc"
- "celo"
- "core"
- "fantom"
- "fuse"
- "goerli"
- "mainnet"
- "matic"
- "xdai"
- "optimism"
- "moonbeam"
- "tombchain"
- "near"
- "near-testnet"
- "optimism"
- "sepolia"
- "xdai"
- "zksyncera"
environment:
name: ${{ matrix.chain }}
url: ${{ format('https://api.studio.thegraph.com/query/67444/request-payments-{0}/version/latest', matrix.chain) }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/deploy
with:
chain: ${{ matrix.chain }}
deploy-key: ${{ secrets.SUBGRAPH_STUDIO_DEPLOY_KEY_RN }}

deploy-thegraph-studio-rf:
runs-on: ubuntu-latest
strategy:
matrix:
chain:
- "mainnet"
environment:
name: ${{ matrix.chain }}
# Use TheGraph Hosted Service for all networks
url: ${{ format('https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-{0}', matrix.chain) }}
url: ${{ format('https://api.studio.thegraph.com/query/35843/request-payments-{0}/version/latest', matrix.chain) }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/deploy
with:
chain: ${{ matrix.chain }}
token: ${{ secrets.THEGRAPH_TOKEN }}
deploy-key: ${{ secrets.SUBGRAPH_STUDIO_DEPLOY_KEY_RF }}

deploy-core:
runs-on: ubuntu-latest
environment:
Expand All @@ -46,7 +62,8 @@ jobs:
- uses: ./.github/actions/deploy
with:
chain: "core"
token: ${{ secrets.THEGRAPH_CORE_TOKEN }}
deploy-key: ${{ secrets.THEGRAPH_CORE_TOKEN }}

deploy-mantle:
runs-on: ubuntu-latest
strategy:
Expand All @@ -64,4 +81,4 @@ jobs:
- uses: ./.github/actions/deploy
with:
chain: ${{ matrix.chain }}
token: ""
deploy-key: ""
134 changes: 41 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,27 @@
This repo contains the code and configuration for Request Payment subgraphs:

Mainnets:
- [Ethereum Mainnet - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-mainnet)
- [Ethereum Mainnet - Decentralized Network](https://thegraph.com/explorer/subgraphs/5mXPGZRC2Caynh4NyVrTK72DAGB9dfcKmLsnxYWHQ9nd?view=Overview&chain=arbitrum-one)
- [Polygon (Matic) - Hosted Service](https://thegraph.com/explorer/subgraph/requestnetwork/request-payments-matic)
- [Polygon (Matic) - Decentralized Network](https://thegraph.com/explorer/subgraphs/DPpU1WMxk2Z4H2TAqgwGbVBGpabjbC1972Mynak5jSuR?view=Overview&chain=arbitrum-one)
- [Celo - Hosted Service](https://thegraph.com/explorer/subgraph/requestnetwork/request-payments-celo)
- [Celo - Decentralized Network](https://thegraph.com/explorer/subgraphs/5ts3PHjMcH2skCgKtvLLNE64WLjbhE5ipruvEcgqyZqC?view=Overview&chain=arbitrum-one)
- [BSC - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-bsc)
- [Gnosis Chain (xDai) - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-xdai)
- [Gnosis Chain (xDai) - Decentralized Network](https://thegraph.com/explorer/subgraphs/2UAW7B94eeeqaL5qUM5FDzTWJcmgA6ta1RcWMo3XuLmU?view=Overview&chain=arbitrum-one)
- [Fuse - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-fuse)
- [Fantom - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-fantom)
- [Fantom - Decentralized Network](https://thegraph.com/explorer/subgraphs/6AwmiYo5eY36W526ZDQeAkNBjXjXKYcMLYyYHeM67xAb?view=Overview&chain=arbitrum-one)
- [Near - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-near)
- [Avalanche - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-avalanche)
- [Avalanche - Decentralized Network](https://thegraph.com/explorer/subgraphs/A27V4PeZdKHeyuBkehdBJN8cxNtzVpXvYoqkjHUHRCFp?view=Overview&chain=arbitrum-one)
- [Optimism - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-optimism)
- [Moonbeam - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-moonbeam)
- [Arbitrum One - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-arbitrum-one)
- [Arbitrum One - Decentralized Network](https://thegraph.com/explorer/subgraphs/3MtDdHbzvBVNBpzUTYXGuDDLgTd1b8bPYwoH1Hdssgp9?view=Overview&chain=arbitrum-one)
- [zkSync Era - Subgraph Studio](https://api.studio.thegraph.com/query/35843/request-payment-zksyncera/version/latest)
- [Base - Subgraph Studio](https://api.studio.thegraph.com/query/35843/request-payments-base/version/latest)
- [Mantle - Hosted by FusionX](https://graph.fusionx.finance/subgraphs/name/request-payments-mantle)
- [Arbitrum One](https://thegraph.com/explorer/subgraphs/3MtDdHbzvBVNBpzUTYXGuDDLgTd1b8bPYwoH1Hdssgp9?view=Overview&chain=arbitrum-one)
- [Avalanche](https://thegraph.com/explorer/subgraphs/A27V4PeZdKHeyuBkehdBJN8cxNtzVpXvYoqkjHUHRCFp?view=Overview&chain=arbitrum-one)
- [Base](https://thegraph.com/explorer/subgraphs/A5AqE5jBRrHYfgqYihwJw9EBZU5MqL6JyN4vLg7sx5jU?view=Overview&chain=arbitrum-one)
- [BSC](https://thegraph.com/explorer/subgraphs/4PScFUi3CFDbop9XzT6gCDtD4RR8kRzyrzSjrHoXHZBt?view=Overview&chain=arbitrum-one)
- [Celo](https://thegraph.com/explorer/subgraphs/5ts3PHjMcH2skCgKtvLLNE64WLjbhE5ipruvEcgqyZqC?view=Overview&chain=arbitrum-one)
- [Core - Hosted by CoreDAO](https://thegraph.coredao.org/subgraphs/name/requestnetwork/request-payments-core)
- [Ethereum Mainnet](https://thegraph.com/explorer/subgraphs/5mXPGZRC2Caynh4NyVrTK72DAGB9dfcKmLsnxYWHQ9nd?view=Overview&chain=arbitrum-one)
- [Fuse](https://thegraph.com/explorer/subgraphs/EHSpUBa7PAewX7WsaU2jbCKowF5it56yStr6Zgf8aDtx?view=Overview&chain=arbitrum-one)
- [Fantom](https://thegraph.com/explorer/subgraphs/6AwmiYo5eY36W526ZDQeAkNBjXjXKYcMLYyYHeM67xAb?view=Overview&chain=arbitrum-one)
- [Gnosis Chain (xDai)](https://thegraph.com/explorer/subgraphs/2UAW7B94eeeqaL5qUM5FDzTWJcmgA6ta1RcWMo3XuLmU?view=Overview&chain=arbitrum-one)
- [Mantle - Hosted by FusionX](https://graph.fusionx.finance/subgraphs/name/request-payments-mantle)
- [Moonbeam](https://thegraph.com/explorer/subgraphs/4Jo3DwA25zyVLeDhyi7cks52dNrkVCWWhQJzm1hKnCfj?view=Overview&chain=arbitrum-one)
- [Near](https://thegraph.com/explorer/subgraphs/9yEg3h46CZiv4VuSqo1erMMBx5sHxRuW5Ai2V8goSpQL?view=Overview&chain=arbitrum-one)
- [Optimism](https://thegraph.com/explorer/subgraphs/525fra79nG3Z1w8aPZh3nHsH5zCVetrVmceB1hKcTrTX?view=Overview&chain=arbitrum-one)
- [Polygon (Matic)](https://thegraph.com/explorer/subgraphs/DPpU1WMxk2Z4H2TAqgwGbVBGpabjbC1972Mynak5jSuR?view=Overview&chain=arbitrum-one)
- [zkSync Era](https://thegraph.com/explorer/subgraphs/HJNZW9vRSGXrcCVyQMdNKxxuLKeZcV6yMjTCyY6T2oon?view=Overview&chain=arbitrum-one)

Testnets:
- [Sepolia - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-sepolia)
- [Goerli - Hosted Service](https://thegraph.com/explorer/subgraph/requestnetwork/request-payments-goerli)
- [Near Testnet - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-near-testnet)
- [Arbitrum Rinkeby - Hosted Service](https://thegraph.com/hosted-service/subgraph/requestnetwork/request-payments-arbitrum-rinkeby)
- [Mantle Testnet - Hosted by Mantle](https://graph.testnet.mantle.xyz/subgraphs/name/request-payments-mantle-testnet)
- [Near Testnet](https://thegraph.com/explorer/subgraphs/AusVyfndonsMVFrVzckuENLqx8t6kcXuxn6C6VbSGd7M?view=Overview&chain=arbitrum-one)
- [Sepolia](https://thegraph.com/explorer/subgraphs/6e8Dcwt3cvsgNU3JYBtRQQ9Sj4P9VVVnXaPjJ3jUpYpY?view=Overview&chain=arbitrum-one)

It indexes Request's proxy smart-contracts for easy querying of payment data.

Expand Down Expand Up @@ -92,7 +83,7 @@ One manifest can refer to many different versions of proxies dealing with the sa
### Build

```
export NETWORK=goerli
export NETWORK=sepolia
yarn build
```

Expand All @@ -101,72 +92,29 @@ yarn build
### Local

```
export NETWORK=goerli
export NETWORK=sepolia
yarn create-local
yarn deploy-local
```

### Networks

Some of the deployments are automated, others are manual
#### Automated Deployment
Deployment on EVM chains is semi-automated, when a Github release is published

* mantle-testnet uses the [graph node hosted by Mantle](https://docs.mantle.xyz/network/for-devs/resources-and-tooling/graph-endpoints).
* mantle uses the [graph node hosted by FusionX](https://graph.fusionx.finance)
* all other EVM chains use the hosted service.

Test chains like Goerli and Mantle Testnet will be deployed immediately when a release is published.

Mainnets (all others) require manual approval in [github actions](https://github.com/RequestNetwork/payments-subgraph/actions).

#### Manual Deployment to 3rd-party Graph Node

The following networks are deployed on 3rd-party graph nodes:

- Core
- Mantle
- Mantle Testnet

The first time a subgraph is deployed to a non-hosted-service graph node, it needs to be created.

For example:

```bash
yarn graph create --node https://deploy.graph.fusionx.finance requestnetwork/request-payments-mantle
```

For non-EVM deployments like NEAR, use:

```
yarn graph deploy --product hosted-service --deploy-key <GRAPH_KEY> requestnetwork/request-payments-<network> ./subgraph.<network>.yaml
```

For decentralized network, use:
```
yarn graph deploy --studio request-payments-<network> ./subgraph.<network>.yaml --version-label v1.<bumped-version>
```
### Hosted

#### Manual Deployment to Subgraph Studio
All deployments are semi-automated through GitHub action.
The first time a subgraph is deployed, it needs to be created on the Graph Node or on Subgraph Studio.

The following networks are only supported by The Graph's Subgraph Studio so the deployment is different.
Graph Node locations:
* `core` uses the [Graph Node hosted by CoreDAO](https://thegraph.coredao.org)
* `mantle` uses the [Graph Node hosted by FusionX](https://graph.fusionx.finance)
* `mantle-testnet` uses the [Graph Node hosted by Mantle](https://docs.mantle.xyz/network/for-devs/resources-and-tooling/graph-endpoints)
* all other chains use Subgraph Studio.

- [zkSync Era](https://thegraph.com/studio/subgraph/request-payment-zksyncera)
- [Base](https://thegraph.com/studio/subgraph/request-payments-base)
When a PR is merged on `main`:
* test chains are deployed immediately, without approval
* mainnet chains require a manual approval in [GitHub actions](https://github.com/RequestNetwork/payments-subgraph/actions).

Step 1: Authenticate the graph-cli using a subgraph-specific deploy key (aka. studio token). Get the deploy keys from the links listed above.
```
graph auth --studio <studio token>
```
Step 2: Deploy to subgraph studio
```
graph deploy --studio request-payment-<network> subgraph.<network>.yaml
```
Examples:
```
graph deploy --studio request-payment-zksyncera subgraph.zksyncera.yaml
graph deploy --studio request-payments-base subgraph.base.yaml
```
> **Important**: Once a subgraph is deployed on Subgraph Studio,
> a manual action is required to publish it to the decentralized network.
> See [the documentation](https://thegraph.com/docs/en/publishing/publishing-a-subgraph/) for more information.
### Check the deployed version

Expand Down Expand Up @@ -210,13 +158,6 @@ yarn subgraph compare NETWORK_NAME_1 NETWORK_NAME_2

### Delays

Some networks will require you to set env vars:

```
export ALCHEMY_API_KEY=...
export INFURA_API_KEY=...
```

Run one of these commands to check for indexing delays.

```
Expand All @@ -228,6 +169,13 @@ yarn subgraph monitor --network NETWORK_NAME
yarn subgraph monitor --network NETWORK_NAME_1 NETWORK_NAME_2
```

Some networks will require you to set env vars:

```
export ALCHEMY_API_KEY=...
export INFURA_API_KEY=...
```

### Hosting service API

URL: https://api.thegraph.com/index-node/graphql
Expand All @@ -236,7 +184,7 @@ Schema: https://github.com/graphprotocol/graph-node/blob/master/server/index-nod
### Sync failed with no logs

```
http POST 'https://api.thegraph.com/index-node/graphql' query="{ indexingStatusForPendingVersion(subgraphName: \"requestnetwork/request-payments-goerli\") { subgraph fatalError { message } nonFatalErrors {message } } }" | jq .data
http POST 'https://api.thegraph.com/index-node/graphql' query="{ indexingStatusForPendingVersion(subgraphName: \"requestnetwork/request-payments-sepolia\") { subgraph fatalError { message } nonFatalErrors {message } } }" | jq .data
```

### Build issue `TS6054: File '~lib/allocator/arena.ts' not found.`
Expand Down
51 changes: 19 additions & 32 deletions cli/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,46 @@
import yargs from "yargs";
import { deploySubgraph } from "../lib/deploy";
import networks from "../networks.json";
import { defaultGraphNodeInfo, graphNodeInfoByNetwork } from "../graph-nodes";
import { graphNodeInfoByNetwork } from "../graph-nodes";

export const command = "deploy [network..]";
export const desc = "Deploys one subgraph";
export const builder = (y: yargs.Argv) =>
y
.middleware(argv => {
if (process.env.TOKEN) argv.token = process.env.TOKEN;
if (process.env.VERSION) argv.version = process.env.VERSION;
if (process.env.DEPLOY_KEY) argv["deploy-key"] = process.env.DEPLOY_KEY;
if (process.env.VERSION_LABEL)
argv["version-label"] = process.env.VERSION_LABEL;
}, true)
.positional("network", {
desc: "The network to deploy to",
type: "string",
array: true,
choices: networks,
})
.option("all", {
desc: "Deploy on all networks",
type: "boolean",
})
.option("token", {
desc: "TheGraph token",
.option("deploy-key", {
desc: "Graph Node deploy key",
type: "string",
})
.check(({ all, network }) => {
if (all && network)
throw new Error("Cannot specify both -all and positional `network`");
if (all || network) return true;
throw new Error("One of --all or positional `network` must be specified");
.option("version-label", {
desc: "The version of the deployed subgraph",
type: "string",
});

export const handler = ({
network,
token,
all,
["deploy-key"]: deployKey,
["version-label"]: versionLabel,
}: Awaited<ReturnType<typeof builder>["argv"]>) => {
const networkList = all ? networks : network || [];
const options = token
? {
"access-token": token,
}
: undefined;
const networkList = network || [];
for (const net of networkList) {
console.log(`Deploy on ${net}`);
deploySubgraph(
`requestnetwork/request-payments-${net}`,
`./subgraph.${net}.yaml`,
{
ipfs: graphNodeInfoByNetwork[net]?.ipfs || defaultGraphNodeInfo.ipfs,
node: `${graphNodeInfoByNetwork[net]?.deploy ||
defaultGraphNodeInfo.deploy}`,
},
options,
);
deploySubgraph(`request-payments-${net}`, `./subgraph.${net}.yaml`, {
"deploy-key": deployKey,
ipfs: graphNodeInfoByNetwork[net]?.ipfs,
node: graphNodeInfoByNetwork[net]?.deploy,
product: deployKey ? "subgraph-studio" : undefined,
"version-label": versionLabel,
});
}
};
Loading

0 comments on commit c9b43c4

Please sign in to comment.