Skip to content

Commit def8026

Browse files
committed
fix: ignore thawing tokens on provision token check (TRST-L13)
Signed-off-by: Tomás Migone <[email protected]>
1 parent 0c0d090 commit def8026

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/horizon/contracts/data-service/utilities/ProvisionManager.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,16 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
202202

203203
/**
204204
* @notice Checks if the provision tokens of a service provider are within the valid range.
205+
* Note that thawing tokens are not considered in this check.
205206
* @param _provision The provision to check.
206207
*/
207208
function _checkProvisionTokens(IHorizonStaking.Provision memory _provision) internal view virtual {
208-
_checkValueInRange(_provision.tokens, minimumProvisionTokens, maximumProvisionTokens, "tokens");
209+
_checkValueInRange(
210+
_provision.tokens - _provision.tokensThawing,
211+
minimumProvisionTokens,
212+
maximumProvisionTokens,
213+
"tokens"
214+
);
209215
}
210216

211217
/**

packages/horizon/test/data-service/DataService.t.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ contract DataServiceTest is HorizonStakingSharedTest {
6565
assertEq(max, dataServiceOverride.PROVISION_TOKENS_MAX());
6666
}
6767

68+
function test_ProvisionTokens_WhenCheckingAValidProvision_WithThawing(uint256 tokens, uint256 tokensThaw) external useIndexer {
69+
dataService.setProvisionTokensRange(dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
70+
tokens = bound(tokens, dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
71+
tokensThaw = bound(tokensThaw, tokens - dataService.PROVISION_TOKENS_MIN() + 1, tokens);
72+
73+
_createProvision(users.indexer, address(dataService), tokens, 0, 0);
74+
staking.thaw(users.indexer, address(dataService), tokensThaw);
75+
vm.expectRevert(
76+
abi.encodeWithSelector(
77+
ProvisionManager.ProvisionManagerInvalidValue.selector,
78+
"tokens",
79+
tokens - tokensThaw,
80+
dataService.PROVISION_TOKENS_MIN(),
81+
dataService.PROVISION_TOKENS_MAX()
82+
)
83+
);
84+
dataService.checkProvisionTokens(users.indexer);
85+
}
86+
6887
function test_ProvisionTokens_WhenCheckingAValidProvision(uint256 tokens) external useIndexer {
6988
dataService.setProvisionTokensRange(dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
7089
tokens = bound(tokens, dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());

0 commit comments

Comments
 (0)