Skip to content

Commit

Permalink
Feature/multi chain support (#1301)
Browse files Browse the repository at this point in the history
* (feat): add support for querying from multiple chains at the same time

* (feat): refactor parseClaimId to standalone utility method, add sql update script for claimIds in supabase

* (feat): update autotask scripts

* (feat): add is claim on connected chain utility method

* (feat): update tests and docs

* (feat): set default indexer environment to all

* (fix): revert auto-task updates
  • Loading branch information
Jipperism authored Apr 15, 2024
1 parent b1a0979 commit 52ea602
Show file tree
Hide file tree
Showing 19 changed files with 331 additions and 213 deletions.
49 changes: 27 additions & 22 deletions pnpm-lock.yaml

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

10 changes: 10 additions & 0 deletions scripts/update-claimids-in-supabase-to-multichain.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
update "allowlistCache-chainId" set "claimId" = concat("chainId", '-', "claimId");
update "allowlistCache-optimism" set "claimId" = concat('10', '-', "claimId");
update "allowlistCache-goerli" set "claimId" = concat('5', '-', "claimId");
update "allowlistCache-sepolia" set "claimId" = concat('11155111', '-', "claimId");

update "claims-metadata-mapping" set "claimId" = concat("chainId", '-', "claimId");

update "collections" set "claimId" = concat("chainId", '-', "claimId");

update "zuzalu-community-hypercerts" set "claimId" = concat("chainId", '-', "claimId");
24 changes: 12 additions & 12 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ HypercertClientConfig is a configuration object used when initializing a new ins
you to customize the client by setting your own providers or deployments. At it's simplest, you only need to provide
`chain.id` to initalize the client in `readonly` mode.
| Field | Type | Description |
| --------------------------- | ------- | ---------------------------------------------------------------------------------------------- |
| `chain` | Object | Partial configuration for the blockchain network. |
| `contractAddress` | String | The address of the deployed contract. |
| `graphUrl` | String | The URL to the subgraph that indexes the contract events. Override for localized testing. |
| `graphName` | String | The name of the subgraph. |
| `easContractAddress` | String | The address of the EAS contract. |
| `publicClient` | Object | The PublicClient is inherently read-only and is used for reading data from the blockchain. |
| `walletClient` | Object | The WalletClient is used for signing and sending transactions. |
| `unsafeForceOverrideConfig` | Boolean | Boolean to force the use of overridden values. |
| `readOnly` | Boolean | Boolean to assert if the client is in read-only mode. |
| `readOnlyReason` | String | Reason for read-only mode. This is optional and can be used for logging or debugging purposes. |
| Field | Type | Description |
| --------------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------- |
| `chain` | Object | Partial configuration for the blockchain network. |
| `contractAddress` | String | The address of the deployed contract. |
| `graphName` | String | The name of the subgraph. |
| `easContractAddress` | String | The address of the EAS contract. |
| `publicClient` | Object | The PublicClient is inherently read-only and is used for reading data from the blockchain. |
| `walletClient` | Object | The WalletClient is used for signing and sending transactions. |
| `unsafeForceOverrideConfig` | Boolean | Boolean to force the use of overridden values. |
| `readOnly` | Boolean | Boolean to assert if the client is in read-only mode. |
| `readOnlyReason` | String | Reason for read-only mode. This is optional and can be used for logging or debugging purposes. |
| `indexerEnvironment` | `'test' \| 'production' \| 'all'` | Determines which graphs should be read out when querying | The environment of the indexer. |
### Read-only mode
Expand Down
8 changes: 5 additions & 3 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hypercerts-org/sdk",
"version": "1.5.0",
"version": "2.0.0-alpha.5",
"description": "SDK for hypercerts protocol",
"repository": "git@github.com:hypercerts-org/hypercerts.git",
"author": "Hypercerts team",
Expand All @@ -26,16 +26,18 @@
"@graphql-typed-document-node/core": "^3.2.0",
"@hypercerts-org/contracts": "1.1.2",
"@openzeppelin/merkle-tree": "^1.0.5",
"@urql/core": "^4.2.0",
"@urql/core": "^4.3.0",
"@whatwg-node/fetch": "^0.9.13",
"ajv": "^8.11.2",
"axios": "^1.6.2",
"dotenv": "^16.0.3",
"ethers": "5.7.2",
"fast-deep-equal": "^3.1.3",
"graphql": "^16.8.1",
"loglevel": "^1.8.1",
"urql": "^4.0.6",
"viem": "^2.9.4"
"viem": "^2.9.4",
"wonka": "^6.3.4"
},
"devDependencies": {
"@babel/core": "^7.23.5",
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { parseAllowListEntriesToMerkleTree } from "./utils/allowlist";
import { DEPLOYMENTS } from "./constants";
import { getClaimStoredDataFromTxHash } from "./utils";
import { ParserReturnType } from "./utils/txParser";
import { isClaimOnChain } from "./utils/chains";

/**
* 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 @@ -75,6 +76,11 @@ export class HypercertClient implements HypercertClientInterface {
}
}

isClaimOrFractionOnConnectedChain = (claimOrFractionId: string) => {
const connectedChain = this._walletClient?.chain?.id;
return isClaimOnChain(claimOrFractionId, connectedChain);
};

/**
* Gets the config for the client.
* @returns The client config.
Expand Down
10 changes: 8 additions & 2 deletions sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* Constants
*/

import { Deployment, SupportedChainIds } from "./types";
import { Deployment, IndexerEnvironment, SupportedChainIds } from "./types";
import { deployments } from "@hypercerts-org/contracts";

const DEFAULT_GRAPH_BASE_URL = "https://api.thegraph.com/subgraphs/name/hypercerts-admin";
const DEFAULT_GRAPH_BASE_URL = "https://api.thegraph.com/subgraphs/name/hypercerts-org";
export const DEFAULT_INDEXER_ENVIRONMENT: IndexerEnvironment = "all";

// The APIs we expose

Expand All @@ -20,26 +21,31 @@ const DEPLOYMENTS: { [key in SupportedChainIds]: Partial<Deployment> } = {
addresses: deployments[10],
graphName: "hypercerts-optimism-mainnet",
graphUrl: `${DEFAULT_GRAPH_BASE_URL}/hypercerts-optimism-mainnet`,
isTestnet: false,
} as const,
42220: {
addresses: deployments[42220],
graphName: "hypercerts-celo",
graphUrl: `${DEFAULT_GRAPH_BASE_URL}/hypercerts-celo`,
isTestnet: false,
},
11155111: {
addresses: deployments[11155111],
graphName: "hypercerts-sepolia",
graphUrl: `${DEFAULT_GRAPH_BASE_URL}/hypercerts-sepolia`,
isTestnet: true,
} as const,
84532: {
addresses: deployments[84532],
graphName: "hypercerts-base-sepolia",
graphUrl: `${DEFAULT_GRAPH_BASE_URL}/hypercerts-base-sepolia`,
isTestnet: true,
} as const,
8453: {
addresses: deployments[8453],
graphName: "hypercerts-base-mainnet",
graphUrl: `${DEFAULT_GRAPH_BASE_URL}/hypercerts-base-mainnet`,
isTestnet: false,
} as const,
};

Expand Down
Loading

0 comments on commit 52ea602

Please sign in to comment.