Skip to content

Commit

Permalink
Merge pull request #1243 from hypercerts-org/chore/main-to-develop
Browse files Browse the repository at this point in the history
Chore/main to develop
  • Loading branch information
Jipperism authored Dec 15, 2023
2 parents dc04f74 + 0182b2e commit 1a3b8d8
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[gha]: https://github.com/hypercerts-org/hypercerts/actions/workflows/ci-default.yml
[gha-badge]: https://github.com/hypercerts-org/hypercerts/actions/workflows/ci-default.yml/badge.svg

Hypercerts are a tool to build scalable retrospective reward systems for impact.
Hypercerts is a tool to build scalable retrospective reward systems for impact.
For more details, check out our [website](https://hypercerts.org/).

## Organization
Expand Down Expand Up @@ -51,7 +51,7 @@ Take a look at `./frontend/.env.local.example` for the complete list.
- You can either set these yourself (e.g. in CI/CD)
- or copy the file to `.env.local` and populate it.

Then the do a turbo build of all apps, run the following:
Then do a turbo build of all apps, run the following:

```bash
yarn install
Expand Down Expand Up @@ -81,7 +81,7 @@ have docker and docker compose installed.

### Setup environment variables

You will then need to create a `.env.local` file in the root of the repository with at the following environment variables:
You will then need to create a `.env.local` file in the root of the repository with the following environment variables:

```
# Required
Expand All @@ -103,7 +103,7 @@ Once you have your environment configured you can run the infrastructure like so
yarn dev:serve-e2e
```

Once everything is the dapp will be served from http://127.0.0.1:3000. You will
Once everything is done, the dapp will be served from http://127.0.0.1:3000. You will
need to point your metamask to the localchain at 127.0.0.1:8545 with ChainID 31337.

## Playbooks
Expand Down
6 changes: 5 additions & 1 deletion defender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@
"deploy:test": "pnpm build && pnpm setup:test",
"deploy:prod": "pnpm build && pnpm setup:prod",
"setup:test": "npx tsx src/setup.ts TEST",
"setup:prod": "npx tsx src/setup.ts PROD"
"setup:prod": "npx tsx src/setup.ts PROD",
"scripts:fix-allowlist-duplicates": "npx tsx src/scripts/fix-allowlist-duplicates.ts"
},
"dependencies": {
"@graphql-mesh/cache-localforage": "^0.95.7",
"@hypercerts-org/contracts": "0.8.11",
"@openzeppelin/defender-autotask-client": "1.50.0",
"@openzeppelin/defender-autotask-utils": "1.50.0",
"@openzeppelin/defender-base-client": "1.49.0",
"@openzeppelin/defender-sentinel-client": "1.49.0",
"@openzeppelin/merkle-tree": "^1.0.2",
"@supabase/supabase-js": "^2.4.1",
"@types/lodash": "^4.14.199",
"axios": "^1.2.6",
"dotenv": "^16.0.3",
"ethers": "5.7.2",
"lodash": "^4.17.21",
"node-fetch": "^3.3.0"
},
"devDependencies": {
Expand Down
129 changes: 129 additions & 0 deletions defender/src/scripts/fix-allowlist-duplicates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// const supabaseLib = require("@supabase/supabase-js");
// const dotenv = require("dotenv");
// const _ = require("lodash");
// import * as fetch from "node-fetch";
// const hypercertsSDK = require("@hypercerts-org/hypercerts-sdk");

import { createClient } from "@supabase/supabase-js";
import dotenv from "dotenv";
import _ from "lodash";
import fetch from "node-fetch";

const pageSize = 1000;

dotenv.config();
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_HYPERCERTS_URL as string,
process.env.NEXT_PUBLIC_SUPABASE_HYPERCERTS_SERVICE_ROLE_KEY as string,
);

const fetchAllowlistPage = async (lastId: number) => {
console.log("fetching page with id >", lastId);
return supabase
.from("allowlistCache-chainId")
.select("*")
.order("id", { ascending: true })
.gt("id", lastId)
.eq("chainId", 10)
.limit(pageSize);
};

const deleteEntries = async (ids: number[]) => {
console.log("deleting entries", ids);
return supabase.from("allowlistCache-chainId").delete().in("id", ids);
};

const query = `
query ClaimTokensByClaim($claimId: String!, $orderDirection: OrderDirection, $first: Int, $skip: Int) {
claimTokens(where: { claim: $claimId }, skip: $skip, first: $first, orderDirection: $orderDirection) {
id
owner
tokenID
units
}
}
`;

const fetchClaimTokenForClaimId = async (claimId: string) => {
return (
fetch(
"https://api.thegraph.com/subgraphs/name/hypercerts-admin/hypercerts-optimism-mainnet",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
variables: {
claimId,
first: 1000,
},
query,
}),
},
)
.then((res) => res.json())
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
.then((res) => res.data?.claimTokens)
);
};

const main = async () => {
const totalNumberOfResults = await supabase
.from("allowlistCache-chainId")
.select("id", { count: "exact" });

console.log("totalNumberOfResults", totalNumberOfResults.count);

let lastId = 1;

// Iterate over all pages
// eslint-disable-next-line no-constant-condition
while (true) {
const { data } = await fetchAllowlistPage(lastId);
if (data.length === 0) {
break;
}
lastId = data[data.length - 1].id;

const allowlistEntriesByClaimId = _.groupBy(data, "claimId");
// console.log("fetched page", i);

for (const claimId in allowlistEntriesByClaimId) {
// console.log("checking duplicates for", claimId);
const entries = allowlistEntriesByClaimId[claimId];
// console.log(entries.length, "entries found");

const tokensForClaim = await fetchClaimTokenForClaimId(claimId);
// console.log("tokensForClaim", tokensForClaim);

const addressesForClaimTokens = tokensForClaim.map(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(token: any) => token.owner,
);
const addressesForEntry = entries.map((x) => x.address);
// console.log("Addresses for claim tokens", addressesForClaimTokens);
// console.log("Addresses for entries", addressesForEntry);

const duplicates = _.intersectionBy(
addressesForClaimTokens,
addressesForEntry,
);

if (duplicates.length > 0) {
const supabaseEntries = entries.filter((entry) =>
duplicates.includes(entry.address),
);
// console.log("duplicates found for claimId", claimId, duplicates.length);
// console.log("duplicates", duplicates);
// console.log("duplicate supabaseEntries", supabaseEntries);
const idsToDelete = supabaseEntries.map((x) => x.id);
await deleteEntries(idsToDelete);
}
}
}
};

// eslint-disable-next-line @typescript-eslint/no-floating-promises
main();
23 changes: 13 additions & 10 deletions docs/versioned_sidebars/version-1.0.0-alpha.0-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,23 @@
"items": [
{
"type": "category",
"label": "Contracts",
"label": "Protocol",
"collapsed": true,
"items": [
{
"type": "doc",
"id": "developer/api/contracts/HypercertMinter"
},
{
"type": "doc",
"id": "developer/api/contracts/SemiFungible1155"
},
"type": "autogenerated",
"dirName": "developer/api/contracts/protocol"
}
]
},
{
"type": "category",
"label": "Exchange",
"collapsed": true,
"items": [
{
"type": "doc",
"id": "developer/api/contracts/AllowlistMinter"
"type": "autogenerated",
"dirName": "developer/api/contracts/marketplace"
}
]
},
Expand Down
6 changes: 2 additions & 4 deletions graph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ dataSources:
handler: handleLeafClaimed
- event: OwnershipTransferred(indexed address,indexed address)
handler: handleOwnershipTransferred
- event: TransferBatch(indexed address,indexed address,indexed
address,uint256[],uint256[])
- event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[])
handler: handleTransferBatch
- event: TransferSingle(indexed address,indexed address,indexed
address,uint256,uint256)
- event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256)
handler: handleTransferSingle
- event: URI(string,indexed uint256)
handler: handleURI
Expand Down
Loading

0 comments on commit 1a3b8d8

Please sign in to comment.