Skip to content

Commit

Permalink
feat(sdk): update api, graph, contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers committed Jun 7, 2024
1 parent fd41759 commit 2f6c788
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion sdk/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/indexer/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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] ?? {};
Expand Down
64 changes: 55 additions & 9 deletions sdk/src/indexer/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ export type BasicFractionWhereInput = {
};

export type BasicHypercertWhereInput = {
creation_block_timestamp?: InputMaybe<NumberSearchOptions>;
block_number?: InputMaybe<NumberSearchOptions>;
hypercert_id?: InputMaybe<StringSearchOptions>;
id?: InputMaybe<IdSearchOptions>;
last_block_update_timestamp?: InputMaybe<NumberSearchOptions>;
owner_address?: InputMaybe<StringSearchOptions>;
token_id?: InputMaybe<NumberSearchOptions>;
uri?: InputMaybe<StringSearchOptions>;
Expand All @@ -163,6 +162,11 @@ export type BasicMetadataWhereInput = {
work_timeframe_to?: InputMaybe<NumberSearchOptions>;
};

export type BasicOrderWhereInput = {
chain_id?: InputMaybe<NumberSearchOptions>;
id?: InputMaybe<IdSearchOptions>;
};

export type BooleanSearchOptions = {
eq?: InputMaybe<Scalars["Boolean"]["input"]>;
};
Expand Down Expand Up @@ -199,6 +203,7 @@ export type Fraction = {
hypercert_id?: Maybe<Scalars["ID"]["output"]>;
id: Scalars["ID"]["output"];
last_block_update_timestamp?: Maybe<Scalars["BigInt"]["output"]>;
orders?: Maybe<GetOrdersResponse>;
owner_address?: Maybe<Scalars["String"]["output"]>;
units?: Maybe<Scalars["EthBigInt"]["output"]>;
};
Expand Down Expand Up @@ -255,17 +260,24 @@ export type GetHypercertsResponse = {
data?: Maybe<Array<Hypercert>>;
};

export type GetOrdersResponse = {
__typename?: "GetOrdersResponse";
count?: Maybe<Scalars["Int"]["output"]>;
data?: Maybe<Array<Order>>;
};

export type Hypercert = {
__typename?: "Hypercert";
attestations?: Maybe<GetAttestationsResponse>;
block_number?: Maybe<Scalars["BigInt"]["output"]>;
contract?: Maybe<Contract>;
contracts_id?: Maybe<Scalars["ID"]["output"]>;
creation_block_timestamp?: Maybe<Scalars["BigInt"]["output"]>;
fractions?: Maybe<GetFractionsResponse>;
hypercert_id?: Maybe<Scalars["ID"]["output"]>;
id: Scalars["ID"]["output"];
last_block_update_timestamp?: Maybe<Scalars["BigInt"]["output"]>;
metadata?: Maybe<Metadata>;
orders?: Maybe<GetOrdersResponse>;
owner_address?: Maybe<Scalars["String"]["output"]>;
token_id?: Maybe<Scalars["EthBigInt"]["output"]>;
units?: Maybe<Scalars["EthBigInt"]["output"]>;
Expand All @@ -277,8 +289,8 @@ export type HypercertFetchInput = {
};

export type HypercertSortOptions = {
block_number?: InputMaybe<SortOrder>;
claim_attestation_count?: InputMaybe<SortOrder>;
creation_block_timestamp?: InputMaybe<SortOrder>;
hypercert_id?: InputMaybe<SortOrder>;
last_block_update_timestamp?: InputMaybe<SortOrder>;
owner_address?: InputMaybe<SortOrder>;
Expand All @@ -289,12 +301,11 @@ export type HypercertSortOptions = {

export type HypercertsWhereInput = {
attestations?: InputMaybe<BasicAttestationWhereInput>;
block_number?: InputMaybe<NumberSearchOptions>;
contract?: InputMaybe<BasicContractWhereInput>;
creation_block_timestamp?: InputMaybe<NumberSearchOptions>;
fractions?: InputMaybe<BasicFractionWhereInput>;
hypercert_id?: InputMaybe<StringSearchOptions>;
id?: InputMaybe<IdSearchOptions>;
last_block_update_timestamp?: InputMaybe<NumberSearchOptions>;
metadata?: InputMaybe<BasicMetadataWhereInput>;
owner_address?: InputMaybe<StringSearchOptions>;
token_id?: InputMaybe<NumberSearchOptions>;
Expand Down Expand Up @@ -342,10 +353,9 @@ export type MetadataSortOptions = {
};

export type MetadataWhereInput = {
creation_block_timestamp?: InputMaybe<NumberSearchOptions>;
block_number?: InputMaybe<NumberSearchOptions>;
hypercert_id?: InputMaybe<StringSearchOptions>;
id?: InputMaybe<IdSearchOptions>;
last_block_update_timestamp?: InputMaybe<NumberSearchOptions>;
metadata?: InputMaybe<BasicMetadataWhereInput>;
owner_address?: InputMaybe<StringSearchOptions>;
token_id?: InputMaybe<NumberSearchOptions>;
Expand All @@ -360,6 +370,33 @@ export type NumberSearchOptions = {
lte?: InputMaybe<Scalars["BigInt"]["input"]>;
};

export type Order = {
__typename?: "Order";
additionalParameters: Scalars["String"]["output"];
amounts: Array<Scalars["Float"]["output"]>;
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<Scalars["String"]["output"]>;
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<ContractSortOptions>;
};

export type Query = {
__typename?: "Query";
attestationSchemas: GetAttestationsSchemaResponse;
Expand All @@ -368,6 +405,7 @@ export type Query = {
fractions: GetFractionsResponse;
hypercerts: GetHypercertsResponse;
metadata: Array<Metadata>;
orders: GetOrdersResponse;
};

export type QueryAttestationSchemasArgs = {
Expand Down Expand Up @@ -418,6 +456,14 @@ export type QueryMetadataArgs = {
where?: InputMaybe<MetadataWhereInput>;
};

export type QueryOrdersArgs = {
count?: InputMaybe<CountKeys>;
first?: InputMaybe<Scalars["Int"]["input"]>;
offset?: InputMaybe<Scalars["Int"]["input"]>;
sort?: InputMaybe<OrderFetchInput>;
where?: InputMaybe<BasicOrderWhereInput>;
};

/** The direction to sort the query results */
export enum SortOrder {
/** Ascending order */
Expand Down Expand Up @@ -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" } },
},
],
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/indexer/queries/hypercerts.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions sdk/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/storage/storeAllowList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/storage/storeMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2f6c788

Please sign in to comment.