Skip to content

Commit 8229e8b

Browse files
committed
feat: restore backward compatibility with single bulk functions to allow an staged upgrade
1 parent ed7ad2b commit 8229e8b

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

contracts/staking/IStaking.sol

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ interface IStaking is IStakingData {
9494

9595
// -- Channel management and allocations --
9696

97+
function allocate(
98+
bytes32 _subgraphDeploymentID,
99+
uint256 _tokens,
100+
address _allocationID,
101+
bytes32 _metadata,
102+
bytes calldata _proof
103+
) external;
104+
97105
function allocateFrom(
98106
address _indexer,
99107
bytes32 _subgraphDeploymentID,
@@ -105,10 +113,25 @@ interface IStaking is IStakingData {
105113

106114
function closeAllocation(address _allocationID, bytes32 _poi) external;
107115

116+
function closeAllocationMany(CloseAllocationRequest[] calldata _requests) external;
117+
118+
function closeAndAllocate(
119+
address _oldAllocationID,
120+
bytes32 _poi,
121+
address _indexer,
122+
bytes32 _subgraphDeploymentID,
123+
uint256 _tokens,
124+
address _allocationID,
125+
bytes32 _metadata,
126+
bytes calldata _proof
127+
) external;
128+
108129
function collect(uint256 _tokens, address _allocationID) external;
109130

110131
function claim(address _allocationID, bool _restake) external;
111132

133+
function claimMany(address[] calldata _allocationID, bool _restake) external;
134+
112135
// -- Getters and calculations --
113136

114137
function hasStake(address _indexer) external view returns (bool);

contracts/staking/Staking.sol

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,24 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking, Multicall {
859859
return _withdrawDelegated(msg.sender, _indexer, _delegateToIndexer);
860860
}
861861

862+
/**
863+
* @dev Allocate available tokens to a subgraph deployment.
864+
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
865+
* @param _tokens Amount of tokens to allocate
866+
* @param _allocationID The allocation identifier
867+
* @param _metadata IPFS hash for additional information about the allocation
868+
* @param _proof A 65-bytes Ethereum signed message of `keccak256(indexerAddress,allocationID)`
869+
*/
870+
function allocate(
871+
bytes32 _subgraphDeploymentID,
872+
uint256 _tokens,
873+
address _allocationID,
874+
bytes32 _metadata,
875+
bytes calldata _proof
876+
) external override notPaused {
877+
_allocate(msg.sender, _subgraphDeploymentID, _tokens, _allocationID, _metadata, _proof);
878+
}
879+
862880
/**
863881
* @dev Allocate available tokens to a subgraph deployment.
864882
* @param _indexer Indexer address to allocate funds from.
@@ -891,6 +909,49 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking, Multicall {
891909
_closeAllocation(_allocationID, _poi);
892910
}
893911

912+
/**
913+
* @dev Close multiple allocations and free the staked tokens.
914+
* To be eligible for rewards a proof of indexing must be presented.
915+
* Presenting a bad proof is subject to slashable condition.
916+
* To opt out for rewards set _poi to 0x0
917+
* @param _requests An array of CloseAllocationRequest
918+
*/
919+
function closeAllocationMany(CloseAllocationRequest[] calldata _requests)
920+
external
921+
override
922+
notPaused
923+
{
924+
for (uint256 i = 0; i < _requests.length; i++) {
925+
_closeAllocation(_requests[i].allocationID, _requests[i].poi);
926+
}
927+
}
928+
929+
/**
930+
* @dev Close and allocate. This will perform a close and then create a new Allocation
931+
* atomically on the same transaction.
932+
* @param _closingAllocationID The identifier of the allocation to be closed
933+
* @param _poi Proof of indexing submitted for the allocated period
934+
* @param _indexer Indexer address to allocate funds from.
935+
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
936+
* @param _tokens Amount of tokens to allocate
937+
* @param _allocationID The allocation identifier
938+
* @param _metadata IPFS hash for additional information about the allocation
939+
* @param _proof A 65-bytes Ethereum signed message of `keccak256(indexerAddress,allocationID)`
940+
*/
941+
function closeAndAllocate(
942+
address _closingAllocationID,
943+
bytes32 _poi,
944+
address _indexer,
945+
bytes32 _subgraphDeploymentID,
946+
uint256 _tokens,
947+
address _allocationID,
948+
bytes32 _metadata,
949+
bytes calldata _proof
950+
) external override notPaused {
951+
_closeAllocation(_closingAllocationID, _poi);
952+
_allocate(_indexer, _subgraphDeploymentID, _tokens, _allocationID, _metadata, _proof);
953+
}
954+
894955
/**
895956
* @dev Collect query fees from state channels and assign them to an allocation.
896957
* Funds received are only accepted from a valid sender.
@@ -976,6 +1037,21 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking, Multicall {
9761037
_claim(_allocationID, _restake);
9771038
}
9781039

1040+
/**
1041+
* @dev Claim tokens from the rebate pool for many allocations.
1042+
* @param _allocationID Array of allocations from where we are claiming tokens
1043+
* @param _restake True if restake fees instead of transfer to indexer
1044+
*/
1045+
function claimMany(address[] calldata _allocationID, bool _restake)
1046+
external
1047+
override
1048+
notPaused
1049+
{
1050+
for (uint256 i = 0; i < _allocationID.length; i++) {
1051+
_claim(_allocationID[i], _restake);
1052+
}
1053+
}
1054+
9791055
/**
9801056
* @dev Stake tokens on the indexer.
9811057
* This function does not check minimum indexer stake requirement to allow

0 commit comments

Comments
 (0)