Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ids): hypercerts-org and chainID to graph #1283

Merged
merged 6 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
"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",
"@graphprotocol/graph-cli": "0.68.5",
"@graphprotocol/graph-ts": "0.33.0",
"assemblyscript": "0.19.23",
"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
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": 1705410292091
"timestamp": 1710361554698
}
12 changes: 7 additions & 5 deletions graph/tests/hypercert-minter-allowlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Describe entity assertions", () => {

let allowlistCreatedEvent = createAllowlistCreatedEvent(
tokenID,
Bytes.fromUTF8("MerkleRoot")
Bytes.fromUTF8("MerkleRoot"),
);

handleAllowlistCreated(allowlistCreatedEvent);
Expand All @@ -33,9 +33,11 @@ describe("Describe entity assertions", () => {

test("AllowlistCreated generates one allowlist entity", () => {
let merkleRoot = Bytes.fromUTF8("MerkleRoot");
let allowlistID = getDefaultContractAddress()
.toHexString()
.concat("-".concat(BigInt.fromI64(1).toString()));
let allowlistID = "1-".concat(
getDefaultContractAddress()
.toHexString()
.concat("-".concat(BigInt.fromI64(1).toString())),
);

assert.entityCount("Allowlist", 1);
assert.entityCount("Claim", 0);
Expand All @@ -46,7 +48,7 @@ describe("Describe entity assertions", () => {
"Allowlist",
allowlistID,
"root",
merkleRoot.toHexString()
merkleRoot.toHexString(),
);
assert.fieldEquals("Allowlist", allowlistID, "claim", allowlistID);
});
Expand Down
8 changes: 6 additions & 2 deletions graph/tests/hypercert-minter-burn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ describe("Describe entity assertions", () => {

handleValueTransfer(valueTransferEvent);

let fractionId = getDefaultContractAddress().toHexString().concat("-1");
let fractionId = "1-".concat(
getDefaultContractAddress().toHexString().concat("-1"),
);

assert.fieldEquals("ClaimToken", fractionId, "owner", from.toHexString());
assert.fieldEquals("ClaimToken", fractionId, "units", "10000");
Expand Down Expand Up @@ -144,7 +146,9 @@ describe("Describe entity assertions", () => {

handleBatchValueTransfer(valueTransferEvent);

let fractionId = getDefaultContractAddress().toHexString().concat("-1");
let fractionId = "1-".concat(
getDefaultContractAddress().toHexString().concat("-1"),
);

assert.fieldEquals("ClaimToken", fractionId, "owner", from.toHexString());
assert.fieldEquals("ClaimToken", fractionId, "units", "10000");
Expand Down
8 changes: 5 additions & 3 deletions graph/tests/hypercert-minter-claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ describe("Describe entity assertions", () => {
assert.entityCount("Claim", 1);
assert.entityCount("ClaimFraction", 0);

let claimId = getDefaultContractAddress()
.toHexString()
.concat("-".concat(BigInt.fromI64(1).toString()));
let claimId = "1-".concat(
getDefaultContractAddress()
.toHexString()
.concat("-".concat(BigInt.fromI64(1).toString())),
);

assert.fieldEquals("Claim", claimId, "uri", "ipfs://exampleshash");
assert.fieldEquals(
Expand Down
Loading
Loading