Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): Implement a unified call to all the subgraphs #745

Merged
merged 13 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion explorer/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import { useNetworkContext } from "@/providers/network-provider/context";
import { APP_ROUTES } from "@/routes/constants";
import { cropString } from "@/utils/stringUtils";

import { MenuButton } from "./components/MenuButtons";
import { Button } from "../Buttons";
import { EButtonType } from "../Buttons/enum";
import { NavigationList } from "../NavigationList";
import { SearchInput } from "../SearchInput";
import { MenuButton } from "./components/MenuButtons";
alainncls marked this conversation as resolved.
Show resolved Hide resolved

import "./styles.css";

Expand Down
10,571 changes: 5,697 additions & 4,874 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2,700 changes: 1,494 additions & 1,206 deletions sdk/.graphclient/index.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions sdk/.graphclient/persisted_operations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"593eb87c0edb701b5f8e028caa5f8319b8477ef56e8b56cc87d5f15118d79e4e": "query MultichainAttestationsQuery($chainNames: [String!]!, $first: Int, $skip: Int, $where: Attestation_filter, $orderBy: Attestation_orderBy, $orderDirection: OrderDirection) {\n multichainAttestations(\n chainNames: $chainNames\n first: $first\n skip: $skip\n where: $where\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n id\n chainName\n replacedBy\n attester\n attestedDate\n expirationDate\n revocationDate\n version\n revoked\n subject\n encodedSubject\n attestationData\n decodedData\n schema {\n id\n name\n description\n context\n schema\n attestationCounter\n }\n portal {\n id\n ownerAddress\n modules\n isRevocable\n name\n description\n ownerName\n attestationCounter\n }\n }\n}\n\nquery MultichainPortalsQuery($chainNames: [String!]!, $first: Int, $skip: Int, $where: Portal_filter, $orderBy: Portal_orderBy, $orderDirection: OrderDirection) {\n multichainPortals(\n chainNames: $chainNames\n first: $first\n skip: $skip\n where: $where\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n chainName\n id\n ownerAddress\n modules\n isRevocable\n name\n description\n ownerName\n attestationCounter\n }\n}\n\nquery MultichainSchemasQuery($chainNames: [String!]!, $first: Int, $skip: Int, $where: Schema_filter, $orderBy: Schema_orderBy, $orderDirection: OrderDirection) {\n multichainSchemas(\n chainNames: $chainNames\n first: $first\n skip: $skip\n where: $where\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n chainName\n id\n name\n description\n context\n schema\n attestationCounter\n }\n}\n\nquery MultichainModulesQuery($chainNames: [String!]!, $first: Int, $skip: Int, $where: Module_filter, $orderBy: Module_orderBy, $orderDirection: OrderDirection) {\n multichainModules(\n chainNames: $chainNames\n first: $first\n skip: $skip\n where: $where\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n chainName\n id\n moduleAddress\n name\n description\n }\n}"
}
998 changes: 503 additions & 495 deletions sdk/.graphclient/schema.graphql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,6 @@ export type _SubgraphErrorPolicy_ =

export type Context = {
["linea-attestation-registry"]: { Query: QuerySdk, Mutation: MutationSdk, Subscription: SubscriptionSdk },

["chainName"]: Scalars['ID']
};
}
31 changes: 30 additions & 1 deletion sdk/.graphclientrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,33 @@ sources:
- name: linea-attestation-registry
handler:
graphql:
endpoint: https://api.studio.thegraph.com/query/67521/verax-v2-linea/v0.0.1
endpoint: https://api.studio.thegraph.com/query/67521/{context.chainName:verax-v2-linea}/version/latest

additionalTypeDefs: |
extend type Attestation {
chainName: String
}
extend type Portal {
chainName: String
}
extend type Schema {
chainName: String
}
extend type Module {
chainName: String
}
extend type Query {
multichainAttestations(chainNames: [String!]!, first: Int, skip: Int, where: Attestation_filter, orderBy: Attestation_orderBy, orderDirection: OrderDirection): [Attestation!]!
multichainPortals(chainNames: [String!]!, first: Int, skip: Int, where: Portal_filter, orderBy: Portal_orderBy, orderDirection: OrderDirection): [Portal!]!
multichainSchemas(chainNames: [String!]!, first: Int, skip: Int, where: Schema_filter, orderBy: Schema_orderBy, orderDirection: OrderDirection): [Schema!]!
multichainModules(chainNames: [String!]!, first: Int, skip: Int, where: Module_filter, orderBy: Module_orderBy, orderDirection: OrderDirection): [Module!]!
}

