Skip to content

Commit

Permalink
[SUBGRAPH | METADATA] tech debt refactor (#1692)
Browse files Browse the repository at this point in the history
* tech debt refactor

- remove config files
- new script for retrieving hosted service networks
- new script for building network config file
- modify deploy.sh to use new network config builder
- build hosted service network json in necessary workflow files

* Delete hosted-service-networks.json

* fix up workflow
  • Loading branch information
0xdavinchee authored Sep 25, 2023
1 parent 5bd8e85 commit 6463845
Show file tree
Hide file tree
Showing 31 changed files with 102 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
run: yarn build
working-directory: ./packages/ethereum-contracts

- name: Get Hosted Service Networks from metadata
run: npx ts-node ./scripts/getHostedServiceNetworks.ts
working-directory: ./packages/subgraph

- name: Run schema check
run: |
./tasks/setupTestEnvironment.sh
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/call.deploy-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ jobs:
run: "yarn codegen"
working-directory: ${{ env.subgraph-working-directory }}

- name: Get Hosted Service Networks from metadata
run: npx ts-node ./scripts/getHostedServiceNetworks.ts
working-directory: ${{ env.subgraph-working-directory }}

# - name: Ensure deployment_env property is passed
# run: |
# if [ "${{ inputs.deployment_env }}" == "" ];then
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/call.test-local-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jobs:
name: Run subgraph unit tests
runs-on: ubuntu-latest

env:
subgraph-working-directory: ./packages/subgraph

defaults:
run:
shell: nix develop -c bash -xe {0}
Expand All @@ -34,10 +37,14 @@ jobs:
- name: "Build contracts"
run: yarn build
working-directory: ./packages/ethereum-contracts

- name: "Build"
run: npx ts-node scripts/buildNetworkConfig.ts polygon-mainnet
working-directory: ${{ env.subgraph-working-directory }}

- name: "Run unit tests"
run: yarn matchstick
working-directory: ./packages/subgraph
working-directory: ${{ env.subgraph-working-directory }}

subgraph-end-to-end-integration:
name: Run subgraph integration tests
Expand Down
2 changes: 1 addition & 1 deletion packages/metadata/module/networks/list.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ContractAddresses {
}
interface SubgraphData {
readonly name: string;
readonly hostedEndpoint: string;
readonly hostedEndpoint?: string;
readonly satsumaEndpoint?: string;
}
export interface NetworkMetaData {
Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ tasks/config
src/addresses.ts
**/*.wasm
**/*.latest.json
tests/.bin
tests/.bin
hosted-service-networks.json
10 changes: 0 additions & 10 deletions packages/subgraph/config/arbitrum-goerli.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/arbitrum-one.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/avalanche-c.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/avalanche-fuji.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/base-goerli.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/base-mainnet.json

This file was deleted.

11 changes: 0 additions & 11 deletions packages/subgraph/config/bsc-mainnet.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/celo-mainnet.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/eth-goerli.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/eth-mainnet.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/eth-sepolia.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/subgraph/config/goerli.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/subgraph/config/matic.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/subgraph/config/mumbai.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/optimism-goerli.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/optimism-mainnet.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/polygon-mainnet.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/polygon-mumbai.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/polygon-zkevm-testnet.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/subgraph/config/xdai-mainnet.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/subgraph/config/xdai.json

This file was deleted.

15 changes: 0 additions & 15 deletions packages/subgraph/hosted-service-networks.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"pretest": "yarn testenv:start",
"test": "npx hardhat test",
"matchstick": "run-s matchstick:*",
"matchstick:prepare-manifest": "mustache config/matic.json subgraph.template.yaml > subgraph.yaml",
"matchstick:prepare-addresses": "mustache config/matic.json src/addresses.template.ts > src/addresses.ts",
"matchstick:prepare-manifest": "mustache config/polygon-mainnet.json subgraph.template.yaml > subgraph.yaml",
"matchstick:prepare-addresses": "mustache config/polygon-mainnet.json src/addresses.template.ts > src/addresses.ts",
"matchstick:prepare-generated": "yarn getAbi && yarn codegen && yarn generate-sf-meta-local",
"matchstick:test": "graph test",
"dev": "nodemon -e ts -x yarn matchstick:test",
Expand Down
48 changes: 48 additions & 0 deletions packages/subgraph/scripts/buildNetworkConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import fs from "fs";
import metadata from "@superfluid-finance/metadata";

interface SubgraphConfig {
readonly network: string;
readonly hostStartBlock: number;
readonly hostAddress: string;
readonly cfaAddress: string;
readonly idaAddress: string;
readonly superTokenFactoryAddress: string;
readonly resolverV1Address: string;
readonly nativeAssetSuperTokenAddress: string;
}

// script usage: npx ts-node ./scripts/buildNetworkConfig.ts <NETWORK_NAME>
function main() {
const networkName = process.argv[2];

const networkMetadata = metadata.getNetworkByName(networkName);

if (!networkMetadata) {
throw new Error("No metadata found");
}
const newThing: SubgraphConfig = {
network: networkMetadata.shortName,
hostStartBlock: networkMetadata.startBlockV1,
hostAddress: networkMetadata.contractsV1.host,
cfaAddress: networkMetadata.contractsV1.cfaV1,
idaAddress: networkMetadata.contractsV1.idaV1,
superTokenFactoryAddress: networkMetadata.contractsV1.superTokenFactory,
resolverV1Address: networkMetadata.contractsV1.resolver,
nativeAssetSuperTokenAddress: networkMetadata.nativeTokenWrapper,
};

const writeToDir =
__dirname.split("subgraph")[0] + `subgraph/config/${networkName}.json`;

fs.writeFile(writeToDir, JSON.stringify(newThing), (err) => {
if (err) {
console.log(err);
process.exit(1);
} else {
process.exit(0);
}
});
}

main();
28 changes: 28 additions & 0 deletions packages/subgraph/scripts/getHostedServiceNetworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import fs from "fs";
import metadata from "@superfluid-finance/metadata";

// This script is used to retrieve the list of networks which have a hosted
// service endpoint.
// script usage: npx ts-node ./scripts/getHostedServiceNetworks.ts
function main() {
const networks = JSON.stringify(
metadata.networks
.filter((x) => x.subgraphV1.hostedEndpoint != null)
.map((x) => x.name)
);

const writeToDir =
__dirname.split("subgraph")[0] +
"subgraph/hosted-service-networks.json";

fs.writeFile(writeToDir, networks, (err) => {
if (err) {
console.log(err);
process.exit(1);
} else {
process.exit(0);
}
});
}

main();
Loading

0 comments on commit 6463845

Please sign in to comment.