Skip to content

Commit 5e09533

Browse files
authored
Merge pull request #1108 from graphprotocol/tmigone/horizon-subgraph-fixes
2 parents 7bceb49 + 375c78f commit 5e09533

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ interface IHorizonStakingMain {
244244
/**
245245
* @notice Emitted when a thaw request is created.
246246
* @dev Can be emitted by the service provider when thawing stake or by the delegator when undelegating.
247+
* @param requestType The type of thaw request
247248
* @param serviceProvider The address of the service provider
248249
* @param verifier The address of the verifier
249250
* @param owner The address of the owner of the thaw request.
@@ -252,23 +253,26 @@ interface IHorizonStakingMain {
252253
* @param thawRequestId The ID of the thaw request
253254
*/
254255
event ThawRequestCreated(
256+
IHorizonStakingTypes.ThawRequestType indexed requestType,
255257
address indexed serviceProvider,
256258
address indexed verifier,
257-
address indexed owner,
259+
address owner,
258260
uint256 shares,
259261
uint64 thawingUntil,
260262
bytes32 thawRequestId
261263
);
262264

263265
/**
264266
* @notice Emitted when a thaw request is fulfilled, meaning the stake is released.
267+
* @param requestType The type of thaw request
265268
* @param thawRequestId The ID of the thaw request
266269
* @param tokens The amount of tokens being released
267270
* @param shares The amount of shares being released
268271
* @param thawingUntil The timestamp until the stake has thawed
269272
* @param valid Whether the thaw request was valid at the time of fulfillment
270273
*/
271274
event ThawRequestFulfilled(
275+
IHorizonStakingTypes.ThawRequestType indexed requestType,
272276
bytes32 indexed thawRequestId,
273277
uint256 tokens,
274278
uint256 shares,
@@ -286,12 +290,12 @@ interface IHorizonStakingMain {
286290
* @param requestType The type of thaw request
287291
*/
288292
event ThawRequestsFulfilled(
293+
IHorizonStakingTypes.ThawRequestType indexed requestType,
289294
address indexed serviceProvider,
290295
address indexed verifier,
291-
address indexed owner,
296+
address owner,
292297
uint256 thawRequestsFulfilled,
293-
uint256 tokens,
294-
IHorizonStakingTypes.ThawRequestType requestType
298+
uint256 tokens
295299
);
296300

297301
// -- Events: governance --

packages/horizon/contracts/staking/HorizonStaking.sol

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
229229
newThawingPeriod <= _maxThawingPeriod,
230230
HorizonStakingInvalidThawingPeriod(newThawingPeriod, _maxThawingPeriod)
231231
);
232+
233+
// Provision must exist
232234
Provision storage prov = _provisions[serviceProvider][verifier];
233235
require(prov.createdAt != 0, HorizonStakingInvalidProvision(serviceProvider, verifier));
234236

@@ -244,7 +246,11 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
244246
*/
245247
function acceptProvisionParameters(address serviceProvider) external override notPaused {
246248
address verifier = msg.sender;
249+
250+
// Provision must exist
247251
Provision storage prov = _provisions[serviceProvider][verifier];
252+
require(prov.createdAt != 0, HorizonStakingInvalidProvision(serviceProvider, verifier));
253+
248254
if ((prov.maxVerifierCutPending != prov.maxVerifierCut) || (prov.thawingPeriodPending != prov.thawingPeriod)) {
249255
prov.maxVerifierCut = prov.maxVerifierCutPending;
250256
prov.thawingPeriod = prov.thawingPeriodPending;
@@ -1026,7 +1032,15 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
10261032
if (thawRequestList.count != 0) _getThawRequest(_requestType, thawRequestList.tail).next = thawRequestId;
10271033
thawRequestList.addTail(thawRequestId);
10281034

1029-
emit ThawRequestCreated(_serviceProvider, _verifier, _owner, _shares, _thawingUntil, thawRequestId);
1035+
emit ThawRequestCreated(
1036+
_requestType,
1037+
_serviceProvider,
1038+
_verifier,
1039+
_owner,
1040+
_shares,
1041+
_thawingUntil,
1042+
thawRequestId
1043+
);
10301044
return thawRequestId;
10311045
}
10321046

@@ -1052,12 +1066,12 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
10521066
TraverseThawRequestsResults memory results = _traverseThawRequests(_params, thawRequestList);
10531067

10541068
emit ThawRequestsFulfilled(
1069+
_params.requestType,
10551070
_params.serviceProvider,
10561071
_params.verifier,
10571072
_params.owner,
10581073
results.requestsFulfilled,
1059-
results.tokensThawed,
1060-
_params.requestType
1074+
results.tokensThawed
10611075
);
10621076

10631077
return (results.tokensThawed, results.tokensThawing, results.sharesThawing);
@@ -1143,6 +1157,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
11431157
tokensThawed = tokensThawed + tokens;
11441158
}
11451159
emit ThawRequestFulfilled(
1160+
requestType,
11461161
_thawRequestId,
11471162
tokens,
11481163
thawRequest.shares,

packages/horizon/hardhat.config.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,25 @@ import '@nomicfoundation/hardhat-ignition-ethers'
77
import 'hardhat-storage-layout'
88
import 'hardhat-contract-sizer'
99
import 'hardhat-secure-accounts'
10+
import { HardhatUserConfig } from 'hardhat/types'
1011

1112
// Skip importing hardhat-graph-protocol when building the project, it has circular dependency
1213
if (process.env.BUILD_RUN !== 'true') {
1314
require('hardhat-graph-protocol')
1415
require('./tasks/deploy')
1516
}
1617

17-
export default hardhatBaseConfig
18+
const config: HardhatUserConfig = {
19+
...hardhatBaseConfig,
20+
solidity: {
21+
version: '0.8.27',
22+
settings: {
23+
optimizer: {
24+
enabled: true,
25+
runs: 70,
26+
},
27+
},
28+
},
29+
}
30+
31+
export default config

packages/horizon/test/shared/horizon-staking/HorizonStakingShared.t.sol

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
420420
// thaw
421421
vm.expectEmit(address(staking));
422422
emit IHorizonStakingMain.ThawRequestCreated(
423+
IHorizonStakingTypes.ThawRequestType.Provision,
423424
serviceProvider,
424425
verifier,
425426
serviceProvider,
@@ -505,6 +506,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
505506
ThawRequest memory thawRequest = calcValues.thawRequestsFulfilledList[i];
506507
vm.expectEmit(address(staking));
507508
emit IHorizonStakingMain.ThawRequestFulfilled(
509+
params.thawRequestType,
508510
calcValues.thawRequestsFulfilledListIds[i],
509511
calcValues.thawRequestsFulfilledListTokens[i],
510512
thawRequest.shares,
@@ -514,12 +516,12 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
514516
}
515517
vm.expectEmit(address(staking));
516518
emit IHorizonStakingMain.ThawRequestsFulfilled(
519+
IHorizonStakingTypes.ThawRequestType.Provision,
517520
serviceProvider,
518521
verifier,
519522
serviceProvider,
520523
calcValues.thawRequestsFulfilledList.length,
521-
calcValues.tokensThawed,
522-
IHorizonStakingTypes.ThawRequestType.Provision
524+
calcValues.tokensThawed
523525
);
524526
vm.expectEmit(address(staking));
525527
emit IHorizonStakingMain.TokensDeprovisioned(serviceProvider, verifier, calcValues.tokensThawed);
@@ -627,6 +629,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
627629
ThawRequest memory thawRequest = calcValues.thawRequestsFulfilledList[i];
628630
vm.expectEmit(address(staking));
629631
emit IHorizonStakingMain.ThawRequestFulfilled(
632+
params.thawRequestType,
630633
calcValues.thawRequestsFulfilledListIds[i],
631634
calcValues.thawRequestsFulfilledListTokens[i],
632635
thawRequest.shares,
@@ -636,12 +639,12 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
636639
}
637640
vm.expectEmit(address(staking));
638641
emit IHorizonStakingMain.ThawRequestsFulfilled(
642+
IHorizonStakingTypes.ThawRequestType.Provision,
639643
serviceProvider,
640644
verifier,
641645
serviceProvider,
642646
calcValues.thawRequestsFulfilledList.length,
643-
calcValues.tokensThawed,
644-
IHorizonStakingTypes.ThawRequestType.Provision
647+
calcValues.tokensThawed
645648
);
646649
vm.expectEmit(address(staking));
647650
emit IHorizonStakingMain.TokensDeprovisioned(serviceProvider, verifier, calcValues.tokensThawed);
@@ -998,6 +1001,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
9981001
// undelegate
9991002
vm.expectEmit();
10001003
emit IHorizonStakingMain.ThawRequestCreated(
1004+
thawRequestType,
10011005
serviceProvider,
10021006
verifier,
10031007
beneficiary,
@@ -1163,6 +1167,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
11631167
ThawRequest memory thawRequest = calcValues.thawRequestsFulfilledList[i];
11641168
vm.expectEmit(address(staking));
11651169
emit IHorizonStakingMain.ThawRequestFulfilled(
1170+
params.thawRequestType,
11661171
calcValues.thawRequestsFulfilledListIds[i],
11671172
calcValues.thawRequestsFulfilledListTokens[i],
11681173
thawRequest.shares,
@@ -1172,12 +1177,12 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
11721177
}
11731178
vm.expectEmit(address(staking));
11741179
emit IHorizonStakingMain.ThawRequestsFulfilled(
1180+
params.thawRequestType,
11751181
params.serviceProvider,
11761182
params.verifier,
11771183
msgSender,
11781184
calcValues.thawRequestsFulfilledList.length,
1179-
calcValues.tokensThawed,
1180-
params.thawRequestType
1185+
calcValues.tokensThawed
11811186
);
11821187
if (calcValues.tokensThawed != 0) {
11831188
vm.expectEmit();

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ contract HorizonStakingProvisionParametersTest is HorizonStakingTest {
8282
vm.stopPrank();
8383
}
8484

85+
86+
function test_ProvisionParametersAccept_SameParameters(
87+
uint256 amount,
88+
uint32 maxVerifierCut,
89+
uint64 thawingPeriod
90+
) public useIndexer useProvision(amount, maxVerifierCut, thawingPeriod) {
91+
_setProvisionParameters(users.indexer, subgraphDataServiceAddress, maxVerifierCut, thawingPeriod);
92+
93+
vm.startPrank(subgraphDataServiceAddress);
94+
_acceptProvisionParameters(users.indexer);
95+
_acceptProvisionParameters(users.indexer);
96+
vm.stopPrank();
97+
}
98+
8599
function test_ProvisionParameters_RevertIf_InvalidMaxVerifierCut(
86100
uint256 amount,
87101
uint32 maxVerifierCut,
@@ -111,4 +125,16 @@ contract HorizonStakingProvisionParametersTest is HorizonStakingTest {
111125
);
112126
staking.setProvisionParameters(users.indexer, subgraphDataServiceAddress, maxVerifierCut, thawingPeriod);
113127
}
128+
129+
function test_ProvisionParametersAccept_RevertWhen_ProvisionNotExists() public useIndexer {
130+
resetPrank(subgraphDataServiceAddress);
131+
vm.expectRevert(
132+
abi.encodeWithSignature(
133+
"HorizonStakingInvalidProvision(address,address)",
134+
users.indexer,
135+
subgraphDataServiceAddress
136+
)
137+
);
138+
staking.acceptProvisionParameters(users.indexer);
139+
}
114140
}

0 commit comments

Comments
 (0)