diff --git a/.github/workflows/ci-default.yml b/.github/workflows/ci-default.yml index 9324c105..5855441f 100644 --- a/.github/workflows/ci-default.yml +++ b/.github/workflows/ci-default.yml @@ -16,7 +16,7 @@ env: NEXT_PUBLIC_SUPABASE_TABLE: ${{ vars.NEXT_PUBLIC_SUPABASE_TABLE }} NEXT_PUBLIC_WALLETCONNECT_ID: ${{ secrets.NEXT_PUBLIC_WALLETCONNECT_ID }} INFURA_API_KEY: ${{ vars.INFURA_API_KEY }} - ALCHEMY_API_KEY: ${{ vars.ALCHEMY_API_KEY }} + ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }} DOCKER_PLATFORM: "amd64" # Trigger the workflow when: diff --git a/sdk/codegen.yml b/sdk/codegen.yml index 35ccfa4a..410b854e 100644 --- a/sdk/codegen.yml +++ b/sdk/codegen.yml @@ -2,7 +2,7 @@ generates: ./src/indexer/gql/: documents: - ./src/indexer/**/*.graphql - schema: https://staging-api.hypercerts.org/graphql + schema: https://staging-api.hypercerts.org/v1/graphql preset: client presetConfig: typesPrefix: I diff --git a/sdk/package.json b/sdk/package.json index 0c8175f8..85b31b1d 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@hypercerts-org/sdk", - "version": "2.0.0-alpha.11", + "version": "2.0.0-alpha.12", "description": "SDK for hypercerts protocol", "repository": "git@github.com:hypercerts-org/hypercerts.git", "author": "Hypercerts team", diff --git a/sdk/src/constants.ts b/sdk/src/constants.ts index 19bcef90..1f526a1e 100644 --- a/sdk/src/constants.ts +++ b/sdk/src/constants.ts @@ -5,7 +5,7 @@ import { Deployment, IndexerEnvironment, SupportedChainIds } from "./types"; import { deployments } from "@hypercerts-org/contracts"; -const DEFAULT_GRAPH_BASE_URL = "https://staging-api.hypercerts.org/graphql"; +const DEFAULT_GRAPH_BASE_URL = "https://staging-api.hypercerts.org/v1/graphql"; export const DEFAULT_INDEXER_ENVIRONMENT: IndexerEnvironment = "all"; // The APIs we expose @@ -19,9 +19,9 @@ const ENDPOINTS: { [key: string]: string } = { // TODO when rolled out to production, enable both testing and prod environments with the correct URLs const GRAPHS: { [key in IndexerEnvironment]: string } = { - all: "https://staging-api.hypercerts.org/graphql", - test: "https://staging-api.hypercerts.org/graphql", - production: "https://staging-api.hypercerts.org/graphql", + all: "https://api.hypercerts.org/v1/graphql", + test: "https://staging-api.hypercerts.org/v1/graphql", + production: "https://api.hypercerts.org/v1/graphql", }; // These are the deployments we manage diff --git a/sdk/src/indexer/gql/gql.ts b/sdk/src/indexer/gql/gql.ts index 8a8a626a..c17034d9 100644 --- a/sdk/src/indexer/gql/gql.ts +++ b/sdk/src/indexer/gql/gql.ts @@ -15,7 +15,7 @@ import { TypedDocumentNode as DocumentNode } from "@graphql-typed-document-node/ const documents = { 'query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) {\n fractions(\n where: {owner_address: {eq: $owner}}\n count: COUNT\n first: $first\n offset: $offset\n ) {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}\n\nquery FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $hypercertId}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n units\n uri\n fractions {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n }\n }\n}\n\nquery FractionById($fractionId: ID!) {\n fractions(where: {hypercert_id: {eq: $fractionId}}) {\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}': types.FractionsByOwnerDocument, - 'query HypercertsByOwner($owner: String = "", $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $owner}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n first: $first\n offset: $offset\n sort: {by: {creation_block_timestamp: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery HypercertById($id: String!) {\n hypercerts(count: COUNT, where: {hypercert_id: {eq: $id}}) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}': + 'query HypercertsByOwner($owner: String = "", $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $owner}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n first: $first\n offset: $offset\n sort: {by: {block_number: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery HypercertById($id: String!) {\n hypercerts(count: COUNT, where: {hypercert_id: {eq: $id}}) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}': types.HypercertsByOwnerDocument, }; @@ -43,8 +43,8 @@ export function graphql( * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: 'query HypercertsByOwner($owner: String = "", $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $owner}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n first: $first\n offset: $offset\n sort: {by: {creation_block_timestamp: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery HypercertById($id: String!) {\n hypercerts(count: COUNT, where: {hypercert_id: {eq: $id}}) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}', -): (typeof documents)['query HypercertsByOwner($owner: String = "", $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $owner}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n first: $first\n offset: $offset\n sort: {by: {creation_block_timestamp: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery HypercertById($id: String!) {\n hypercerts(count: COUNT, where: {hypercert_id: {eq: $id}}) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}']; + source: 'query HypercertsByOwner($owner: String = "", $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $owner}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n first: $first\n offset: $offset\n sort: {by: {block_number: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery HypercertById($id: String!) {\n hypercerts(count: COUNT, where: {hypercert_id: {eq: $id}}) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}', +): (typeof documents)['query HypercertsByOwner($owner: String = "", $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $owner}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n first: $first\n offset: $offset\n sort: {by: {block_number: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery HypercertById($id: String!) {\n hypercerts(count: COUNT, where: {hypercert_id: {eq: $id}}) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}']; export function graphql(source: string) { return (documents as any)[source] ?? {}; diff --git a/sdk/src/indexer/gql/graphql.ts b/sdk/src/indexer/gql/graphql.ts index 53b323b6..a76dc323 100644 --- a/sdk/src/indexer/gql/graphql.ts +++ b/sdk/src/indexer/gql/graphql.ts @@ -138,10 +138,9 @@ export type BasicFractionWhereInput = { }; export type BasicHypercertWhereInput = { - creation_block_timestamp?: InputMaybe; + block_number?: InputMaybe; hypercert_id?: InputMaybe; id?: InputMaybe; - last_block_update_timestamp?: InputMaybe; owner_address?: InputMaybe; token_id?: InputMaybe; uri?: InputMaybe; @@ -163,6 +162,11 @@ export type BasicMetadataWhereInput = { work_timeframe_to?: InputMaybe; }; +export type BasicOrderWhereInput = { + chain_id?: InputMaybe; + id?: InputMaybe; +}; + export type BooleanSearchOptions = { eq?: InputMaybe; }; @@ -199,6 +203,7 @@ export type Fraction = { hypercert_id?: Maybe; id: Scalars["ID"]["output"]; last_block_update_timestamp?: Maybe; + orders?: Maybe; owner_address?: Maybe; units?: Maybe; }; @@ -255,17 +260,24 @@ export type GetHypercertsResponse = { data?: Maybe>; }; +export type GetOrdersResponse = { + __typename?: "GetOrdersResponse"; + count?: Maybe; + data?: Maybe>; +}; + export type Hypercert = { __typename?: "Hypercert"; attestations?: Maybe; + block_number?: Maybe; contract?: Maybe; contracts_id?: Maybe; - creation_block_timestamp?: Maybe; fractions?: Maybe; hypercert_id?: Maybe; id: Scalars["ID"]["output"]; last_block_update_timestamp?: Maybe; metadata?: Maybe; + orders?: Maybe; owner_address?: Maybe; token_id?: Maybe; units?: Maybe; @@ -277,8 +289,8 @@ export type HypercertFetchInput = { }; export type HypercertSortOptions = { + block_number?: InputMaybe; claim_attestation_count?: InputMaybe; - creation_block_timestamp?: InputMaybe; hypercert_id?: InputMaybe; last_block_update_timestamp?: InputMaybe; owner_address?: InputMaybe; @@ -289,12 +301,11 @@ export type HypercertSortOptions = { export type HypercertsWhereInput = { attestations?: InputMaybe; + block_number?: InputMaybe; contract?: InputMaybe; - creation_block_timestamp?: InputMaybe; fractions?: InputMaybe; hypercert_id?: InputMaybe; id?: InputMaybe; - last_block_update_timestamp?: InputMaybe; metadata?: InputMaybe; owner_address?: InputMaybe; token_id?: InputMaybe; @@ -342,10 +353,9 @@ export type MetadataSortOptions = { }; export type MetadataWhereInput = { - creation_block_timestamp?: InputMaybe; + block_number?: InputMaybe; hypercert_id?: InputMaybe; id?: InputMaybe; - last_block_update_timestamp?: InputMaybe; metadata?: InputMaybe; owner_address?: InputMaybe; token_id?: InputMaybe; @@ -360,6 +370,33 @@ export type NumberSearchOptions = { lte?: InputMaybe; }; +export type Order = { + __typename?: "Order"; + additionalParameters: Scalars["String"]["output"]; + amounts: Array; + chainId: Scalars["BigInt"]["output"]; + collection: Scalars["String"]["output"]; + collectionType: Scalars["Float"]["output"]; + createdAt: Scalars["String"]["output"]; + currency: Scalars["String"]["output"]; + endTime: Scalars["Float"]["output"]; + globalNonce: Scalars["String"]["output"]; + id: Scalars["ID"]["output"]; + itemIds: Array; + orderNonce: Scalars["String"]["output"]; + price: Scalars["String"]["output"]; + quoteType: Scalars["Float"]["output"]; + signature: Scalars["String"]["output"]; + signer: Scalars["String"]["output"]; + startTime: Scalars["Float"]["output"]; + strategyId: Scalars["Float"]["output"]; + subsetNonce: Scalars["Float"]["output"]; +}; + +export type OrderFetchInput = { + by?: InputMaybe; +}; + export type Query = { __typename?: "Query"; attestationSchemas: GetAttestationsSchemaResponse; @@ -368,6 +405,7 @@ export type Query = { fractions: GetFractionsResponse; hypercerts: GetHypercertsResponse; metadata: Array; + orders: GetOrdersResponse; }; export type QueryAttestationSchemasArgs = { @@ -418,6 +456,14 @@ export type QueryMetadataArgs = { where?: InputMaybe; }; +export type QueryOrdersArgs = { + count?: InputMaybe; + first?: InputMaybe; + offset?: InputMaybe; + sort?: InputMaybe; + where?: InputMaybe; +}; + /** The direction to sort the query results */ export enum SortOrder { /** Ascending order */ @@ -1092,7 +1138,7 @@ export const RecentHypercertsDocument = { fields: [ { kind: "ObjectField", - name: { kind: "Name", value: "creation_block_timestamp" }, + name: { kind: "Name", value: "block_number" }, value: { kind: "Variable", name: { kind: "Name", value: "orderDirection" } }, }, ], diff --git a/sdk/src/indexer/queries/hypercerts.graphql b/sdk/src/indexer/queries/hypercerts.graphql index b268032b..751004b5 100644 --- a/sdk/src/indexer/queries/hypercerts.graphql +++ b/sdk/src/indexer/queries/hypercerts.graphql @@ -24,7 +24,7 @@ query RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 10 count: COUNT first: $first offset: $offset - sort: {by: {creation_block_timestamp: $orderDirection}} + sort: {by: {block_number: $orderDirection}} ) { count data { diff --git a/sdk/src/storage.ts b/sdk/src/storage.ts index 56ae2209..f7aedc5e 100644 --- a/sdk/src/storage.ts +++ b/sdk/src/storage.ts @@ -57,13 +57,15 @@ export class HypercertsStorage implements HypercertStorageInterface { config, ); - if (!resData.data?.cid || (resData.errors && Object.keys(resData.errors).length > 0)) { + if (!resData?.cid || (resData.errors && Object.keys(resData.errors).length > 0)) { throw new StorageError("Failed to store metadata", { errors: resData.errors, data }); } - logger.debug(`Stored metadata at ${resData.data?.cid}`); + const { cid } = resData; - return resData.data?.cid; + logger.debug(`Stored metadata at ${cid}`); + + return cid; } /** diff --git a/sdk/test/storage/storeAllowList.test.ts b/sdk/test/storage/storeAllowList.test.ts index fb29cd96..4c385293 100644 --- a/sdk/test/storage/storeAllowList.test.ts +++ b/sdk/test/storage/storeAllowList.test.ts @@ -42,7 +42,7 @@ describe("Storage - store allowlist", () => { }, ]; - mocks.uploadAllowlist.mockResolvedValue({ data: { cid: someData.cid } }); + mocks.uploadAllowlist.mockResolvedValue({ cid: someData.cid }); const res = await storage.storeAllowList(allowList, 100n); expect(res).to.eq(someData.cid); expect(mocks.uploadAllowlist).toHaveBeenCalledTimes(1); diff --git a/sdk/test/storage/storeMetadata.test.ts b/sdk/test/storage/storeMetadata.test.ts index bb339127..336e2072 100644 --- a/sdk/test/storage/storeMetadata.test.ts +++ b/sdk/test/storage/storeMetadata.test.ts @@ -33,7 +33,7 @@ describe("Storage - store metadata", () => { }); it("Store metadata", async () => { - mocks.uploadMetadata.mockResolvedValue({ data: { cid: hypercertMetadata.cid } }); + mocks.uploadMetadata.mockResolvedValue({ cid: hypercertMetadata.cid }); const res = await storage.storeMetadata(hypercertMetadata.data); expect(res).to.eq(hypercertMetadata.cid); expect(mocks.uploadMetadata).toHaveBeenCalledTimes(1);