Skip to content

Commit

Permalink
Feat/allowlist proof util (#1168)
Browse files Browse the repository at this point in the history
* feat(util): allowlist utils and updated docs

* feat(test): updated test and docs

* chore(bump): alpha-7

* feat(merkle): test merkleProof fetcher

* chore(bump): 1.0.0-alpha.8

* fix(import): allowlist default export

* chore(run): local validation run
  • Loading branch information
bitbeckers authored Nov 7, 2023
1 parent 462abfd commit ee250ee
Show file tree
Hide file tree
Showing 22 changed files with 622 additions and 342 deletions.
3 changes: 0 additions & 3 deletions frontend/components/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export function Config(props: ConfigProps) {
? Number(hypercertClient.config.chain.id)
: undefined;

console.log(chainId);
console.log("Config: ", hypercertClient.config);

const data: ConfigData = {
domain: DOMAIN,
chainId: chainId,
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@graphprotocol/client-cli": "^2.2.16",
"@hypercerts-org/contracts": "0.9.0",
"@hypercerts-org/observabletreemap": "workspace: *",
"@hypercerts-org/sdk": "1.0.0-alpha.6",
"@hypercerts-org/sdk": "1.0.0-alpha.8",
"@mui/icons-material": "^5.11.9",
"@mui/material": "^5.11.2",
"@mui/x-date-pickers": "^5.0.12",
Expand Down
2 changes: 1 addition & 1 deletion graph/tests/.latest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.6.0",
"timestamp": 1699280746839
"timestamp": 1699397492586
}
133 changes: 71 additions & 62 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

92 changes: 24 additions & 68 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ import { HypercertClient } from "@hypercerts-org/sdk";
```js
const client = new HypercertClient({
chainId: 5,
provider,
signer,
chain: { id: 5 } // required
nftStorageToken,
web3StorageToken,
});
```
> **Note** If there's no `signer`, `provider`, `nftStorageToken` or `web3StorageToken` provided, the client will run in
> **Note** If there's no `walletClient`, `nftStorageToken` or `web3StorageToken` provided, the client will run in
> [read-only mode](#read-only-mode)
4. Use the client object to interact with the Hypercert network.
Expand Down Expand Up @@ -60,78 +58,36 @@ environment variables for your NFT.storage and web3.storage API keys in your .en
## Config
The SDK will try to determine the `DEFAULT_CHAIN_ID` and use that to inform the configuration. We allow for `overrides`
when creating the SDK by passing configuration variables. Finally, when not defaults or overrides are found, we check
the environment variables.
HypercertClientConfig is a configuration object used when initializing a new instance of the HypercertClient. It allows
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. |
| `nftStorageToken` | String | The API token for NFT.storage. |
| `web3StorageToken` | String | The API token for Web3.storage. |
| `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. |
### Read-only mode
The SDK client will be in read-only mode if any of the following conditions are true:
- The client was initialized without a signer or provider.
- The client was initialized with a provider but not a signer.
- The client was initialized with a signer but not a provider.
- The client was initialized without a walletprovider.
- The contract address is not set.
- The storage layer is in read-only mode.
If any of these conditions are true, the readonly property of the HypercertClient instance will be set to true, and a
warning message will be logged indicating that the client is in read-only mode.
### Defaults
The constants.ts file defines various constants that are used throughout the Hypercert system. Here's a brief
explanation of each constant:
`DEFAULT_CHAIN_ID`: This constant defines the default chain ID to use if no chain ID is specified. In this case, the
default chain ID is set to 5, which corresponds to the Goerli testnet.
Based on `DEFAULT_CHAIN_ID` the SDK will select a `DEPLOYMENT`.
`DEPLOYMENTS`: This constant defines the deployments that are managed by the Hypercert system. Each Deployment object
contains information about a specific deployment, including the chain ID, chain name, contract address, and graph name.
For example:
```json
{
"5": {
"chainId": 5,
"chainName": "goerli",
"contractAddress": "0x822F17A9A5EeCFd66dBAFf7946a8071C265D1d07",
"graphName": "hypercerts-testnet"
}
}
```
### Client config properties
| \| Property | Type | Description |
| ------------------ | -------------------- | -------------------------------------- |
| `chainId` | `number` | The chain ID of the network to use. |
| `chainName` | `string` | The name of the network to use. |
| `contractAddress` | `string` | The address of the Hypercert contract. |
| `rpcUrl` | `string` | The URL of the RPC endpoint to use. |
| `graphName` | `string` | The name of the Gsubgraph to use. |
| `provider` | `providers.Provider` | A custom provider to use. |
| `signer` | `Signer` | A custom signer to use. |
| `nftStorageToken` | `string` | Your NFT.storage API key. |
| `web3StorageToken` | `string` | Your web3.storage API key. |
### Environment variables
To determine the missing configuration values the SDK defaults to the following environment variables:
| Environment Variable | Description |
| -------------------------------- | --------------------------------------------------------------------------------------------------- |
| `DEFAULT_CHAIN_ID` | Specifies the default chain ID to use if no chain ID is specified. |
| `CONTRACT_ADDRESS` | Specifies the contract address to use for the Hypercert protocol. |
| `RPC_URL` | Specifies the RPC URL to use for the evm-compatible network. |
| `PRIVATE_KEY` | Specifies the private key to use for signing transactions. |
| `NFT_STORAGE_TOKEN` | Specifies the NFT.storage API token to use for storing Hypercert metadata. |
| `NEXT_PUBLIC_NFT_STORAGE_TOKEN` | Specifies the NFT.storage API token to use for storing Hypercert metadata in a Next.js application. |
| `WEB3_STORAGE_TOKEN` | Specifies the Web3.storage API token to use for storing Hypercert data. |
| `NEXT_PUBLIC_WEB3_STORAGE_TOKEN` | Specifies the Web3.storage API token to use for storing Hypercert data in a Next.js application. |
### Logging
The logger for the SDK uses the log level based on the value of the LOG_LEVEL environment variable. The log level
Expand All @@ -147,7 +103,7 @@ HypercertIndexer, and HypercertMinter classes, respectively.
```js
const {
client: { storage },
} = new HypercertClient({});
} = new HypercertClient({ chain: { id: 5 } });
```
The `storage` is a utility class that provides methods for storing and retrieving Hypercert metadata on IPFS and
Expand All @@ -156,7 +112,7 @@ NFT.storage. It is used by the HypercertClient to store metadata when creating n
```js
const {
client: { indexer },
} = new HypercertClient({});
} = new HypercertClient({ chain: { id: 5 } });
```
The `indexer` is a utility class that provides methods for indexing and searching Hypercerts based on various criteria.
Expand All @@ -165,7 +121,7 @@ It is used by the HypercertClient to retrieve event-based data via the subgraph
```js
const {
client: { contract },
} = new HypercertClient({});
} = new HypercertClient({ chain: { id: 5 } });
```
Finally we have a `contract` that provides methods for interacting with the HypercertMinter smart contract. It is used
Expand Down
4 changes: 2 additions & 2 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hypercerts-org/sdk",
"version": "1.0.0-alpha.6",
"version": "1.0.0-alpha.8",
"description": "SDK for hypercerts protocol",
"repository": "[email protected]:hypercerts-org/hypercerts.git",
"author": "Hypercerts team",
Expand Down Expand Up @@ -38,7 +38,7 @@
"@graphql-mesh/utils": "^0.95.7",
"@graphql-typed-document-node/core": "^3.2.0",
"@hypercerts-org/contracts": "0.8.11",
"@openzeppelin/merkle-tree": "^1.0.4",
"@openzeppelin/merkle-tree": "^1.0.5",
"@whatwg-node/fetch": "^0.9.13",
"ajv": "^8.11.2",
"axios": "^1.2.2",
Expand Down
Loading

0 comments on commit ee250ee

Please sign in to comment.