Skip to content

Commit 7abc379

Browse files
committed
Restored after merge.
1 parent 352f4ad commit 7abc379

6 files changed

Lines changed: 64 additions & 10 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ foundry.lock
88
# Environment variables
99
.env
1010
*.env
11+
*.venv/
12+
13+
# Hardhat
14+
artifacts/
1115

1216
# Logs
1317
*.log
@@ -27,6 +31,8 @@ lib/*
2731

2832
# OS
2933
.DS_Store
34+
.idea/
35+
.vscode/
3036
Thumbs.db
3137

3238
# misc

script/DeployDev.s.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ contract DeployDev is Script {
3535
StakeEngine stake = new StakeEngine(address(token));
3636
ScoreEngine score = new ScoreEngine(
3737
address(registry),
38-
address(graph),
39-
address(stake)
38+
address(stake),
39+
address(graph)
4040
);
4141
ProtocolViews views_ = new ProtocolViews(
4242
address(registry),
@@ -45,6 +45,10 @@ contract DeployDev is Script {
4545
address(score)
4646
);
4747

48+
// CRITICAL: StakeEngine must be allowed to mint/burn for epoch settlement
49+
authority.setMinter(address(stake), true);
50+
authority.setBurner(address(stake), true);
51+
4852
// Wire registry <-> graph
4953
graph.setRegistry(address(registry));
5054
registry.setLinkGraph(address(graph));

script/DeployMainnet.s.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ contract DeployMainnet is Script {
3434
StakeEngine stake = new StakeEngine(address(token));
3535
ScoreEngine score = new ScoreEngine(
3636
address(registry),
37-
address(graph),
38-
address(stake)
37+
address(stake),
38+
address(graph)
3939
);
4040
ProtocolViews views_ = new ProtocolViews(
4141
address(registry),
@@ -44,6 +44,10 @@ contract DeployMainnet is Script {
4444
address(score)
4545
);
4646

47+
// CRITICAL: StakeEngine must be allowed to mint/burn for epoch settlement
48+
authority.setMinter(address(stake), true);
49+
authority.setBurner(address(stake), true);
50+
4751
// Wire registry <-> graph
4852
graph.setRegistry(address(registry));
4953
registry.setLinkGraph(address(graph));

script/DeployTestnet.s.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ contract DeployTestnet is Script {
3434
StakeEngine stake = new StakeEngine(address(token));
3535
ScoreEngine score = new ScoreEngine(
3636
address(registry),
37-
address(graph),
38-
address(stake)
37+
address(stake),
38+
address(graph)
3939
);
4040
ProtocolViews views_ = new ProtocolViews(
4141
address(registry),
@@ -44,6 +44,10 @@ contract DeployTestnet is Script {
4444
address(score)
4545
);
4646

47+
// CRITICAL: StakeEngine must be allowed to mint/burn for epoch settlement
48+
authority.setMinter(address(stake), true);
49+
authority.setBurner(address(stake), true);
50+
4751
// Wire registry <-> graph
4852
graph.setRegistry(address(registry));
4953
registry.setLinkGraph(address(graph));

src/ScoreEngine.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ contract ScoreEngine {
3636
uint256 postingFee = stake.postingFeeThreshold();
3737

3838
uint256 T = A + D;
39+
40+
// Always safe on empty.
41+
if (T == 0) return 0;
42+
43+
// Economic gating.
3944
if (T < postingFee) return 0;
4045

41-
// Inject posting fee as virtual support
46+
// Inject posting fee as virtual support (only once active)
4247
uint256 Aeff = A + postingFee;
4348
uint256 Teff = Aeff + D;
4449

50+
// Teff can't be 0 here because T>=postingFee and T>0, and Aeff>=A>=0.
4551
int256 num = int256(2 * Aeff) * RAY;
4652
int256 vs = (num / int256(Teff)) - RAY;
4753

@@ -91,6 +97,7 @@ contract ScoreEngine {
9197
int256 linkVS = baseVSRay(linkPostId);
9298
if (e.isChallenge) linkVS = -linkVS;
9399

100+
// contrib = (linkVS * icVS) * (linkStake / sumOutgoing)
94101
int256 contrib = (linkVS * icVS) / RAY;
95102
contrib = (contrib * int256(linkStake)) / int256(sumOutgoing);
96103

@@ -114,7 +121,10 @@ contract ScoreEngine {
114121
view
115122
returns (bool)
116123
{
117-
return _totalStake(postId) >= threshold;
124+
// If threshold is accidentally set to 0, still treat empty as inactive.
125+
uint256 t = _totalStake(postId);
126+
if (t == 0) return false;
127+
return t >= threshold;
118128
}
119129

120130
function _sumOutgoingLinkStake(uint256 ic, uint256 threshold)

src/StakeEngine.sol

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ contract StakeEngine {
4545
uint256 public constant P_MIN = 1e17;
4646
uint256 public constant P_MAX = 1e18;
4747

48+
/// @notice Minimum total stake required for a post to be economically active (ScoreEngine gating).
49+
/// @dev MUST be non-zero to avoid accidental "active when empty" semantics.
4850
uint256 public postingFeeThreshold;
4951

5052
error InvalidSide();
@@ -62,6 +64,24 @@ contract StakeEngine {
6264
if (vspToken_ == address(0)) revert ZeroAddressToken();
6365
ERC20_TOKEN = IERC20(vspToken_);
6466
VSP_TOKEN = IVSPToken(vspToken_);
67+
68+
// Keep tests + ScoreEngine semantics sane: "empty post" must not be active.
69+
// Tests use raw small units (1, 10, 100) so use 1 (not 1e18).
70+
postingFeeThreshold = 1;
71+
}
72+
73+
// ------------------------------------------------------------------------
74+
// Views (required by IStakeEngine consumers)
75+
// ------------------------------------------------------------------------
76+
77+
function getPostTotals(uint256 postId)
78+
external
79+
view
80+
returns (uint256 support, uint256 challenge)
81+
{
82+
PostState storage ps = posts[postId];
83+
support = ps.sides[SIDE_SUPPORT].total;
84+
challenge = ps.sides[SIDE_CHALLENGE].total;
6585
}
6686

6787
// ------------------------------------------------------------------------
@@ -172,8 +192,14 @@ contract StakeEngine {
172192
uint256 minted = mintS + mintC;
173193
uint256 burned = burnS + burnC;
174194

175-
if (minted > 0) VSP_TOKEN.mint(address(this), minted);
176-
if (burned > 0) VSP_TOKEN.burn(burned);
195+
if (minted > 0) {
196+
VSP_TOKEN.mint(address(this), minted);
197+
emit EpochMinted(postId, minted);
198+
}
199+
if (burned > 0) {
200+
VSP_TOKEN.burn(burned);
201+
emit EpochBurned(postId, burned);
202+
}
177203

178204
_recomputePostTotals(postId);
179205

0 commit comments

Comments
 (0)