From 177fcdfd40b67550d4a5fbd62069f12731ffcd8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Migone?= Date: Mon, 9 Sep 2024 16:20:49 -0300 Subject: [PATCH] chore: use solidity 0.8.27 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Migone --- packages/subgraph-service/foundry.toml | 10 +- packages/subgraph-service/package.json | 2 +- .../test/disputeManager/DisputeManager.t.sol | 61 ++++++----- .../disputeManager/disputes/disputes.t.sol | 2 +- .../disputes/indexing/accept.t.sol | 2 +- .../disputes/indexing/cancel.t.sol | 2 +- .../disputes/indexing/create.t.sol | 2 +- .../disputes/indexing/draw.t.sol | 2 +- .../disputes/indexing/reject.t.sol | 2 +- .../disputes/query/accept.t.sol | 2 +- .../disputes/query/cancel.t.sol | 2 +- .../disputes/query/create.t.sol | 2 +- .../disputeManager/disputes/query/draw.t.sol | 2 +- .../disputes/query/reject.t.sol | 2 +- .../disputes/queryConflict/accept.t.sol | 2 +- .../disputes/queryConflict/cancel.t.sol | 2 +- .../disputes/queryConflict/create.t.sol | 2 +- .../disputes/queryConflict/draw.t.sol | 2 +- .../disputes/queryConflict/reject.t.sol | 2 +- .../governance/arbitrator.t.sol | 2 +- .../governance/disputeDeposit.t.sol | 2 +- .../governance/maxSlashingCut.t.sol | 2 +- .../test/shared/HorizonStakingShared.t.sol | 2 +- .../subgraphService/SubgraphService.t.sol | 101 ++++++++++++------ .../allocation/closeStale.t.sol | 2 +- .../subgraphService/allocation/resize.t.sol | 2 +- .../subgraphService/allocation/start.t.sol | 2 +- .../collect/indexing/indexing.t.sol | 2 +- .../subgraphService/collect/query/query.t.sol | 2 +- .../provider/rewardsDestination.t.sol | 2 +- 30 files changed, 136 insertions(+), 90 deletions(-) diff --git a/packages/subgraph-service/foundry.toml b/packages/subgraph-service/foundry.toml index 235a58eb9..9f5c3a92a 100644 --- a/packages/subgraph-service/foundry.toml +++ b/packages/subgraph-service/foundry.toml @@ -4,14 +4,6 @@ out = 'build' libs = ['node_modules', 'lib'] test = 'test' cache_path = 'cache_forge' +fs_permissions = [{ access = "read", path = "./"}] optimizer = true optimizer-runs = 200 -via_ir = true -fs_permissions = [{ access = "read", path = "./"}] - -[profile.lite] -optimizer = false -optimizer-runs = 1 - -[profile.lite.optimizer_details.yulDetails] -optimizerSteps = ':' \ No newline at end of file diff --git a/packages/subgraph-service/package.json b/packages/subgraph-service/package.json index da7b33a3d..bb5dd9ea9 100644 --- a/packages/subgraph-service/package.json +++ b/packages/subgraph-service/package.json @@ -10,7 +10,7 @@ "lint": "yarn lint:ts && yarn lint:sol", "clean": "rm -rf build cache typechain-types", "build": "forge build && hardhat compile", - "test": "FOUNDRY_PROFILE=lite forge test -vvvv && hardhat test" + "test": "forge test && hardhat test" }, "devDependencies": { "@graphprotocol/contracts": "workspace:^7.0.0", diff --git a/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol b/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol index 685150e62..0d99aec0b 100644 --- a/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol +++ b/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol @@ -166,54 +166,67 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { return _disputeID; } + struct BeforeValues_CreateQueryDisputeConflict { + Attestation.State attestation1; + Attestation.State attestation2; + address indexer1; + address indexer2; + uint256 stakeSnapshot1; + uint256 stakeSnapshot2; + } function _createQueryDisputeConflict( bytes memory attestationData1, bytes memory attestationData2 ) internal returns (bytes32, bytes32) { (, address fisherman,) = vm.readCallers(); - Attestation.State memory attestation1 = Attestation.parse(attestationData1); - Attestation.State memory attestation2 = Attestation.parse(attestationData2); - address indexer1 = disputeManager.getAttestationIndexer(attestation1); - address indexer2 = disputeManager.getAttestationIndexer(attestation2); + + BeforeValues_CreateQueryDisputeConflict memory beforeValues; + beforeValues.attestation1 = Attestation.parse(attestationData1); + beforeValues.attestation2 = Attestation.parse(attestationData2); + beforeValues.indexer1 = disputeManager.getAttestationIndexer(beforeValues.attestation1); + beforeValues.indexer2 = disputeManager.getAttestationIndexer(beforeValues.attestation2); + beforeValues.stakeSnapshot1 = disputeManager.getStakeSnapshot(beforeValues.indexer1); + beforeValues.stakeSnapshot2 = disputeManager.getStakeSnapshot(beforeValues.indexer2); + bytes32 expectedDisputeId1 = keccak256( abi.encodePacked( - attestation1.requestCID, - attestation1.responseCID, - attestation1.subgraphDeploymentId, - indexer1, + beforeValues.attestation1.requestCID, + beforeValues.attestation1.responseCID, + beforeValues.attestation1.subgraphDeploymentId, + beforeValues.indexer1, fisherman ) ); bytes32 expectedDisputeId2 = keccak256( abi.encodePacked( - attestation2.requestCID, - attestation2.responseCID, - attestation2.subgraphDeploymentId, - indexer2, + beforeValues.attestation2.requestCID, + beforeValues.attestation2.responseCID, + beforeValues.attestation2.subgraphDeploymentId, + beforeValues.indexer2, fisherman ) ); - uint256 stakeSnapshot1 = disputeManager.getStakeSnapshot(indexer1); - uint256 stakeSnapshot2 = disputeManager.getStakeSnapshot(indexer2); + // createQueryDisputeConflict vm.expectEmit(address(disputeManager)); emit IDisputeManager.QueryDisputeCreated( expectedDisputeId1, - indexer1, + beforeValues.indexer1, fisherman, 0, - attestation1.subgraphDeploymentId, + beforeValues.attestation1.subgraphDeploymentId, attestationData1, - stakeSnapshot1 + beforeValues.stakeSnapshot1 ); + vm.expectEmit(address(disputeManager)); emit IDisputeManager.QueryDisputeCreated( expectedDisputeId2, - indexer2, + beforeValues.indexer2, fisherman, 0, - attestation2.subgraphDeploymentId, + beforeValues.attestation2.subgraphDeploymentId, attestationData2, - stakeSnapshot2 + beforeValues.stakeSnapshot2 ); (bytes32 _disputeId1, bytes32 _disputeId2) = disputeManager.createQueryDisputeConflict(attestationData1, attestationData2); @@ -226,24 +239,24 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { // Check dispute values IDisputeManager.Dispute memory dispute1 = _getDispute(_disputeId1); - assertEq(dispute1.indexer, indexer1, "Indexer 1 should match"); + assertEq(dispute1.indexer, beforeValues.indexer1, "Indexer 1 should match"); assertEq(dispute1.fisherman, fisherman, "Fisherman 1 should match"); assertEq(dispute1.deposit, 0, "Deposit 1 should match"); assertEq(dispute1.relatedDisputeId, _disputeId2, "Related dispute ID 1 should be the id of the other dispute"); assertEq(uint8(dispute1.disputeType), uint8(IDisputeManager.DisputeType.QueryDispute), "Dispute type 1 should be query"); assertEq(uint8(dispute1.status), uint8(IDisputeManager.DisputeStatus.Pending), "Dispute status 1 should be pending"); assertEq(dispute1.createdAt, block.timestamp, "Created at 1 should match"); - assertEq(dispute1.stakeSnapshot, stakeSnapshot1, "Stake snapshot 1 should match"); + assertEq(dispute1.stakeSnapshot, beforeValues.stakeSnapshot1, "Stake snapshot 1 should match"); IDisputeManager.Dispute memory dispute2 = _getDispute(_disputeId2); - assertEq(dispute2.indexer, indexer2, "Indexer 2 should match"); + assertEq(dispute2.indexer, beforeValues.indexer2, "Indexer 2 should match"); assertEq(dispute2.fisherman, fisherman, "Fisherman 2 should match"); assertEq(dispute2.deposit, 0, "Deposit 2 should match"); assertEq(dispute2.relatedDisputeId, _disputeId1, "Related dispute ID 2 should be the id of the other dispute"); assertEq(uint8(dispute2.disputeType), uint8(IDisputeManager.DisputeType.QueryDispute), "Dispute type 2 should be query"); assertEq(uint8(dispute2.status), uint8(IDisputeManager.DisputeStatus.Pending), "Dispute status 2 should be pending"); assertEq(dispute2.createdAt, block.timestamp, "Created at 2 should match"); - assertEq(dispute2.stakeSnapshot, stakeSnapshot2, "Stake snapshot 2 should match"); + assertEq(dispute2.stakeSnapshot, beforeValues.stakeSnapshot2, "Stake snapshot 2 should match"); return (_disputeId1, _disputeId2); } diff --git a/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol b/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol index cd229dbc4..b6b4a6890 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol b/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol index 5e0d36132..49bee9e26 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/indexing/cancel.t.sol b/packages/subgraph-service/test/disputeManager/disputes/indexing/cancel.t.sol index 0a09ad7f4..1639f2cad 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/indexing/cancel.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/indexing/cancel.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/indexing/create.t.sol b/packages/subgraph-service/test/disputeManager/disputes/indexing/create.t.sol index 0174315a2..8d1b75c21 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/indexing/create.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/indexing/create.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/indexing/draw.t.sol b/packages/subgraph-service/test/disputeManager/disputes/indexing/draw.t.sol index 3df590f74..7ce70d962 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/indexing/draw.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/indexing/draw.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/indexing/reject.t.sol b/packages/subgraph-service/test/disputeManager/disputes/indexing/reject.t.sol index 5401c0afe..41b5adabc 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/indexing/reject.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/indexing/reject.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol b/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol index d0f00234d..7670d381e 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/query/cancel.t.sol b/packages/subgraph-service/test/disputeManager/disputes/query/cancel.t.sol index a61db6ad9..5a70e2f70 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/query/cancel.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/query/cancel.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/query/create.t.sol b/packages/subgraph-service/test/disputeManager/disputes/query/create.t.sol index 01f27cf66..4eba11744 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/query/create.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/query/create.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/query/draw.t.sol b/packages/subgraph-service/test/disputeManager/disputes/query/draw.t.sol index 1b9c96ad2..2ff182378 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/query/draw.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/query/draw.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/query/reject.t.sol b/packages/subgraph-service/test/disputeManager/disputes/query/reject.t.sol index 07c738a90..fff210ea6 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/query/reject.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/query/reject.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol index 1cfde0a8c..46a6d4bdd 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/cancel.t.sol b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/cancel.t.sol index 4de2b3155..36d14fab2 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/cancel.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/cancel.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/create.t.sol b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/create.t.sol index 2f54983ae..edd2d545b 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/create.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/create.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/draw.t.sol b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/draw.t.sol index 5127b56a5..5444936cc 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/draw.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/draw.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol index 078969267..ff347f7d2 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/governance/arbitrator.t.sol b/packages/subgraph-service/test/disputeManager/governance/arbitrator.t.sol index 53e36a497..1277235fd 100644 --- a/packages/subgraph-service/test/disputeManager/governance/arbitrator.t.sol +++ b/packages/subgraph-service/test/disputeManager/governance/arbitrator.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol b/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol index 163157886..1df13acb2 100644 --- a/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol +++ b/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/disputeManager/governance/maxSlashingCut.t.sol b/packages/subgraph-service/test/disputeManager/governance/maxSlashingCut.t.sol index 343e514bc..a554f774c 100644 --- a/packages/subgraph-service/test/disputeManager/governance/maxSlashingCut.t.sol +++ b/packages/subgraph-service/test/disputeManager/governance/maxSlashingCut.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/shared/HorizonStakingShared.t.sol b/packages/subgraph-service/test/shared/HorizonStakingShared.t.sol index 28a22e1a2..e07516903 100644 --- a/packages/subgraph-service/test/shared/HorizonStakingShared.t.sol +++ b/packages/subgraph-service/test/shared/HorizonStakingShared.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol index e9c3d5529..05c038680 100644 --- a/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol +++ b/packages/subgraph-service/test/subgraphService/SubgraphService.t.sol @@ -30,7 +30,7 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { * MODIFIERS */ - modifier useOperator { + modifier useOperator() { resetPrank(users.indexer); staking.setOperator(users.operator, address(subgraphService), true); resetPrank(users.operator); @@ -38,7 +38,7 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { vm.stopPrank(); } - modifier useRewardsDestination { + modifier useRewardsDestination() { _setRewardsDestination(users.rewardsDestination); _; } @@ -74,10 +74,10 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { uint64 thawingPeriod = provision.thawingPeriod; uint32 maxVerifierCutPending = provision.maxVerifierCutPending; uint64 thawingPeriodPending = provision.thawingPeriodPending; - + vm.expectEmit(address(subgraphService)); emit IDataService.ProvisionAccepted(_indexer); - + // Accept provision subgraphService.acceptProvision(_indexer, _data); @@ -110,7 +110,13 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { } vm.expectEmit(address(subgraphService)); - emit AllocationManager.AllocationResized(_indexer, _allocationId, subgraphDeploymentId, _tokens, beforeSubgraphAllocatedTokens); + emit AllocationManager.AllocationResized( + _indexer, + _allocationId, + subgraphDeploymentId, + _tokens, + beforeSubgraphAllocatedTokens + ); // resize allocation subgraphService.resizeAllocation(_indexer, _allocationId, _tokens); @@ -119,8 +125,12 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { uint256 afterSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens(subgraphDeploymentId); uint256 afterAllocatedTokens = subgraphService.allocationProvisionTracker(_indexer); Allocation.State memory afterAllocation = subgraphService.getAllocation(_allocationId); - uint256 accRewardsPerAllocatedTokenDelta = afterAllocation.accRewardsPerAllocatedToken - beforeAllocation.accRewardsPerAllocatedToken; - uint256 afterAccRewardsPending = rewardsManager.calcRewards(beforeAllocation.tokens, accRewardsPerAllocatedTokenDelta); + uint256 accRewardsPerAllocatedTokenDelta = afterAllocation.accRewardsPerAllocatedToken - + beforeAllocation.accRewardsPerAllocatedToken; + uint256 afterAccRewardsPending = rewardsManager.calcRewards( + beforeAllocation.tokens, + accRewardsPerAllocatedTokenDelta + ); // check state if (_tokens > beforeAllocation.tokens) { @@ -138,10 +148,17 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { assertTrue(subgraphService.isActiveAllocation(_allocationId)); Allocation.State memory allocation = subgraphService.getAllocation(_allocationId); - uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens(allocation.subgraphDeploymentId); - + uint256 previousSubgraphAllocatedTokens = subgraphService.getSubgraphAllocatedTokens( + allocation.subgraphDeploymentId + ); + vm.expectEmit(address(subgraphService)); - emit AllocationManager.AllocationClosed(allocation.indexer, _allocationId, allocation.subgraphDeploymentId, allocation.tokens); + emit AllocationManager.AllocationClosed( + allocation.indexer, + _allocationId, + allocation.subgraphDeploymentId, + allocation.tokens + ); // close stale allocation subgraphService.closeStaleAllocation(_allocationId); @@ -182,15 +199,20 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { uint256 paymentCollected = 0; Allocation.State memory allocation; CollectPaymentData memory collectPaymentDataBefore; - + // PaymentType.IndexingRewards variables IndexingRewardsData memory indexingRewardsData; - uint32 delegationRatio = subgraphService.delegationRatio(); address rewardsDestination = subgraphService.rewardsDestination(_indexer); collectPaymentDataBefore.rewardsDestinationBalance = token.balanceOf(rewardsDestination); - collectPaymentDataBefore.indexerProvisionBalance = staking.getProviderTokensAvailable(_indexer, address(subgraphService)); - collectPaymentDataBefore.delegationPoolBalance = staking.getDelegatedTokensAvailable(_indexer, address(subgraphService)); - + collectPaymentDataBefore.indexerProvisionBalance = staking.getProviderTokensAvailable( + _indexer, + address(subgraphService) + ); + collectPaymentDataBefore.delegationPoolBalance = staking.getDelegatedTokensAvailable( + _indexer, + address(subgraphService) + ); + // PaymentType.QueryFee variables QueryFeeData memory queryFeeData; queryFeeData.protocolPaymentCut = graphPayments.PROTOCOL_PAYMENT_CUT(); @@ -257,25 +279,38 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { // Collect payment data after CollectPaymentData memory collectPaymentDataAfter; collectPaymentDataAfter.rewardsDestinationBalance = token.balanceOf(rewardsDestination); - collectPaymentDataAfter.indexerProvisionBalance = staking.getProviderTokensAvailable(_indexer, address(subgraphService)); - collectPaymentDataAfter.delegationPoolBalance = staking.getDelegatedTokensAvailable(_indexer, address(subgraphService)); + collectPaymentDataAfter.indexerProvisionBalance = staking.getProviderTokensAvailable( + _indexer, + address(subgraphService) + ); + collectPaymentDataAfter.delegationPoolBalance = staking.getDelegatedTokensAvailable( + _indexer, + address(subgraphService) + ); collectPaymentDataAfter.indexerBalance = token.balanceOf(_indexer); collectPaymentDataAfter.curationBalance = token.balanceOf(address(curation)); collectPaymentDataAfter.lockedTokens = subgraphService.feesProvisionTracker(_indexer); if (_paymentType == IGraphPayments.PaymentTypes.QueryFee) { // Check indexer got paid the correct amount - uint256 tokensProtocol = paymentCollected.mulPPM(protocolPaymentCut); - uint256 curationTokens = paymentCollected.mulPPM(queryFeeData.curationCut); - uint256 expectedIndexerTokensPayment = paymentCollected - tokensProtocol - curationTokens; - assertEq(collectPaymentDataAfter.indexerBalance, collectPaymentDataBefore.indexerBalance + expectedIndexerTokensPayment); + { + uint256 tokensProtocol = paymentCollected.mulPPM(protocolPaymentCut); + uint256 curationTokens = paymentCollected.mulPPM(queryFeeData.curationCut); + uint256 expectedIndexerTokensPayment = paymentCollected - tokensProtocol - curationTokens; + assertEq( + collectPaymentDataAfter.indexerBalance, + collectPaymentDataBefore.indexerBalance + expectedIndexerTokensPayment + ); - // Check curation got paid the correct amount - assertEq(collectPaymentDataAfter.curationBalance, collectPaymentDataBefore.curationBalance + curationTokens); + // Check curation got paid the correct amount + assertEq( + collectPaymentDataAfter.curationBalance, + collectPaymentDataBefore.curationBalance + curationTokens + ); + } // Check locked tokens - uint256 stakeToFeesRatio = subgraphService.stakeToFeesRatio(); - uint256 tokensToLock = paymentCollected * stakeToFeesRatio; + uint256 tokensToLock = paymentCollected * subgraphService.stakeToFeesRatio(); assertEq(collectPaymentDataAfter.lockedTokens, collectPaymentDataBefore.lockedTokens + tokensToLock); // Check the stake claim @@ -290,10 +325,12 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { } else { // Update allocation after collecting rewards allocation = subgraphService.getAllocation(allocationId); - + // Check allocation state assertEq(allocation.accRewardsPending, 0); - uint256 accRewardsPerAllocatedToken = rewardsManager.onSubgraphAllocationUpdate(allocation.subgraphDeploymentId); + uint256 accRewardsPerAllocatedToken = rewardsManager.onSubgraphAllocationUpdate( + allocation.subgraphDeploymentId + ); assertEq(allocation.accRewardsPerAllocatedToken, accRewardsPerAllocatedToken); assertEq(allocation.lastPOIPresentedAt, block.timestamp); @@ -301,7 +338,7 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { if (rewardsDestination == address(0)) { // If rewards destination is address zero indexer should get paid to their provision balance assertEq( - collectPaymentDataAfter.indexerProvisionBalance, + collectPaymentDataAfter.indexerProvisionBalance, collectPaymentDataBefore.indexerProvisionBalance + indexingRewardsData.tokensIndexerRewards ); } else { @@ -314,12 +351,16 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest { // Check delegation pool got paid the correct amount assertEq( - collectPaymentDataAfter.delegationPoolBalance, + collectPaymentDataAfter.delegationPoolBalance, collectPaymentDataBefore.delegationPoolBalance + indexingRewardsData.tokensDelegationRewards ); // If after collecting indexing rewards the indexer is over allocated the allcation should close - uint256 tokensAvailable = staking.getTokensAvailable(_indexer, address(subgraphService), delegationRatio); + uint256 tokensAvailable = staking.getTokensAvailable( + _indexer, + address(subgraphService), + subgraphService.delegationRatio() + ); if (allocation.tokens <= tokensAvailable) { // Indexer isn't over allocated so allocation should still be open assertTrue(allocation.isOpen()); diff --git a/packages/subgraph-service/test/subgraphService/allocation/closeStale.t.sol b/packages/subgraph-service/test/subgraphService/allocation/closeStale.t.sol index 3e6672dd7..68d736261 100644 --- a/packages/subgraph-service/test/subgraphService/allocation/closeStale.t.sol +++ b/packages/subgraph-service/test/subgraphService/allocation/closeStale.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol b/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol index 3da7c5a0c..0df994929 100644 --- a/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol +++ b/packages/subgraph-service/test/subgraphService/allocation/resize.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/subgraphService/allocation/start.t.sol b/packages/subgraph-service/test/subgraphService/allocation/start.t.sol index 6db5e73db..9157444fb 100644 --- a/packages/subgraph-service/test/subgraphService/allocation/start.t.sol +++ b/packages/subgraph-service/test/subgraphService/allocation/start.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol b/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol index d51f9ea4b..8b29ec830 100644 --- a/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol +++ b/packages/subgraph-service/test/subgraphService/collect/indexing/indexing.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/subgraphService/collect/query/query.t.sol b/packages/subgraph-service/test/subgraphService/collect/query/query.t.sol index 9e20ad352..6ad7b5347 100644 --- a/packages/subgraph-service/test/subgraphService/collect/query/query.t.sol +++ b/packages/subgraph-service/test/subgraphService/collect/query/query.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol"; diff --git a/packages/subgraph-service/test/subgraphService/provider/rewardsDestination.t.sol b/packages/subgraph-service/test/subgraphService/provider/rewardsDestination.t.sol index 3926bc362..0b4c805b2 100644 --- a/packages/subgraph-service/test/subgraphService/provider/rewardsDestination.t.sol +++ b/packages/subgraph-service/test/subgraphService/provider/rewardsDestination.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.26; +pragma solidity 0.8.27; import "forge-std/Test.sol";