Skip to content

Commit 2da0670

Browse files
committed
V 3.5
1 parent 2c4663b commit 2da0670

7 files changed

Lines changed: 378 additions & 270 deletions

File tree

src/PostRegistry.sol

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ contract PostRegistry {
4747

4848
error NotOwner();
4949
error LinkGraphAlreadySet();
50+
error LinkGraphZeroAddress();
5051
error LinkGraphNotSet();
5152

5253
constructor() {
5354
owner = msg.sender;
5455
}
5556

57+
/// @notice One-time wiring to the LinkGraph contract.
58+
/// @dev IMPORTANT: LinkGraph.registry must be set separately by LinkGraph.owner via LinkGraph.setRegistry(address(this)).
5659
function setLinkGraph(address linkGraph_) external {
5760
if (msg.sender != owner) revert NotOwner();
5861
if (address(linkGraph) != address(0)) revert LinkGraphAlreadySet();
59-
if (linkGraph_ == address(0)) revert LinkGraphNotSet();
62+
if (linkGraph_ == address(0)) revert LinkGraphZeroAddress();
6063

6164
linkGraph = LinkGraph(linkGraph_);
6265
emit LinkGraphSet(linkGraph_);
@@ -96,7 +99,13 @@ contract PostRegistry {
9699
postId = nextPostId++;
97100

98101
uint256 linkId = links.length;
99-
links.push(Link({independentPostId: independentPostId, dependentPostId: dependentPostId, isChallenge: isChallenge}));
102+
links.push(
103+
Link({
104+
independentPostId: independentPostId,
105+
dependentPostId: dependentPostId,
106+
isChallenge: isChallenge
107+
})
108+
);
100109

101110
posts[postId] = Post({
102111
creator: msg.sender,
@@ -105,7 +114,8 @@ contract PostRegistry {
105114
contentId: linkId
106115
});
107116

108-
// 🔐 DAG enforcement + metadata storage
117+
// DAG enforcement + metadata storage
118+
// NOTE: This will revert NotRegistry() unless LinkGraph.setRegistry(address(this)) has already been called.
109119
linkGraph.addEdge(independentPostId, dependentPostId, postId, isChallenge);
110120

111121
emit PostCreated(postId, msg.sender, ContentType.Link);
@@ -129,3 +139,4 @@ contract PostRegistry {
129139
return postId < nextPostId;
130140
}
131141
}
142+

src/ProtocolViews.sol

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@
22
pragma solidity ^0.8.20;
33

44
import "./PostRegistry.sol";
5-
import "./LinkGraph.sol";
65
import "./StakeEngine.sol";
6+
import "./LinkGraph.sol";
77
import "./ScoreEngine.sol";
88

99
/// @title ProtocolViews
10-
/// @notice Read-only aggregation over PostRegistry + StakeEngine + LinkGraph + ScoreEngine.
11-
/// No storage; no mutation; deterministic output.
10+
/// @notice Read-only aggregation layer for UI/indexers.
1211
contract ProtocolViews {
1312
PostRegistry public immutable registry;
1413
StakeEngine public immutable stake;
1514
LinkGraph public immutable graph;
1615
ScoreEngine public immutable score;
1716

1817
struct ClaimSummary {
19-
uint256 postId;
20-
address creator;
21-
uint256 version;
2218
string text;
2319
uint256 supportStake;
2420
uint256 challengeStake;
@@ -40,107 +36,73 @@ contract ProtocolViews {
4036
score = ScoreEngine(score_);
4137
}
4238

43-
// ------------------------------------------------------------------------
44-
// Claim summary
45-
// ------------------------------------------------------------------------
46-
4739
function getClaimSummary(uint256 claimPostId)
4840
external
4941
view
50-
returns (ClaimSummary memory summary)
42+
returns (ClaimSummary memory s)
5143
{
5244
(
53-
address creator,
54-
uint256 version,
45+
,
46+
,
5547
PostRegistry.ContentType ct,
5648
uint256 contentId
5749
) = registry.getPost(claimPostId);
5850

59-
require(ct == PostRegistry.ContentType.Claim, "ProtocolViews: not claim");
51+
require(ct == PostRegistry.ContentType.Claim, "not claim");
6052

61-
string memory text = registry.getClaim(contentId);
53+
s.text = registry.getClaim(contentId);
6254

63-
(uint256 supportStake, uint256 challengeStake) =
55+
(s.supportStake, s.challengeStake) =
6456
stake.getPostTotals(claimPostId);
6557

66-
int256 baseVS = score.baseVSRay(claimPostId);
67-
int256 effectiveVS = score.effectiveVSRay(claimPostId);
68-
69-
uint256 incomingCount =
70-
graph.getIncoming(claimPostId).length;
71-
72-
uint256 outgoingCount =
73-
graph.getOutgoing(claimPostId).length;
74-
75-
summary = ClaimSummary({
76-
postId: claimPostId,
77-
creator: creator,
78-
version: version,
79-
text: text,
80-
supportStake: supportStake,
81-
challengeStake: challengeStake,
82-
baseVSRay: baseVS,
83-
effectiveVSRay: effectiveVS,
84-
incomingCount: incomingCount,
85-
outgoingCount: outgoingCount
86-
});
58+
s.baseVSRay = score.baseVSRay(claimPostId);
59+
s.effectiveVSRay = score.effectiveVSRay(claimPostId);
60+
61+
s.incomingCount = graph.getIncoming(claimPostId).length;
62+
s.outgoingCount = graph.getOutgoing(claimPostId).length;
8763
}
8864

89-
// ------------------------------------------------------------------------
90-
// Raw VS passthroughs
91-
// ------------------------------------------------------------------------
65+
// passthrough helpers
9266

93-
/// @notice Raw base VS in ray (1e18 = +1.0, -1e18 = -1.0).
9467
function getBaseVSRay(uint256 claimPostId) external view returns (int256) {
9568
return score.baseVSRay(claimPostId);
9669
}
9770

98-
/// @notice Raw effective VS in ray (multi-hop, symmetrical).
9971
function getEffectiveVSRay(uint256 claimPostId) external view returns (int256) {
10072
return score.effectiveVSRay(claimPostId);
10173
}
10274

103-
// ------------------------------------------------------------------------
104-
// Graph passthroughs
105-
// ------------------------------------------------------------------------
106-
107-
function getOutgoingEdges(uint256 claimPostId)
75+
function getIncomingEdges(uint256 claimPostId)
10876
external
10977
view
110-
returns (LinkGraph.Edge[] memory)
78+
returns (LinkGraph.IncomingEdge[] memory)
11179
{
112-
return graph.getOutgoing(claimPostId);
80+
return graph.getIncoming(claimPostId);
11381
}
11482

115-
function getIncomingEdges(uint256 claimPostId)
83+
function getOutgoingEdges(uint256 claimPostId)
11684
external
11785
view
118-
returns (LinkGraph.IncomingEdge[] memory)
86+
returns (LinkGraph.Edge[] memory)
11987
{
120-
return graph.getIncoming(claimPostId);
88+
return graph.getOutgoing(claimPostId);
12189
}
12290

123-
/// @notice Resolve link metadata for a link post id.
12491
function getLinkMeta(uint256 linkPostId)
12592
external
12693
view
127-
returns (
128-
uint256 independentClaimPostId,
129-
uint256 dependentClaimPostId,
130-
bool isChallenge
131-
)
94+
returns (uint256 from, uint256 to, bool isChallenge)
13295
{
13396
(
13497
,
13598
,
13699
PostRegistry.ContentType ct,
137-
uint256 contentId
100+
uint256 linkId
138101
) = registry.getPost(linkPostId);
139102

140-
require(ct == PostRegistry.ContentType.Link, "ProtocolViews: not link");
103+
require(ct == PostRegistry.ContentType.Link, "not link");
141104

142-
(independentClaimPostId, dependentClaimPostId, isChallenge) =
143-
registry.getLink(contentId);
105+
return registry.getLink(linkId);
144106
}
145107
}
146108

0 commit comments

Comments
 (0)