Skip to content

Commit

Permalink
feat(ids): hypercerts-org and chainID to graph
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers committed Mar 13, 2024
1 parent 84d6743 commit 064988c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 81 deletions.
22 changes: 11 additions & 11 deletions graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"build:codegen": "graph codegen",
"deploy:test": "pnpm auth && pnpm deploy:sepolia && pnpm deploy:base-sepolia",
"deploy:prod": "pnpm auth && pnpm deploy:optimism && pnpm deploy:celo && pnpm deploy:base",
"deploy:base": "graph deploy --node https://api.thegraph.com/deploy/ --network base hypercerts-admin/hypercerts-base-mainnet",
"deploy:celo": "graph deploy --node https://api.thegraph.com/deploy/ --network celo hypercerts-admin/hypercerts-celo",
"deploy:optimism": "graph deploy --node https://api.thegraph.com/deploy/ --network optimism hypercerts-admin/hypercerts-optimism-mainnet",
"deploy:sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network sepolia hypercerts-admin/hypercerts-sepolia",
"deploy:base-sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network base-sepolia hypercerts-admin/hypercerts-base-sepolia",
"create-local": "graph create --node http://localhost:8020/ hypercerts-admin/hypercerts-testnet",
"remove-local": "graph remove --node http://localhost:8020/ hypercerts-admin/hypercerts-testnet",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 hypercerts-admin/hypercerts-testnet",
"deploy:base": "graph deploy --node https://api.thegraph.com/deploy/ --network base hypercerts-org/hypercerts-base-mainnet",
"deploy:celo": "graph deploy --node https://api.thegraph.com/deploy/ --network celo hypercerts-org/hypercerts-celo",
"deploy:optimism": "graph deploy --node https://api.thegraph.com/deploy/ --network optimism hypercerts-org/hypercerts-optimism-mainnet",
"deploy:sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network sepolia hypercerts-org/hypercerts-sepolia",
"deploy:base-sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network base-sepolia hypercerts-org/hypercerts-base-sepolia",
"create-local": "graph create --node http://localhost:8020/ hypercerts-org/hypercerts-testnet",
"remove-local": "graph remove --node http://localhost:8020/ hypercerts-org/hypercerts-testnet",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 hypercerts-org/hypercerts-testnet",
"graph": "graph",
"test": "graph test"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.60.0",
"@graphprotocol/graph-ts": "0.31.0",
"assemblyscript": "0.19.23",
"@graphprotocol/graph-cli": "0.68.5",
"@graphprotocol/graph-ts": "0.33.0",
"assemblyscript": "0.27.25",
"matchstick-as": "0.6.0"
},
"//": [
Expand Down
40 changes: 0 additions & 40 deletions graph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,4 @@ type ClaimToken @entity {
claim: Claim!
owner: Bytes!
units: BigInt!
offers: [Offer!] @derivedFrom(field: "fractionID")
}

type Token @entity {
id: String!
name: String!
symbol: String
decimals: BigInt
}

type AcceptedToken @entity {
id: String!
token: Token!
minimumAmountPerUnit: BigInt!
accepted: Boolean!
}

enum OfferStatus {
Open
Fulfilled
Cancelled
}

type Offer @entity {
id: String!
fractionID: ClaimToken!
unitsAvailable: BigInt!
minUnitsPerTrade: BigInt!
maxUnitsPerTrade: BigInt!
status: OfferStatus!
acceptedTokens: [AcceptedToken!]!
}

type Trade @entity {
id: String!
buyer: Bytes!
offerID: Offer!
unitsSold: BigInt!
token: Token!
amountPerUnit: BigInt!
}
35 changes: 34 additions & 1 deletion graph/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
import { HypercertMinter } from "../generated/HypercertMinter/HypercertMinter";
import { Allowlist, Claim, ClaimToken } from "../generated/schema";
import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts";
import { dataSource } from "@graphprotocol/graph-ts";

// const chainIds = {
// base: "84531",
// "base-sepolia": "84532",
// celo: "42220",
// mainnet: "1",
// optimism: "10",
// sepolia: "11155111",
// } as const;

export const ZERO_ADDRESS = Address.fromString(
"0x0000000000000000000000000000000000000000",
);

export function getID(tokenID: BigInt, contract: Address): string {
return contract.toHexString().concat("-".concat(tokenID.toString()));
const network = dataSource.network();

let chainId: string;

// TODO fix this ugly hack because of the stupid type compile errors
if (network == "mainnet") {
chainId = "1";
} else if (network == "celo") {
chainId = "42220";
} else if (network == "optimism") {
chainId = "10";
} else if (network == "sepolia") {
chainId = "11155111";
} else if (network == "base") {
chainId = "84531";
} else if (network == "base-sepolia") {
chainId = "84532";
} else {
chainId = "";
}

return chainId.concat(
"-".concat(contract.toHexString().concat("-".concat(tokenID.toString()))),
);
}

export function getOrCreateAllowlist(
Expand Down
6 changes: 4 additions & 2 deletions graph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ 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 064988c

Please sign in to comment.