Skip to content

Commit

Permalink
(feat): add support for passing allowlist by uri, parsing and inserting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jipperism committed Jul 7, 2024
1 parent cee148d commit f21c10a
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 18 deletions.
Binary file added graph/tests/.bin/hypercert-minter-allowlist.wasm
Binary file not shown.
Binary file added graph/tests/.bin/hypercert-minter-burn.wasm
Binary file not shown.
Binary file added graph/tests/.bin/hypercert-minter-claim.wasm
Binary file not shown.
Binary file added graph/tests/.bin/hypercert-minter-fraction.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion sdk/lib/hypercerts-api
Submodule hypercerts-api updated 48 files
+3 −1 .env.template
+1 −0 .gitmodules
+3 −0 .prettierignore
+1 −0 .prettierrc
+1 −1 lib/hypercerts-indexer
+10 −10 package.json
+536 −374 pnpm-lock.yaml
+133 −34 schema.graphql
+2 −2 src/__generated__/routes/routes.ts
+2 −2 src/__generated__/swagger.json
+44 −35 src/client/graphql.ts
+6 −0 src/client/hypercerts.ts
+1 −1 src/client/supabase.ts
+0 −1 src/controllers/AllowListController.ts
+5 −13 src/controllers/MarketplaceController.ts
+17 −0 src/graphql/schemas/args/salesArgs.ts
+2 −0 src/graphql/schemas/inputs/allowlistRecordsInput.ts
+8 −3 src/graphql/schemas/inputs/attestationInput.ts
+11 −7 src/graphql/schemas/inputs/collectionInput.ts
+15 −9 src/graphql/schemas/inputs/fractionInput.ts
+13 −7 src/graphql/schemas/inputs/hypercertsInput.ts
+19 −0 src/graphql/schemas/inputs/saleOptions.ts
+28 −0 src/graphql/schemas/inputs/salesInput.ts
+29 −29 src/graphql/schemas/inputs/searchOptions.ts
+26 −7 src/graphql/schemas/inputs/sortOptions.ts
+37 −39 src/graphql/schemas/resolvers/allowlistRecordResolver.ts
+7 −4 src/graphql/schemas/resolvers/attestationResolver.ts
+20 −18 src/graphql/schemas/resolvers/composed.ts
+62 −12 src/graphql/schemas/resolvers/fractionResolver.ts
+375 −309 src/graphql/schemas/resolvers/hypercertResolver.ts
+46 −0 src/graphql/schemas/resolvers/salesResolver.ts
+9 −4 src/graphql/schemas/typeDefs/allowlistRecordTypeDefs.ts
+2 −2 src/graphql/schemas/typeDefs/attestationSchemaTypeDefs.ts
+32 −25 src/graphql/schemas/typeDefs/attestationTypeDefs.ts
+14 −14 src/graphql/schemas/typeDefs/collectionTypeDefs.ts
+3 −3 src/graphql/schemas/typeDefs/contractTypeDefs.ts
+46 −13 src/graphql/schemas/typeDefs/fractionTypeDefs.ts
+81 −47 src/graphql/schemas/typeDefs/hypercertTypeDefs.ts
+9 −8 src/graphql/schemas/typeDefs/metadataTypeDefs.ts
+2 −2 src/graphql/schemas/typeDefs/orderTypeDefs.ts
+41 −0 src/graphql/schemas/typeDefs/salesTypeDefs.ts
+3 −4 src/index.ts
+26 −4 src/services/SupabaseCachingService.ts
+655 −68 src/types/graphql-env.d.ts
+130 −50 src/types/supabaseCaching.ts
+5 −0 src/utils/constants.ts
+29 −0 src/utils/getFractionsById.ts
+3 −0 supabase/migrations/20240623104303_add_validation_column_to_marketplace_orders.sql
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.28",
"version": "2.0.0-alpha.29",
"description": "SDK for hypercerts protocol",
"repository": "git@github.com:hypercerts-org/hypercerts.git",
"author": "Hypercerts team",
Expand Down
28 changes: 14 additions & 14 deletions sdk/src/__generated__/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ParserReturnType } from "./utils/txParser";
import { isClaimOnChain } from "./utils/chains";
import { StoreAllowList201AnyOfTwoData, StoreMetadata201AnyOf } from "./__generated__/api";
import { HypercertStorage } from "./types/storage";
import { fetchFromHttpsOrIpfs } from "./utils/fetchers";

/**
* The `HypercertClient` is a core class in the hypercerts SDK, providing a high-level interface to interact with the hypercerts system.
Expand Down Expand Up @@ -128,7 +129,38 @@ export class HypercertClient implements HypercertClientInterface {
let root;

if (allowList) {
const tree = parseAllowListEntriesToMerkleTree(allowList);
let allowListEntries: AllowlistEntry[] = [];
if (typeof allowList === "string") {
// fetch the csv contents
const csvContents = await fetchFromHttpsOrIpfs(allowList);

if (!csvContents) {
throw new ClientError("No contents found in the csv", { allowList });
}

if (typeof csvContents !== "string") {
throw new ClientError("Invalid contents found in the csv", { allowList });
}
// parse the csv contents into an array of AllowlistEntry
// get first row as headers
const headers = (csvContents as string).split("\n")[0].split(",");
// map headers onto other rows
const rows = (csvContents as string)
.split("\n")
.slice(1)
.map((row) => {
const values = row.split(",");
return Object.fromEntries(headers.map((header, i) => [header, values[i]]));
});
allowListEntries = rows.map((entry) => {
const { address, units } = entry;
return { address, units: BigInt(units) };
});
} else {
allowListEntries = allowList;
}

const tree = parseAllowListEntriesToMerkleTree(allowListEntries);

// store allowlist on IPFS
const allowlistStoreRes = await this.storage.storeAllowlist(
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface MintParams extends TransactionParams {
metaData: HypercertMetadata;
totalUnits: bigint;
transferRestriction: TransferRestrictions;
allowList?: AllowlistEntry[];
allowList?: AllowlistEntry[] | string;
}

export interface TransferParams extends TransactionParams {
Expand Down
43 changes: 43 additions & 0 deletions sdk/src/utils/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,46 @@ const getWeb3UpGatewayUri = (cidOrIpfsUri: string) => {
};

export { getFromIPFS };

export const fetchFromHTTPS = async ({ uri }: { uri: string }) => {
// URL validation
const url = new URL(uri);
try {
const res = await axios.get(url.toString());

if (!res || !res.data) {
return;
}

return res.data;
} catch (error) {
console.error(`Failed to get metadata from URI ${uri} `, error);
return;
}
};

export const fetchFromHttpsOrIpfs = async (uri?: string): Promise<unknown> => {
if (!uri || uri === "ipfs://null" || uri === "ipfs://") {
console.error("[fetchFromHttpsOrIpfs] URI is missing");
return;
}

let fetchResult;

// Try from IPFS
if (uri.startsWith("ipfs://")) {
fetchResult = await getFromIPFS(uri);
}

// Try from HTTPS
if (uri.startsWith("https://")) {
fetchResult = await fetchFromHTTPS({ uri });
}

// If nothing found yet, try from IPFS as CID
if (!fetchResult) {
fetchResult = await getFromIPFS(uri);
}

return fetchResult;
};

0 comments on commit f21c10a

Please sign in to comment.