Skip to content

Commit 26e4dc7

Browse files
committed
fix: getThawedTokens calculation (TRST-L03)
1 parent 07ef418 commit 26e4dc7

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/horizon/contracts/staking/HorizonStakingBase.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,25 @@ abstract contract HorizonStakingBase is
206206
return 0;
207207
}
208208

209-
uint256 tokens = 0;
209+
uint256 thawedTokens = 0;
210210
Provision storage prov = _provisions[serviceProvider][verifier];
211+
uint256 tokensThawing = prov.tokensThawing;
212+
uint256 sharesThawing = prov.sharesThawing;
211213

212214
bytes32 thawRequestId = thawRequestList.head;
213215
while (thawRequestId != bytes32(0)) {
214216
ThawRequest storage thawRequest = _getThawRequest(requestType, thawRequestId);
215217
if (thawRequest.thawingUntil <= block.timestamp) {
216-
tokens += (thawRequest.shares * prov.tokensThawing) / prov.sharesThawing;
218+
uint256 tokens = (thawRequest.shares * tokensThawing) / sharesThawing;
219+
tokensThawing = tokensThawing - tokens;
220+
sharesThawing = sharesThawing - thawRequest.shares;
221+
thawedTokens = thawedTokens + tokens;
217222
} else {
218223
break;
219224
}
220225
thawRequestId = thawRequest.next;
221226
}
222-
return tokens;
227+
return thawedTokens;
223228
}
224229

225230
/**

packages/horizon/test/staking/provision/thaw.t.sol

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,28 @@ contract HorizonStakingThawTest is HorizonStakingTest {
139139
resetPrank(users.indexer);
140140
_thaw(users.indexer, subgraphDataServiceAddress, thawAmount);
141141
}
142+
143+
function testThaw_GetThawedTokens(
144+
uint256 amount,
145+
uint64 thawingPeriod,
146+
uint256 thawSteps
147+
) public useIndexer useProvision(amount, 0, thawingPeriod) {
148+
thawSteps = bound(thawSteps, 1, 10);
149+
150+
uint256 thawAmount = amount / thawSteps;
151+
vm.assume(thawAmount > 0);
152+
for (uint256 i = 0; i < thawSteps; i++) {
153+
_thaw(users.indexer, subgraphDataServiceAddress, thawAmount);
154+
}
155+
156+
skip(thawingPeriod + 1);
157+
158+
uint256 thawedTokens = staking.getThawedTokens(
159+
ThawRequestType.Provision,
160+
users.indexer,
161+
subgraphDataServiceAddress,
162+
users.indexer
163+
);
164+
vm.assertEq(thawedTokens, thawAmount * thawSteps);
165+
}
142166
}

0 commit comments

Comments
 (0)