Skip to content

Commit eb910f0

Browse files
authored
feat: remove minimum allocation duration restriction (#902)
Signed-off-by: Tomás Migone <[email protected]>
1 parent ff8f0ed commit eb910f0

File tree

9 files changed

+54
-27
lines changed

9 files changed

+54
-27
lines changed

packages/contracts/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @graphprotocol/contracts
22

3+
## 6.3.0
4+
5+
### Minor Changes
6+
7+
- Remove restriction that prevented closing allocations older than 1 epoch.
8+
39
## 6.2.1
410

511
### Patch Changes

packages/contracts/addresses-staging.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@
134134
"txHash": "0x5ae51383f5ad1e434a78c2a6d5393d497be315c40287d827c63c4ca48cc66aca",
135135
"proxy": true,
136136
"implementation": {
137-
"address": "0xC4Cfde877Bc77fD93378D33Ec26330127Ed93bbE",
138-
"creationCodeHash": "0x9319aaf6b70b423fa04ad747f004961123e7833b269f69ecff902db13b010fa2",
139-
"runtimeCodeHash": "0x9a3f54b5f61709d40a71892f241f61fc72cf95346e5d928f1d699ea57065efc4",
140-
"txHash": "0x1e53eadecdb33a8e90e5c9bc3d02d438dd21217c5017b596b3e51f64be4501e2",
137+
"address": "0x0a6b1efb7b2e9A27Cf7C5ED1bdF1Bd03bF8F5600",
138+
"creationCodeHash": "0x60bc1fda6913ef750a1d931e87068d0f6cd62b8b42a4fff13b304b9c0c278557",
139+
"runtimeCodeHash": "0xd8bbd97b94f8ac45a479c55c0416e7b0ebef6a99da8ef7580bebaaad1d8d74d9",
140+
"txHash": "0x5d9276e47f3d1fa1fe5c6d826534722aa73d47f5a114e844de73a3cf0cb22d6b",
141141
"libraries": {
142-
"LibExponential": "0x6f6Db03f7F3bBE43669F81FD954Bd083FEdBb4a5"
142+
"LibExponential": "0xb7fB963257d4f31F88021d2D7Ee53688e38A0938"
143143
}
144144
}
145145
},

packages/contracts/addresses.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,12 @@
705705
"txHash": "0xa33c0d58ddaed7e3f7381a33e3d5f63e39219863019f00d54ce2fd2446076ac7",
706706
"proxy": true,
707707
"implementation": {
708-
"address": "0x4a886d3E44C7731Dcf888Da704CA5C51ed63DfC8",
709-
"creationCodeHash": "0xa9796308a637b0bfe091f32c1019e4db8efe4bab80788c052fa334e6810c3a98",
710-
"runtimeCodeHash": "0x19d3491cab54b2aae04d05525a532200e946ce9b55573b58f2e3e1606b4514be",
711-
"txHash": "0xc3235306a51c20b28a8b05da69859e03a081a84c9914156c79da07dcc45b3b4e",
708+
"address": "0x0Dae36adCbE384a31309269448E09465B2288429",
709+
"creationCodeHash": "0x7bd2944ba001c51a42d88f89b10eb894e11be62ee96e76331309ff6a8e9b20ff",
710+
"runtimeCodeHash": "0x0808fafef220cfddb64a51f680a18e455d5b7c6b9c0c7aad8f8067f4775dd204",
711+
"txHash": "0x6bdee0f03f74df2b7e6141075b06a88b201cbc78a131aa0fe6bb1ef1da1e2dc1",
712712
"libraries": {
713-
"LibExponential": "0x208f638d8804e4ccc874ec39e240feea3dc289ee"
713+
"LibExponential": "0x6F436161bBa439FB7D0A6192D22dd8fcE4C26Fb5"
714714
}
715715
}
716716
},
@@ -1146,12 +1146,12 @@
11461146
"txHash": "0x326cf1f2849da4bb4d7e39f2783779e3c99fa48e4ee8ef004cfdd50c62e775df",
11471147
"proxy": true,
11481148
"implementation": {
1149-
"address": "0xD07dFD514dc1b57020e6C1F49e05c48d0658C99f",
1150-
"creationCodeHash": "0x6a763345e5f166ea4e73ce9a116a49c9fc0833d9ea235a86fa5a997e91cf09e5",
1151-
"runtimeCodeHash": "0xb4c31859ac132241f04c802d4add70a94c7f2c6eb9dfd4bf224048d249dbc7bc",
1152-
"txHash": "0x68b34eda64287b84582c8f005c4e96162252d36c9c5c9b84332336a7c2e3d6d3",
1149+
"address": "0x64Ed77b164d3B22339DA4DB6d56a1C1d8A051c0A",
1150+
"creationCodeHash": "0x56a3dd587f3f4ae38dd782e9c35125fa7015c708394950de90bc190204502438",
1151+
"runtimeCodeHash": "0x9040ccf84a89ba2e7a32eb297f0da148827e7e272b20d9e57b1acf749baa35da",
1152+
"txHash": "0xbfec14a2dd1a571612076b71b4f2e78ea18f95d7d80e14cd1456ecaa7466db54",
11531153
"libraries": {
1154-
"LibExponential": "0xd844116f6d79a280b117Bb6d9EBf4121D4e8B44b"
1154+
"LibExponential": "0x413d16eF53d3dd8b7e769570115ee5419CF77C98"
11551155
}
11561156
}
11571157
},

