Skip to content

Commit 85ed0ad

Browse files
feat: new-list-metadata-flow
1 parent 971bcb2 commit 85ed0ad

File tree

13 files changed

+287
-530
lines changed

13 files changed

+287
-530
lines changed

contracts/deployments/arbitrumSepoliaDevnet/CurateFactory.json

+62-44
Large diffs are not rendered by default.

contracts/deployments/arbitrumSepoliaDevnet/CurateV2.json

+81-81
Large diffs are not rendered by default.

contracts/deployments/arbitrumSepoliaDevnet/CurateView.json

+15-15
Large diffs are not rendered by default.

contracts/src/CurateFactory.sol

+27-15
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ contract CurateFactory {
1919

2020
/// @dev Emitted when a new Curate contract is deployed using this factory. TODO: change TCR mentions.
2121
/// @param _address The address of the newly deployed Curate contract.
22-
event NewGTCR(CurateV2 indexed _address);
22+
/// @param _listMetadata A link to registry / list metadata (title,description) using its URI
23+
event NewList(CurateV2 indexed _address, string _listMetadata);
24+
25+
// ************************************* //
26+
// * Enums / Structs * //
27+
// ************************************* //
28+
29+
struct TemplateRegistryParams {
30+
address templateRegistry; // The current status of the item.
31+
string[2] registrationTemplateParameters; // Template and data mappings json for registration requests.
32+
string[2] removalTemplateParameters; // Template and data mappings json for removal requests.
33+
}
2334

2435
// ************************************* //
2536
// * Storage * //
@@ -47,46 +58,47 @@ contract CurateFactory {
4758
/// @param _arbitrator Arbitrator to resolve potential disputes. The arbitrator is trusted to support appeal periods and not reenter.
4859
/// @param _arbitratorExtraData Extra data for the trusted arbitrator contract.
4960
/// @param _evidenceModule The evidence contract for the arbitrator.
50-
/// @param _connectedTCR The address of the Curate contract that stores related Curate addresses. This parameter can be left empty.
51-
/// @param _registrationTemplateParameters Template and data mappings json for registration requests.
52-
/// @param _removalTemplateParameters Template and data mappings json for removal requests.
53-
/// @param _templateRegistry The dispute template registry.
61+
/// @param _connectedList The address of the Curate contract that stores related Curate addresses. This parameter can be left empty.
62+
/// @param _templateRegistryParams The dispute template registry.
63+
/// - templateRegistry : The dispute template registry.
64+
/// - registrationTemplateParameters : Template and data mappings json for registration requests.
65+
/// - removalTemplateParameters : Template and data mappings json for removal requests.
5466
/// @param _baseDeposits The base deposits for requests/challenges as follows:
5567
/// - The base deposit to submit an item.
5668
/// - The base deposit to remove an item.
5769
/// - The base deposit to challenge a submission.
5870
/// - The base deposit to challenge a removal request.
5971
/// @param _challengePeriodDuration The time in seconds parties have to challenge a request.
6072
/// @param _relayerContract The address of the relay contract to add/remove items directly.
73+
/// @param _listMetadata A link to registry / list metadata (title,description) using its URI
6174
function deploy(
6275
address _governor,
6376
IArbitratorV2 _arbitrator,
6477
bytes calldata _arbitratorExtraData,
6578
EvidenceModule _evidenceModule,
66-
address _connectedTCR,
67-
string[2] calldata _registrationTemplateParameters,
68-
string[2] calldata _removalTemplateParameters,
69-
address _templateRegistry,
79+
address _connectedList,
80+
TemplateRegistryParams calldata _templateRegistryParams,
7081
uint256[4] calldata _baseDeposits,
7182
uint256 _challengePeriodDuration,
72-
address _relayerContract
83+
address _relayerContract,
84+
string memory _listMetadata
7385
) public {
7486
CurateV2 instance = clone(curate);
7587
instance.initialize(
7688
_governor,
7789
_arbitrator,
7890
_arbitratorExtraData,
7991
_evidenceModule,
80-
_connectedTCR,
81-
_registrationTemplateParameters,
82-
_removalTemplateParameters,
83-
_templateRegistry,
92+
_connectedList,
93+
_templateRegistryParams.registrationTemplateParameters,
94+
_templateRegistryParams.removalTemplateParameters,
95+
_templateRegistryParams.templateRegistry,
8496
_baseDeposits,
8597
_challengePeriodDuration,
8698
_relayerContract
8799
);
88100
instances.push(instance);
89-
emit NewGTCR(instance);
101+
emit NewList(instance, _listMetadata);
90102
}
91103

92104
/// @notice Adaptation of https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/Clones.sol.

contracts/src/CurateV2.sol

+10-10
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ contract CurateV2 is IArbitrableV2 {
129129
event RequestSubmitted(bytes32 indexed _itemID, uint256 _requestID);
130130

131131
/// @dev Emitted when the address of the connected Curate contract is set. The Curate is an instance of the Curate contract where each item is the address of a Curate contract related to this one.
132-
/// @param _connectedTCR The address of the connected Curate. TODO: change TCR mentions.
133-
event ConnectedTCRSet(address indexed _connectedTCR);
132+
/// @param _connectedList The address of the connected Curate.
133+
event ConnectedListSet(address indexed _connectedList);
134134

135135
// ************************************* //
136136
// * Initializer * //
@@ -141,7 +141,7 @@ contract CurateV2 is IArbitrableV2 {
141141
/// @param _arbitrator Arbitrator to resolve potential disputes. The arbitrator is trusted to support appeal periods and not reenter.
142142
/// @param _arbitratorExtraData Extra data for the trusted arbitrator contract.
143143
/// @param _evidenceModule The evidence contract for the arbitrator.
144-
/// @param _connectedTCR The address of the Curate contract that stores related Curate addresses. This parameter can be left empty.
144+
/// @param _connectedList The address of the Curate contract that stores related Curate addresses. This parameter can be left empty.
145145
/// @param _registrationTemplateParameters Template and data mappings json for registration requests.
146146
/// @param _removalTemplateParameters Template and data mappings json for removal requests.
147147
/// @param _templateRegistry The dispute template registry.
@@ -157,7 +157,7 @@ contract CurateV2 is IArbitrableV2 {
157157
IArbitratorV2 _arbitrator,
158158
bytes calldata _arbitratorExtraData,
159159
EvidenceModule _evidenceModule,
160-
address _connectedTCR,
160+
address _connectedList,
161161
string[2] calldata _registrationTemplateParameters,
162162
string[2] calldata _removalTemplateParameters,
163163
address _templateRegistry,
@@ -196,8 +196,8 @@ contract CurateV2 is IArbitrableV2 {
196196
})
197197
);
198198

199-
if (_connectedTCR != address(0)) {
200-
emit ConnectedTCRSet(_connectedTCR);
199+
if (_connectedList != address(0)) {
200+
emit ConnectedListSet(_connectedList);
201201
}
202202
}
203203

@@ -241,10 +241,10 @@ contract CurateV2 is IArbitrableV2 {
241241
governor = _governor;
242242
}
243243

244-
/// @dev Change the address of connectedTCR, the Curate instance that stores addresses of Curate contracts related to this one.
245-
/// @param _connectedTCR The address of the connectedTCR contract to use.
246-
function changeConnectedTCR(address _connectedTCR) external onlyGovernor {
247-
emit ConnectedTCRSet(_connectedTCR);
244+
/// @dev Change the address of connectedList, the Curate instance that stores addresses of Curate contracts related to this one.
245+
/// @param _connectedList The address of the connectedList contract to use.
246+
function changeConnectedList(address _connectedList) external onlyGovernor {
247+
emit ConnectedListSet(_connectedList);
248248
}
249249

250250
/// @dev Change the address of the relay contract.

subgraph/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"node": "20.11.0"
2525
},
2626
"dependencies": {
27-
"@graphprotocol/graph-ts": "^0.32.0"
27+
"@graphprotocol/graph-ts": "^0.33.0"
2828
},
2929
"devDependencies": {
30-
"@graphprotocol/graph-cli": "0.64.0",
30+
"@graphprotocol/graph-cli": "0.68.5",
3131
"@kleros/curate-v2-eslint-config": "workspace:^",
3232
"@kleros/curate-v2-prettier-config": "workspace:^",
3333
"gluegun": "^5.1.2",

subgraph/schema.graphql

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
enum Status {
2-
"The item is not registered on the TCR and there are no pending requests."
2+
"The item is not registered on the List and there are no pending requests."
33
absent
44
"The item is registered and there are no pending requests."
55
registered
6-
"The item is not registered on the TCR, but there is a pending registration request."
6+
"The item is not registered on the List, but there is a pending registration request."
77
registrationRequested
8-
"The item is registered on the TCR, but there is a pending removal request. These are sometimes also called removal requests."
8+
"The item is registered on the List, but there is a pending removal request. These are sometimes also called removal requests."
99
clearingRequested
1010
}
1111

@@ -46,10 +46,16 @@ type Registry @entity {
4646
items: [Item!]! @derivedFrom(field: "registry")
4747
"The requests submitted to this list"
4848
requests: [Request!]! @derivedFrom(field: "registry")
49-
"Connected TCR. Can be the 0 address. In practice, will never be null."
50-
connectedTCR: Bytes
49+
"Connected List. Can be the 0 address. In practice, will never be null."
50+
connectedList: Bytes
5151
"The address that registered the curate"
5252
registerer: User!
53+
"Registry metadata"
54+
title: String
55+
description: String
56+
logoURI: String
57+
policyURI: String
58+
metadataURI: String!
5359
}
5460

5561
type Item @entity {

subgraph/src/Curate.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import {
77
RequestSubmitted,
88
NewItem,
99
Ruling,
10-
ConnectedTCRSet as ConnectedTCRSetEvent,
1110
Curate,
1211
DisputeRequest,
12+
ConnectedListSet,
1313
} from "../generated/templates/Curate/Curate";
1414
import { ItemStatus, ONE, ZERO, getFinalRuling, getStatus } from "./utils";
1515
import { createRequestFromEvent } from "./entities/Request";
1616
import { createItemFromEvent } from "./entities/Item";
1717
import { ensureUser } from "./entities/User";
1818

19-
// Items on a TCR can be in 1 of 4 states:
20-
// - (0) Absent: The item is not registered on the TCR and there are no pending requests.
19+
// Items on a List can be in 1 of 4 states:
20+
// - (0) Absent: The item is not registered on the List and there are no pending requests.
2121
// - (1) Registered: The item is registered and there are no pending requests.
22-
// - (2) Registration Requested: The item is not registered on the TCR, but there is a pending
22+
// - (2) Registration Requested: The item is not registered on the List, but there is a pending
2323
// registration request.
24-
// - (3) Clearing Requested: The item is registered on the TCR, but there is a pending removal
24+
// - (3) Clearing Requested: The item is registered on the List, but there is a pending removal
2525
// request. These are sometimes also called removal requests.
2626
//
2727
// Registration and removal requests can be challenged. Once the request resolves (either by
@@ -35,7 +35,7 @@ import { ensureUser } from "./entities/User";
3535
//
3636
// Example:
3737
// requestIndex: 0
38-
// requestID: <itemID>@<tcrAddress>-0
38+
// requestID: <itemID>@<listAddress>-0
3939
//
4040
// The only exception to this rule is the itemID, which is the in-contract itemID.
4141
//
@@ -121,13 +121,13 @@ export function handleStatusUpdated(event: ItemStatusChange): void {
121121
request.save();
122122
}
123123

124-
export function handleConnectedTCRSet(event: ConnectedTCRSetEvent): void {
124+
export function handleConnectedListSet(event: ConnectedListSet): void {
125125
let registry = Registry.load(event.address.toHexString());
126126
if (!registry) {
127127
log.error(`Registry {} not found.`, [event.address.toHexString()]);
128128
return;
129129
}
130-
registry.connectedTCR = event.params._connectedTCR;
130+
registry.connectedList = event.params._connectedList;
131131

132132
registry.save();
133133
}

subgraph/src/CurateFactory.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable prefer-const */
2-
import { NewGTCR } from "../generated/CurateFactory/CurateFactory";
2+
import { Bytes, ipfs, json, log } from "@graphprotocol/graph-ts";
3+
import { NewList } from "../generated/CurateFactory/CurateFactory";
34
import { Registry, User } from "../generated/schema";
45
import { Curate } from "../generated/templates";
56
import { ensureCounter } from "./entities/Counters";
67
import { ensureUser } from "./entities/User";
7-
import { ONE } from "./utils";
8+
import { JSONValueToMaybeString, ONE } from "./utils";
89

9-
export function handleNewCurate(event: NewGTCR): void {
10+
export function handleNewCurate(event: NewList): void {
1011
Curate.create(event.params._address);
1112

1213
let registry = new Registry(event.params._address.toHexString());
@@ -17,6 +18,33 @@ export function handleNewCurate(event: NewGTCR): void {
1718
if (!doesCuratorExist) counter.numberOfCurators = counter.numberOfCurators.plus(ONE);
1819

1920
registry.registerer = ensureUser(event.transaction.from.toHexString()).id;
21+
registry.metadataURI = event.params._listMetadata;
22+
23+
let jsonStr = ipfs.cat(registry.metadataURI);
24+
if (!jsonStr) {
25+
log.error("Failed to fetch registry metadata #{} JSON: {}", [registry.id, registry.metadataURI]);
26+
registry.save();
27+
return;
28+
}
29+
30+
let jsonObjValueAndSuccess = json.try_fromBytes(jsonStr as Bytes);
31+
if (!jsonObjValueAndSuccess.isOk) {
32+
log.error(`Error getting json object value for registry metadata {}`, [registry.id]);
33+
registry.save();
34+
return;
35+
}
36+
37+
let jsonObj = jsonObjValueAndSuccess.value.toObject();
38+
if (!jsonObj) {
39+
log.error(`Error converting object for registry metadata {}`, [registry.id]);
40+
registry.save();
41+
return;
42+
}
43+
44+
registry.title = JSONValueToMaybeString(jsonObj.get("title"));
45+
registry.description = JSONValueToMaybeString(jsonObj.get("description"));
46+
registry.logoURI = JSONValueToMaybeString(jsonObj.get("logoURI"));
47+
registry.policyURI = JSONValueToMaybeString(jsonObj.get("policyURI"));
2048

2149
counter.save();
2250
registry.save();

subgraph/subgraph.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
specVersion: 0.0.4
1+
specVersion: 0.0.7
22
description: Curate
33
features:
44
- fullTextSearch
@@ -11,9 +11,9 @@ dataSources:
1111
name: CurateFactory
1212
network: arbitrum-sepolia
1313
source:
14-
address: "0x5D03d22229899cd7Af84a3F0f9c39B24F51c8E21"
14+
address: "0xF5B335323e1b8c219A9e0bF798a2bFf8325e1cE1"
1515
abi: CurateFactory
16-
startBlock: 14782094
16+
startBlock: 23023734
1717
mapping:
1818
kind: ethereum/events
1919
apiVersion: 0.0.6
@@ -24,7 +24,7 @@ dataSources:
2424
- name: CurateFactory
2525
file: ./../contracts/deployments/arbitrumSepoliaDevnet/CurateFactory.json
2626
eventHandlers:
27-
- event: NewGTCR(indexed address)
27+
- event: NewList(indexed address,string)
2828
handler: handleNewCurate
2929
file: ./src/CurateFactory.ts
3030
templates:
@@ -55,6 +55,6 @@ templates:
5555
handler: handleStatusUpdated
5656
- event: Ruling(indexed address,indexed uint256,uint256)
5757
handler: handleRuling
58-
- event: ConnectedTCRSet(indexed address)
59-
handler: handleConnectedTCRSet
58+
- event: ConnectedListSet(indexed address)
59+
handler: handleConnectedListSet
6060
file: ./src/Curate.ts

web/.env.devnet.public

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Do not enter sensitive information here.
22
export REACT_APP_DEPLOYMENT=devnet
3-
export REACT_APP_ARBSEPOLIA_SUBGRAPH=https://api.thegraph.com/subgraphs/name/kemuru/curate-v2-devnet
3+
export REACT_APP_ARBSEPOLIA_SUBGRAPH=https://api.thegraph.com/subgraphs/name/harman-singh-waraich/curate-test-graph
44
export REACT_APP_STATUS_URL=https://curate-v2-devnet.betteruptime.com/badge
55
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=14782082

web/src/hooks/queries/useRegistriesQuery.ts

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export type { RegistryDetailsFragment };
88
export const registryFragment = graphql(`
99
fragment RegistryDetails on Registry {
1010
id
11+
title
12+
description
13+
logoURI
14+
policyURI
15+
metadataURI
1116
}
1217
`);
1318

0 commit comments

Comments
 (0)