Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit bf0a66b

Browse files
authored
Merge pull request #1283 from hypercerts-org/feat/update_graph_deploy_and_ids
feat(ids): hypercerts-org and chainID to graph
2 parents 84d6743 + 6c5ac61 commit bf0a66b

10 files changed

+158
-131
lines changed

graph/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
"build:codegen": "graph codegen",
1212
"deploy:test": "pnpm auth && pnpm deploy:sepolia && pnpm deploy:base-sepolia",
1313
"deploy:prod": "pnpm auth && pnpm deploy:optimism && pnpm deploy:celo && pnpm deploy:base",
14-
"deploy:base": "graph deploy --node https://api.thegraph.com/deploy/ --network base hypercerts-admin/hypercerts-base-mainnet",
15-
"deploy:celo": "graph deploy --node https://api.thegraph.com/deploy/ --network celo hypercerts-admin/hypercerts-celo",
16-
"deploy:optimism": "graph deploy --node https://api.thegraph.com/deploy/ --network optimism hypercerts-admin/hypercerts-optimism-mainnet",
17-
"deploy:sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network sepolia hypercerts-admin/hypercerts-sepolia",
18-
"deploy:base-sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network base-sepolia hypercerts-admin/hypercerts-base-sepolia",
19-
"create-local": "graph create --node http://localhost:8020/ hypercerts-admin/hypercerts-testnet",
20-
"remove-local": "graph remove --node http://localhost:8020/ hypercerts-admin/hypercerts-testnet",
21-
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 hypercerts-admin/hypercerts-testnet",
14+
"deploy:base": "graph deploy --node https://api.thegraph.com/deploy/ --network base hypercerts-org/hypercerts-base-mainnet",
15+
"deploy:celo": "graph deploy --node https://api.thegraph.com/deploy/ --network celo hypercerts-org/hypercerts-celo",
16+
"deploy:optimism": "graph deploy --node https://api.thegraph.com/deploy/ --network optimism hypercerts-org/hypercerts-optimism-mainnet",
17+
"deploy:sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network sepolia hypercerts-org/hypercerts-sepolia",
18+
"deploy:base-sepolia": "graph deploy --node https://api.thegraph.com/deploy/ --network base-sepolia hypercerts-org/hypercerts-base-sepolia",
19+
"create-local": "graph create --node http://localhost:8020/ hypercerts-org/hypercerts-testnet",
20+
"remove-local": "graph remove --node http://localhost:8020/ hypercerts-org/hypercerts-testnet",
21+
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 hypercerts-org/hypercerts-testnet",
2222
"graph": "graph",
2323
"test": "graph test"
2424
},
2525
"devDependencies": {
26-
"@graphprotocol/graph-cli": "0.60.0",
27-
"@graphprotocol/graph-ts": "0.31.0",
26+
"@graphprotocol/graph-cli": "0.68.5",
27+
"@graphprotocol/graph-ts": "0.33.0",
2828
"assemblyscript": "0.19.23",
2929
"matchstick-as": "0.6.0"
3030
},

graph/schema.graphql

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,4 @@ type ClaimToken @entity {
2222
claim: Claim!
2323
owner: Bytes!
2424
units: BigInt!
25-
offers: [Offer!] @derivedFrom(field: "fractionID")
26-
}
27-
28-
type Token @entity {
29-
id: String!
30-
name: String!
31-
symbol: String
32-
decimals: BigInt
33-
}
34-
35-
type AcceptedToken @entity {
36-
id: String!
37-
token: Token!
38-
minimumAmountPerUnit: BigInt!
39-
accepted: Boolean!
40-
}
41-
42-
enum OfferStatus {
43-
Open
44-
Fulfilled
45-
Cancelled
46-
}
47-
48-
type Offer @entity {
49-
id: String!
50-
fractionID: ClaimToken!
51-
unitsAvailable: BigInt!
52-
minUnitsPerTrade: BigInt!
53-
maxUnitsPerTrade: BigInt!
54-
status: OfferStatus!
55-
acceptedTokens: [AcceptedToken!]!
56-
}
57-
58-
type Trade @entity {
59-
id: String!
60-
buyer: Bytes!
61-
offerID: Offer!
62-
unitsSold: BigInt!
63-
token: Token!
64-
amountPerUnit: BigInt!
6525
}

graph/src/utils.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
11
import { HypercertMinter } from "../generated/HypercertMinter/HypercertMinter";
22
import { Allowlist, Claim, ClaimToken } from "../generated/schema";
33
import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts";
4+
import { dataSource } from "@graphprotocol/graph-ts";
5+
6+
// const chainIds = {
7+
// base: "84531",
8+
// "base-sepolia": "84532",
9+
// celo: "42220",
10+
// mainnet: "1",
11+
// optimism: "10",
12+
// sepolia: "11155111",
13+
// } as const;
414

