Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hop-protocol/hop-subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Feb 14, 2024
2 parents 19667e9 + 1caa8a0 commit 2e3c82c
Show file tree
Hide file tree
Showing 10 changed files with 10,281 additions and 6,291 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ config/*
!config/base.json
!config/base-mainnet.json
!config/base-testnet.json
!config/polygonzk-mainnet.json
!config/polygonzk.json

src/*
!src/L1_mapping.template.ts
Expand Down
163 changes: 119 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,6 @@

> The Hop Protocol Subgraph for [The Graph](https://thegraph.com/).
## Pre-setup notes

```bash
# Required for AbortController
nvm install 16.6.1
nvm use 16.6.1

# Various requirements
sudo apt install npm
sudo apt install -y jq
npm i @graphprotocol/[email protected]
``````

#### Troubleshooting

- Depending on your NPM version, [email protected] & [email protected] appears to hang when installing NPM packages. In reality, they just take a long time to install (up to or over an hour, depending on the instance type & resources).

- Auth key starts with 70cc

- When setting it up locally and running a load balancer, each of these should work for debugging at various stages
- http://ec2...com:8000/subgraphs/name/hop-protocol/hop-base-mainnet
- http://lb...com/subgraphs/name/hop-protocol/hop-base-mainnet
- https://base.subgraph.hop.exchange/subgraphs/name/hop-protocol/hop-base


- If you get the following error, you need to run comment out two lines in `buildfile.template.sh`

```
# Error
Failed to deploy to Graph node https://api.thegraph.com/deploy/: subgraph failure::Subgraph [hop-protocol/hop-base-mainnet] not found

# Lines to comment
npx graph auth https://api.thegraph.com/deploy/ $ACCESS_TOKEN
npx graph deploy --product hosted-service --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ "$GITHUB_ORG/{{subgraphName}}"
```

## Subgraphs

Expand Down Expand Up @@ -65,21 +30,27 @@ npx graph auth https://api.thegraph.com/deploy/ <access-token>

The access token is found on the hosted-service [dashboard](https://thegraph.com/hosted-service/dashboard).

### Add new chain config or new addresses
## Instructions to Add new chain config or new addresses

1. Update `scripts/mapping_config.json` with the new chain network and subgraph name mapping.

2. Update the `@hop-protocol/core` package version in `package.json`.

Update `scripts/mapping_config.json` with the new chain network and subgraph name mapping.
3. Add the `build-deploy` npm script in `package.json`.

If not adding a new chain, and only new addresses, then only update the `@hop-protocol/core` package version and run build/deploy commands as usual.
4. Update `.gitignore` and `clean.sh` (this step can probably be automated).

5. Run `npm i` to install the latest `@hop-protocol/core` package

6. Run `npm run generate-config-json` to create the updated config files

The config generation script is run automatically when building the subgraph with npm `build-deploy` command and can also be ran with `npm run generate-config-json`.

The generation script `scripts/generate_config_json.js` will read the chain/token config from `@hop-protocol/core` and output/override the config JSON files to `config/`.

When adding new chain, make sure to update `.gitignore` and `clean.sh` (this step can probably be automated).
7. [Install Docker](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository)

### Running local graph node with Docker

After bumping the version of `@hop-protocol/core` in `package.json` and pushing to github and CircleCI finishes building the [docker image](https://hub.docker.com/r/hopprotocol/subgraph), run the following commands to build and deploy the subgraph locally or on a server using docker compose:
8. After bumping the version of `@hop-protocol/core` in `package.json` and pushing to github and CircleCI finishes building the [docker image](https://hub.docker.com/r/hopprotocol/subgraph), run the following commands to build and deploy the subgraph locally or on a server using docker compose:

```bash
# change this values to deploy a different subgraph. Refer to `scripts/mapping_config.json` for the subgraph name
Expand All @@ -89,12 +60,58 @@ export RPC=https://goerli.base.org
# download docker-compose file
wget https://raw.githubusercontent.com/hop-protocol/subgraph/master/docker-compose.yml

# start services (use `-d` to run in background)
docker compose up --pull=always
# start services
# the `-d` is used to run in background
# the `--pull=always` is used to update the image when there is one available

# NOTE: The NETWORK and RPC are redundant, but sometimes cause issues if they do not exist
sudo RPC=https://rpc.linea.build NETWORK=linea docker compose up --pull=always
```

After a minute or so the graph should be available at http://localhost:8000/subgraphs/name/hop-protocol/hop-base-goerli/graphql

9. Troubleshooting

* If your server is unreachable from outside, ensure you enabled port `8000` with UFW
* Disable and enable UFW after this

## Pre-setup notes

_**These are deprecated in favor of the local Docker instructions. Only reference these if Docker is not used.**_

```bash
# Required for AbortController
nvm install 16.6.1
nvm use 16.6.1

# Various requirements
sudo apt install npm
sudo apt install -y jq
npm i @graphprotocol/[email protected]
``````

#### Troubleshooting

- Depending on your NPM version, [email protected] & [email protected] appears to hang when installing NPM packages. In reality, they just take a long time to install (up to or over an hour, depending on the instance type & resources).

- Auth key starts with 70cc

- When setting it up locally and running a load balancer, each of these should work for debugging at various stages
- http://ec2...com:8000/subgraphs/name/hop-protocol/hop-base-mainnet
- http://lb...com/subgraphs/name/hop-protocol/hop-base-mainnet
- https://base.subgraph.hop.exchange/subgraphs/name/hop-protocol/hop-base


- If you get the following error, you need to run comment out two lines in `buildfile.template.sh`

```
# Error
Failed to deploy to Graph node https://api.thegraph.com/deploy/: subgraph failure::Subgraph [hop-protocol/hop-base-mainnet] not found

# Lines to comment
npx graph auth https://api.thegraph.com/deploy/ $ACCESS_TOKEN
npx graph deploy --product hosted-service --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ "$GITHUB_ORG/{{subgraphName}}"
```
### Build and deploy
```bash
Expand All @@ -116,6 +133,8 @@ npm run build-deploy:nova
npm run build-deploy:zksync
npm run build-deploy:base-goerli
npm run build-deploy:base-mainnet
npm run build-deploy:linea
npm run build-deploy:polygonzk
```

By default, it will deploy under `hop-protocol` github org.
Expand Down Expand Up @@ -173,6 +192,18 @@ For Base:
ethereum: 'base-mainnet:https://developer-access-mainnet.base.org'
```
For Linea:
```yml
ethereum: 'linea:https://rpc.linea.build'
```
For Polygonzk:
```yml
ethereum: 'polygonzk:https://zkevm-rpc.com'
```
For Linea (Goerli):
```yml
Expand Down Expand Up @@ -223,6 +254,18 @@ For Base:
npx graph create hop-protocol/hop-base-mainnet --node http://127.0.0.1:8020
```

For Base:

```bash
npx graph create hop-protocol/hop-linea --node http://127.0.0.1:8020
```

For Polygonzk:

```bash
npx graph create hop-protocol/hop-polygonzk --node http://127.0.0.1:8020
```

For Linea (Goerli):

```bash
Expand Down Expand Up @@ -267,6 +310,18 @@ For Base:
npx graph deploy --ipfs http://localhost:5001 --node http://localhost:8020 hop-protocol/hop-base-mainnet
```

For Linea:

```bash
npx graph deploy --ipfs http://localhost:5001 --node http://localhost:8020 hop-protocol/hop-linea
```

For Polygonzk:

```bash
npx graph deploy --ipfs http://localhost:5001 --node http://localhost:8020 hop-protocol/hop-polygonzk
```

For Linea (Goerli):

```bash
Expand Down Expand Up @@ -311,6 +366,18 @@ For Base:
npm run build-deploy:base-mainnet
```

For Linea:

```bash
npm run build-deploy:linea
```

For Polygonzk:

```bash
npm run build-deploy:polygonzk
```

For Linea (Goerli):

```bash
Expand Down Expand Up @@ -347,6 +414,14 @@ For Base:

http://localhost:8000/subgraphs/name/hop-protocol/hop-base-mainnet

For Linea:

http://localhost:8000/subgraphs/name/hop-protocol/hop-linea

For Polygonzk:

http://localhost:8000/subgraphs/name/hop-protocol/hop-polygonzk

For Linea (Goerli):

http://localhost:8000/subgraphs/name/hop-protocol/hop-linea-goerli
Expand Down
2 changes: 2 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ rm -f config/base-goerli_*.json
rm -f config/base-testnet_*.json
rm -f config/base-mainnet_*.json
rm -f config/base_*.json
rm -f config/polygonzk_mainnet.json
rm -f config/polygonzk_*.json

rm -f src/L1_mapping_*_*.ts
rm -f src/L1_token_mapping_*_*.ts
Expand Down
70 changes: 0 additions & 70 deletions config/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,6 @@
"tokenDecimals": 18,
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 7393532
},
{
"dataSourceName": "TokenHOP",
"token": "HOP",
"tokenName": "Hop",
"tokenDecimals": 18,
"address": "0x38aF6928BF1Fd6B3c768752e716C49eb8206e20c",
"startBlock": 8901515
},
{
"dataSourceName": "TokenUSDC",
"token": "USDC",
"tokenName": "USD Coin",
"tokenDecimals": 6,
"address": "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
"startBlock": 8901770
},
{
"dataSourceName": "TokenUSDT",
"token": "USDT",
"tokenName": "Tether USD",
"tokenDecimals": 6,
"address": "0xfad6367E97217cC51b4cd838Cc086831f81d38C2",
"startBlock": 8892201
},
{
"dataSourceName": "TokenDAI",
"token": "DAI",
"tokenName": "DAI Stablecoin",
"tokenDecimals": 18,
"address": "0xb93cba7013f4557cDFB590fD152d24Ef4063485f",
"startBlock": 8892249
},
{
"dataSourceName": "TokenUNI",
"token": "UNI",
"tokenName": "Uniswap",
"tokenDecimals": 18,
"address": "0x41E5E6045f91B61AACC99edca0967D518fB44CFB",
"startBlock": 8892277
}
],
"bridges": [
Expand All @@ -58,36 +18,6 @@
"token": "ETH",
"address": "0xC8A4FB931e8D77df8497790381CA7d228E68a41b",
"startBlock": 7393532
},
{
"dataSourceName": "HopL1BridgeHOP",
"token": "HOP",
"address": "0xC7C736deFBfF0aD1CB63dB82f55f053D331B4d7C",
"startBlock": 8901515
},
{
"dataSourceName": "HopL1BridgeUSDC",
"token": "USDC",
"address": "0x0AA3256364e6fBb277cCf7bd90F8b512CE39eFFA",
"startBlock": 8901770
},
{
"dataSourceName": "HopL1BridgeUSDT",
"token": "USDT",
"address": "0x4A26dE45BD65ef6e5535846b92a8575E0A0e5CEd",
"startBlock": 8892201
},
{
"dataSourceName": "HopL1BridgeDAI",
"token": "DAI",
"address": "0x2d6fd82C7f531328BCaCA96EF985325C0894dB62",
"startBlock": 8892249
},
{
"dataSourceName": "HopL1BridgeUNI",
"token": "UNI",
"address": "0x4Ef4C1208F7374d0252767E3992546d61dCf9848",
"startBlock": 8892277
}
]
}
29 changes: 26 additions & 3 deletions config/linea-goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,30 @@
"network": "linea-goerli",
"isMainnet": false,
"subgraphName": "hop-linea-goerli",
"tokens": [],
"amms": [],
"bridges": []
"tokens": [
{
"dataSourceName": "Token",
"token": "ETH",
"tokenName": "Ethereum",
"tokenDecimals": 18,
"address": "0x2C1b868d6596a18e32E61B901E4060C872647b6C",
"startBlock": 1904158
}
],
"amms": [
{
"dataSourceName": "HopL2Amm",
"token": "ETH",
"address": "0x1Be8d7851d64BC296e9E941F414f9a6635b5D830",
"startBlock": 1904158
}
],
"bridges": [
{
"dataSourceName": "HopL2Bridge",
"token": "ETH",
"address": "0x893246FACF345c99e4235E5A7bbEE7404c988b96",
"startBlock": 1904158
}
]
}
Loading

0 comments on commit 2e3c82c

Please sign in to comment.