additionalResolvers:
- ./src/resolvers.ts

documents:
- ./queries.graphql

codegen:
contextType: "MeshContext & { chainName: string }"
11 changes: 10 additions & 1 deletion sdk/doc/cli-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
pnpm portal findonebyid '0x34798a866f52949208e67fb57ad36244024c50c0'

pnpm portal findby '{\"ownerName\": \"Tester\"}'

pnpm portal findbymultichain '{\"ownerName\": \"Clique\"}'

pnpm portal simulateattest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}, \"validationPayloads\": []}'

pnpm portal attest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": 1693583329, \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": true }]}, \"validationPayloads\": []}'
Expand Down Expand Up @@ -56,6 +59,8 @@

pnpm attestation findby '{\"portal\": \"0x34798a866f52949208e67fb57ad36244024c50c0\"}'

pnpm attestation findbymultichain '{\"id\": \"0x00000000000000000000000000000000000000000000000000000000000001ce\"}'

pnpm attestation getRelatedAttestations "0x0000000000000000000000000000000000000000000000000000000000000001"

pnpm attestation simulateUpdateRouter "0xC825ACA6621597bcb86438346A2538fba85380d9"
Expand Down Expand Up @@ -95,6 +100,8 @@

pnpm module findby '{\"name\": \"Msg Sender Module\"}'

pnpm module findbymultichain '{\"name_contains\": \"CliqueSchemaChecker\"}'

pnpm module simulateUpdateRouter "0x980978299e23B8F9B4D11542A83D92C83e781cb6"