515
export const ZERO_ADDRESS = Address.fromString(
616
"0x0000000000000000000000000000000000000000",
717
);
818

919
export function getID(tokenID: BigInt, contract: Address): string {
10-
return contract.toHexString().concat("-".concat(tokenID.toString()));
20+
const network = dataSource.network();
21+
22+
let chainId: string;
23+
24+
// TODO fix this ugly hack because of the stupid type compile errors
25+
if (network == "mainnet") {
26+
chainId = "1";
27+
} else if (network == "celo") {
28+
chainId = "42220";
29+
} else if (network == "optimism") {
30+
chainId = "10";
31+
} else if (network == "sepolia") {
32+
chainId = "11155111";
33+
} else if (network == "base") {
34+
chainId = "84531";
35+
} else if (network == "base-sepolia") {
36+
chainId = "84532";
37+
} else {
38+
chainId = "";
39+
}
40+
41+
return chainId.concat(
42+
"-".concat(contract.toHexString().concat("-".concat(tokenID.toString()))),
43+
);
1144
}
1245

1346
export function getOrCreateAllowlist(

graph/subgraph.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ dataSources:
3333
handler: handleLeafClaimed
3434
- event: OwnershipTransferred(indexed address,indexed address)
3535
handler: handleOwnershipTransferred
36-
- event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[])
36+
- event: TransferBatch(indexed address,indexed address,indexed
37+
address,uint256[],uint256[])
3738
handler: handleTransferBatch
38-
- event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256)
39+
- event: TransferSingle(indexed address,indexed address,indexed
40+
address,uint256,uint256)
3941
handler: handleTransferSingle
4042
- event: URI(string,indexed uint256)
4143
handler: handleURI

graph/tests/.latest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"version": "0.6.0",
3-
"timestamp": 1705410292091
3+
"timestamp": 1710361554698
44
}

graph/tests/hypercert-minter-allowlist.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("Describe entity assertions", () => {
2121

2222
let allowlistCreatedEvent = createAllowlistCreatedEvent(
2323
tokenID,
24-
Bytes.fromUTF8("MerkleRoot")
24+
Bytes.fromUTF8("MerkleRoot"),
2525
);
2626

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

3434
test("AllowlistCreated generates one allowlist entity", () => {
3535
let merkleRoot = Bytes.fromUTF8("MerkleRoot");
36-
let allowlistID = getDefaultContractAddress()
37-
.toHexString()
38-
.concat("-".concat(BigInt.fromI64(1).toString()));
36+
let allowlistID = "1-".concat(
37+
getDefaultContractAddress()
38+
.toHexString()
39+
.concat("-".concat(BigInt.fromI64(1).toString())),
40+
);
3941

4042
assert.entityCount("Allowlist", 1);
4143
assert.entityCount("Claim", 0);
@@ -46,7 +48,7 @@ describe("Describe entity assertions", () => {
4648
"Allowlist",
4749
allowlistID,
4850
"root",
49-
merkleRoot.toHexString()
51+
merkleRoot.toHexString(),
5052
);
5153
assert.fieldEquals("Allowlist", allowlistID, "claim", allowlistID);
5254
});

graph/tests/hypercert-minter-burn.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ describe("Describe entity assertions", () => {
6767

6868
handleValueTransfer(valueTransferEvent);
6969

70-
let fractionId = getDefaultContractAddress().toHexString().concat("-1");
70+
let fractionId = "1-".concat(
71+
getDefaultContractAddress().toHexString().concat("-1"),
72+
);
7173

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

145147
handleBatchValueTransfer(valueTransferEvent);
146148

147-
let fractionId = getDefaultContractAddress().toHexString().concat("-1");
149+
let fractionId = "1-".concat(
150+
getDefaultContractAddress().toHexString().concat("-1"),
151+
);
148152

149153
assert.fieldEquals("ClaimToken", fractionId, "owner", from.toHexString());
150154
assert.fieldEquals("ClaimToken", fractionId, "units", "10000");

graph/tests/hypercert-minter-claim.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ describe("Describe entity assertions", () => {
3434
assert.entityCount("Claim", 1);
3535
assert.entityCount("ClaimFraction", 0);
3636

37-
let claimId = getDefaultContractAddress()
38-
.toHexString()
39-
.concat("-".concat(BigInt.fromI64(1).toString()));
37+
let claimId = "1-".concat(
38+
getDefaultContractAddress()
39+
.toHexString()
40+
.concat("-".concat(BigInt.fromI64(1).toString())),
41+
);
4042

4143
assert.fieldEquals("Claim", claimId, "uri", "ipfs://exampleshash");
4244
assert.fieldEquals(

0 commit comments

Comments
 (0)