packages/contracts/contracts/staking/Staking.sol

+8-6
Original file line numberDiff line numberDiff line change
@@ -775,18 +775,18 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
775775
// Get allocation
776776
Allocation memory alloc = __allocations[_allocationID];
777777

778-
// Validate that an allocation cannot be closed before one epoch
779778
alloc.closedAtEpoch = epochManager().currentEpoch();
779+
780+
// Allocation duration in epochs
780781
uint256 epochs = MathUtils.diffOrZero(alloc.closedAtEpoch, alloc.createdAtEpoch);
781-
require(epochs > 0, "<epochs");
782782

783783
// Indexer or operator can close an allocation
784784
// Anyone is allowed to close ONLY under two concurrent conditions
785785
// - After maxAllocationEpochs passed
786786
// - When the allocation is for non-zero amount of tokens
787-
bool isIndexer = _isAuth(alloc.indexer);
787+
bool isIndexerOrOperator = _isAuth(alloc.indexer);
788788
if (epochs <= __maxAllocationEpochs || alloc.tokens == 0) {
789-
require(isIndexer, "!auth");
789+
require(isIndexerOrOperator, "!auth");
790790
}
791791

792792
// Close the allocation
@@ -797,7 +797,9 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
797797
// Process non-zero-allocation rewards tracking
798798
if (alloc.tokens > 0) {
799799
// Distribute rewards if proof of indexing was presented by the indexer or operator
800-
if (isIndexer && _poi != 0) {
800+
// and the allocation is at least one epoch old (most indexed chains require the EBO
801+
// posting epoch block numbers to produce a valid POI which happens once per epoch)
802+
if (isIndexerOrOperator && _poi != 0 && epochs > 0) {
801803
_distributeRewards(_allocationID, alloc.indexer);
802804
} else {
803805
_updateRewards(alloc.subgraphDeploymentID);
@@ -821,7 +823,7 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
821823
_allocationID,
822824
msg.sender,
823825
_poi,
824-
!isIndexer
826+
!isIndexerOrOperator
825827
);
826828
}
827829

packages/contracts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/contracts",
3-
"version": "6.2.1",
3+
"version": "6.3.0",
44
"description": "Contracts for the Graph Protocol",
55
"directories": {
66
"test": "test"

packages/contracts/tasks/contract/deploy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { confirm, deploy, DeployType, GraphNetworkAddressBook } from '@graphprotocol/sdk'
1+
import { confirm, deploy, DeployType } from '@graphprotocol/sdk'
22
import { greTask } from '@graphprotocol/sdk/gre'
33

44
greTask('contract:deploy', 'Deploy a contract')
@@ -37,7 +37,7 @@ greTask('contract:deploy', 'Deploy a contract')
3737
name: taskArgs.contract,
3838
args: taskArgs.init?.split(',') || [],
3939
},
40-
new GraphNetworkAddressBook(taskArgs.addressBook, graph.chainId),
40+
graph.addressBook,
4141
)
4242
console.log(`Contract deployed at ${deployment.contract.address}`)
4343
})

