@@ -101,8 +101,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
101
101
uint256 epoch ,
102
102
uint256 tokens ,
103
103
address allocationID ,
104
- bytes32 metadata ,
105
- address assetHolder
104
+ bytes32 metadata
106
105
);
107
106
108
107
/**
@@ -156,9 +155,15 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
156
155
);
157
156
158
157
/**
159
- * @dev Emitted when `caller` set `slasher` address as `enabled ` to slash stakes.
158
+ * @dev Emitted when `caller` set `slasher` address as `allowed ` to slash stakes.
160
159
*/
161
- event SlasherUpdate (address indexed caller , address indexed slasher , bool enabled );
160
+ event SlasherUpdate (address indexed caller , address indexed slasher , bool allowed );
161
+
162
+ /**
163
+ * @dev Emitted when `caller` set `assetHolder` address as `allowed` to send funds
164
+ * to staking contract.
165
+ */
166
+ event AssetHolderUpdate (address indexed caller , address indexed assetHolder , bool allowed );
162
167
163
168
/**
164
169
* @dev Emitted when `indexer` set `operator` access.
@@ -363,10 +368,22 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
363
368
* @param _allowed True if slasher is allowed
364
369
*/
365
370
function setSlasher (address _slasher , bool _allowed ) external override onlyGovernor {
371
+ require (_slasher != address (0 ), "!slasher " );
366
372
slashers[_slasher] = _allowed;
367
373
emit SlasherUpdate (msg .sender , _slasher, _allowed);
368
374
}
369
375
376
+ /**
377
+ * @dev Set an address as allowed asset holder.
378
+ * @param _assetHolder Address of allowed source for state channel funds
379
+ * @param _allowed True if asset holder is allowed
380
+ */
381
+ function setAssetHolder (address _assetHolder , bool _allowed ) external override onlyGovernor {
382
+ require (_assetHolder != address (0 ), "!assetHolder " );
383
+ assetHolders[_assetHolder] = _allowed;
384
+ emit AssetHolderUpdate (msg .sender , _assetHolder, _allowed);
385
+ }
386
+
370
387
/**
371
388
* @dev Get the GRT token used by the contract.
372
389
* @return GRT token contract address
@@ -680,24 +697,15 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
680
697
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
681
698
* @param _tokens Amount of tokens to allocate
682
699
* @param _allocationID The allocation identifier
683
- * @param _assetHolder Authorized sender address of collected funds
684
700
* @param _metadata IPFS hash for additional information about the allocation
685
701
*/
686
702
function allocate (
687
703
bytes32 _subgraphDeploymentID ,
688
704
uint256 _tokens ,
689
705
address _allocationID ,
690
- address _assetHolder ,
691
706
bytes32 _metadata
692
707
) external override notPaused {
693
- _allocate (
694
- msg .sender ,
695
- _subgraphDeploymentID,
696
- _tokens,
697
- _allocationID,
698
- _assetHolder,
699
- _metadata
700
- );
708
+ _allocate (msg .sender , _subgraphDeploymentID, _tokens, _allocationID, _metadata);
701
709
}
702
710
703
711
/**
@@ -706,18 +714,16 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
706
714
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
707
715
* @param _tokens Amount of tokens to allocate
708
716
* @param _allocationID The allocation identifier
709
- * @param _assetHolder Authorized sender address of collected funds
710
717
* @param _metadata IPFS hash for additional information about the allocation
711
718
*/
712
719
function allocateFrom (
713
720
address _indexer ,
714
721
bytes32 _subgraphDeploymentID ,
715
722
uint256 _tokens ,
716
723
address _allocationID ,
717
- address _assetHolder ,
718
724
bytes32 _metadata
719
725
) external override notPaused {
720
- _allocate (_indexer, _subgraphDeploymentID, _tokens, _allocationID, _assetHolder, _metadata);
726
+ _allocate (_indexer, _subgraphDeploymentID, _tokens, _allocationID, _metadata);
721
727
}
722
728
723
729
/**
@@ -741,7 +747,6 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
741
747
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
742
748
* @param _tokens Amount of tokens to allocate
743
749
* @param _allocationID The allocation identifier
744
- * @param _assetHolder Authorized sender address of collected funds
745
750
* @param _metadata IPFS hash for additional information about the allocation
746
751
*/
747
752
function closeAndAllocate (
@@ -751,11 +756,10 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
751
756
bytes32 _subgraphDeploymentID ,
752
757
uint256 _tokens ,
753
758
address _allocationID ,
754
- address _assetHolder ,
755
759
bytes32 _metadata
756
760
) external override notPaused {
757
761
_closeAllocation (_closingAllocationID, _poi);
758
- _allocate (_indexer, _subgraphDeploymentID, _tokens, _allocationID, _assetHolder, _metadata);
762
+ _allocate (_indexer, _subgraphDeploymentID, _tokens, _allocationID, _metadata);
759
763
}
760
764
761
765
/**
@@ -767,13 +771,8 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
767
771
// Allocation identifier validation
768
772
require (_allocationID != address (0 ), "Invalid allocation " );
769
773
770
- // NOTE: commented out for easier test of state-channel integrations
771
- // NOTE: this validation might be removed in the future if no harm to the
772
- // NOTE: economic incentive structure is done by an external caller use
773
- // NOTE: of this function
774
- // The contract caller must be an asset holder registered during allocate()
775
- // Allocation memory alloc = allocations[_allocationID];
776
- // require(alloc.assetHolder == msg.sender, "caller is not authorized");
774
+ // The contract caller must be an authorized asset holder
775
+ require (assetHolders[msg .sender ] == true , "!assetHolder " );
777
776
778
777
// Transfer tokens to collect from the authorized sender
779
778
require (graphToken ().transferFrom (msg .sender , address (this ), _tokens), "!transfer " );
@@ -816,7 +815,6 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
816
815
alloc.closedAtEpoch = 0 ;
817
816
alloc.collectedFees = 0 ;
818
817
alloc.effectiveAllocation = 0 ;
819
- alloc.assetHolder = address (0 ); // This avoid collect() to be called
820
818
821
819
// -- Effects --
822
820
@@ -877,15 +875,13 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
877
875
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
878
876
* @param _tokens Amount of tokens to allocate
879
877
* @param _allocationID The allocationID will work to identify collected funds related to this allocation
880
- * @param _assetHolder Authorized sender address of collected funds
881
878
* @param _metadata Metadata related to the allocation
882
879
*/
883
880
function _allocate (
884
881
address _indexer ,
885
882
bytes32 _subgraphDeploymentID ,
886
883
uint256 _tokens ,
887
884
address _allocationID ,
888
- address _assetHolder ,
889
885
bytes32 _metadata
890
886
) internal {
891
887
require (_onlyAuth (_indexer), "!auth " );
@@ -918,7 +914,6 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
918
914
0 , // closedAtEpoch
919
915
0 , // Initialize collected fees
920
916
0 , // Initialize effective allocation
921
- _assetHolder, // Source address for allocation collected funds
922
917
_updateRewards (_subgraphDeploymentID) // Initialize accumulated rewards per stake allocated
923
918
);
924
919
allocations[_allocationID] = alloc;
@@ -938,8 +933,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
938
933
alloc.createdAtEpoch,
939
934
alloc.tokens,
940
935
_allocationID,
941
- _metadata,
942
- _assetHolder
936
+ _metadata
943
937
);
944
938
}
945
939
0 commit comments