pnpm module updateRouter "0x980978299e23B8F9B4D11542A83D92C83e781cb6"
Expand Down Expand Up @@ -130,7 +137,9 @@
```shell
pnpm schema findonebyid "0xce2647ed39aa89e6d1528a56deb6c30667ed2aae1ec2378ec3140c0c5d98a61e"

pnpm schema findby '{\"description\": \"Gitcoin Passport Score\"}'
pnpm schema findby '{\"description\": \"Gitcoin Passport score\"}'

pnpm schema findbymultichain '{\"description\": \"Gitcoin Passport score\"}'

pnpm schema simulateUpdateRouter "0x980978299e23B8F9B4D11542A83D92C83e781cb6"

Expand Down
17 changes: 16 additions & 1 deletion sdk/examples/attestation/attestationExamples.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import { ChainName, VeraxSdk } from "../../src/VeraxSdk";
import { Attestation_filter } from "../../.graphclient";

export default class AttestationExamples {
Expand All @@ -22,6 +22,21 @@ export default class AttestationExamples {
console.log(await this.veraxSdk.attestation.findBy(2, 0, filter, "attestedDate", "desc"));
}

if (methodName.toLowerCase() == "findByMultiChain".toLowerCase() || methodName == "") {
const filter: Attestation_filter | undefined =
argv !== "" ? JSON.parse(argv) : { attester_not: "0x6ecfd8252c19ac2bf4bd1cbdc026c001c93e179d" };
console.log(
await this.veraxSdk.attestation.findByMultiChain(
[ChainName.LINEA_MAINNET, ChainName.ARBITRUM_MAINNET],
2,
0,
filter,
"attestedDate",
"desc",
),
);
}

if (methodName.toLowerCase() == "getRelatedAttestations".toLowerCase() || methodName == "") {
const attestationId: string =
argv === "" ? "0x0000000000000000000000000000000000000000000000000000000000000001" : argv;
Expand Down
18 changes: 17 additions & 1 deletion sdk/examples/module/moduleExamples.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Address } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import { ChainName, VeraxSdk } from "../../src/VeraxSdk";
import { Module_filter } from "../../.graphclient";

export default class ModuleExamples {
private veraxSdk: VeraxSdk;
Expand All @@ -18,6 +19,21 @@ export default class ModuleExamples {
console.log(await this.veraxSdk.module.findBy(2, 0, { name_contains: "Msg" }, undefined, undefined));
}

if (methodName.toLowerCase() == "findByMultiChain".toLowerCase() || methodName == "") {
const filter: Module_filter | undefined =
argv !== "" ? JSON.parse(argv) : { name_contains: "CliqueSchemaChecker" };
console.log(
await this.veraxSdk.module.findByMultiChain(
[ChainName.LINEA_MAINNET, ChainName.ARBITRUM_MAINNET],
2,
0,
filter,
undefined,
undefined,
),
);
}

if (methodName.toLowerCase() == "simulateUpdateRouter".toLowerCase() || methodName == "") {
const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address);
console.log(await this.veraxSdk.module.simulateUpdateRouter(routerAddress));
Expand Down
17 changes: 16 additions & 1 deletion sdk/examples/portal/portalExamples.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Address } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import { ChainName, VeraxSdk } from "../../src/VeraxSdk";
import { Portal_filter } from "../../.graphclient";

export default class PortalExamples {
private veraxSdk: VeraxSdk;
Expand All @@ -18,6 +19,20 @@ export default class PortalExamples {
console.log(await this.veraxSdk.portal.findBy(2, 0, { ownerName: "Alain" }, "name", "desc"));
}

if (methodName.toLowerCase() == "findByMultiChain".toLowerCase() || methodName == "") {
const filter: Portal_filter | undefined = argv !== "" ? JSON.parse(argv) : { name_contains: "CliquePortal" };
console.log(
await this.veraxSdk.portal.findByMultiChain(
[ChainName.LINEA_MAINNET, ChainName.ARBITRUM_MAINNET],
2,
0,
filter,
undefined,
undefined,
),
);
}

if (methodName.toLowerCase() == "simulateAttest".toLowerCase() || methodName == "") {
let params;
if (argv !== "") params = JSON.parse(argv);
Expand Down
20 changes: 18 additions & 2 deletions sdk/examples/schema/schemaExamples.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Address } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import { ChainName, VeraxSdk } from "../../src/VeraxSdk";
import { Schema_filter } from "../../.graphclient";

export default class SchemaExamples {
private veraxSdk: VeraxSdk;
Expand All @@ -16,7 +17,22 @@ export default class SchemaExamples {
}

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "") {
console.log(await this.veraxSdk.schema.findBy(2, 0, { description: "Gitcoin Passport Score" }, "name", "desc"));
console.log(await this.veraxSdk.schema.findBy(2, 0, { description: "Gitcoin Passport score" }, "name", "desc"));
}

if (methodName.toLowerCase() == "findByMultiChain".toLowerCase() || methodName == "") {
const filter: Schema_filter | undefined =
argv !== "" ? JSON.parse(argv) : { description: "Gitcoin Passport score" };
console.log(
await this.veraxSdk.schema.findByMultiChain(
[ChainName.LINEA_MAINNET, ChainName.ARBITRUM_MAINNET],
2,
0,
filter,
undefined,
undefined,
),
);
}

if (methodName.toLowerCase() == "simulateUpdateRouter".toLowerCase() || methodName == "") {
Expand Down
36 changes: 19 additions & 17 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@verax-attestation-registry/verax-sdk",
"version": "2.0.1",
"version": "3.0.0-beta-1",
"description": "Verax Attestation Registry SDK to interact with the subgraph and the contracts",
"keywords": [
"linea-attestation-registry",
Expand Down Expand Up @@ -38,32 +38,34 @@
"test:unit:ci": "cp .env.example .env && pnpm run test:unit"
},
"dependencies": {
"@graphql-mesh/cache-localforage": "^0.95.8",
"@graphql-mesh/cross-helpers": "^0.4.1",
"@graphql-mesh/graphql": "^0.95.8",
"@graphql-mesh/http": "^0.96.14",
"@graphql-mesh/merger-bare": "^0.95.8",
"@graphql-mesh/runtime": "^0.96.13",
"@graphql-mesh/store": "^0.95.8",
"@graphql-mesh/utils": "^0.95.8",
"@whatwg-node/fetch": "^0.9.14",
"@graphprotocol/client-add-source-name": "^2.0.7",
"@graphql-mesh/cache-localforage": "^0.102.5",
"@graphql-mesh/cross-helpers": "^0.4.6",
"@graphql-mesh/graphql": "^0.102.6",
"@graphql-mesh/http": "^0.103.6",
"@graphql-mesh/merger-bare": "^0.102.5",
"@graphql-mesh/runtime": "^0.103.6",
"@graphql-mesh/store": "^0.102.5",
"@graphql-mesh/utils": "^0.102.5",
"@graphql-yoga/plugin-persisted-operations": "^3.7.0",
"@whatwg-node/fetch": "^0.9.21",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"graphql": "^16.8.1",
"graphql": "16.9.0",
"viem": "^2.9.26"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@graphprotocol/client-cli": "^3.0.0",
"@babel/plugin-transform-runtime": "^7.25.4",
"@babel/preset-env": "^7.25.4",
"@babel/preset-typescript": "^7.24.7",
"@graphprotocol/client-cli": "^3.0.7",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"@types/node": "^18.16.20",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "5.4.5"
"typescript": "5.5.4"
}
}
Loading