packages/contracts/test/unit/staking/allocation.test.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
toGRT,
2020
} from '@graphprotocol/sdk'
2121
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
22+
import { IRewardsManager } from '../../../build/types'
2223

2324
const { AddressZero } = constants
2425

@@ -93,6 +94,7 @@ describe('Staking:Allocation', () => {
9394
let epochManager: EpochManager
9495
let grt: GraphToken
9596
let staking: IStaking
97+
let rewardsManager: IRewardsManager
9698
let libExponential: LibExponential
9799

98100
// Test values
@@ -375,6 +377,7 @@ describe('Staking:Allocation', () => {
375377
epochManager = contracts.EpochManager
376378
grt = contracts.GraphToken as GraphToken
377379
staking = contracts.Staking as IStaking
380+
rewardsManager = contracts.RewardsManager as IRewardsManager
378381

379382
const stakingName = isGraphL1ChainId(graph.chainId) ? 'L1Staking' : 'L2Staking'
380383
const entry = graph.addressBook.getEntry(stakingName)
@@ -875,9 +878,24 @@ describe('Staking:Allocation', () => {
875878
await expect(tx).revertedWith('!active')
876879
})
877880

878-
it('reject close before at least one epoch has passed', async function () {
881+
it('allow close before one epoch has passed', async function () {
882+
const currentEpoch = await epochManager.currentEpoch()
883+
const beforeAlloc = await staking.getAllocation(allocationID)
884+
879885
const tx = staking.connect(indexer).closeAllocation(allocationID, poi)
880-
await expect(tx).revertedWith('<epochs')
886+
await expect(tx)
887+
.emit(staking, 'AllocationClosed')
888+
.withArgs(
889+
indexer.address,
890+
subgraphDeploymentID,
891+
currentEpoch,
892+
beforeAlloc.tokens,
893+
allocationID,
894+
indexer.address,
895+
poi,
896+
false,
897+
)
898+
await expect(tx).not.to.emit(rewardsManager, 'RewardsAssigned')
881899
})
882900

883901
it('reject close if not the owner of allocation', async function () {
@@ -922,7 +940,7 @@ describe('Staking:Allocation', () => {
922940
it('should close an allocation (by public) only if allocation is non-zero', async function () {
923941
// Reject to close if public address and under max allocation epochs
924942
const tx1 = staking.connect(me).closeAllocation(allocationID, poi)
925-
await expect(tx1).revertedWith('<epochs')
943+
await expect(tx1).revertedWith('!auth')
926944

927945
// Move max allocation epochs to close by delegator
928946
const maxAllocationEpochs = await staking.maxAllocationEpochs()

packages/sdk/src/deployments/lib/contracts/log.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function logContractDeployReceipt(
3939
runtimeCodeHash: string,
4040
) {
4141
const msg: string[] = []
42+
msg.push(` = Contract deployed at: ${receipt.contractAddress}`)
4243
msg.push(` = CreationCodeHash: ${creationCodeHash}`)
4344
msg.push(` = RuntimeCodeHash: ${runtimeCodeHash}`)
4445
logToConsoleAndFile(msg)

0 commit comments

Comments
 (0)