Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove asset holder allowlist (with latest main) #855

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
3 changes: 0 additions & 3 deletions config/graph.arbitrum-goerli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ contracts:
- fn: "setSlasher"
slasher: "${{DisputeManager.address}}"
allowed: true
- fn: "setAssetHolder"
assetHolder: "${{AllocationExchange.address}}"
allowed: true
- fn: "syncAllContracts"
RewardsManager:
proxy: true
Expand Down
3 changes: 0 additions & 3 deletions config/graph.arbitrum-localhost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ contracts:
- fn: "setSlasher"
slasher: "${{DisputeManager.address}}"
allowed: true
- fn: "setAssetHolder"
assetHolder: "${{AllocationExchange.address}}"
allowed: true
- fn: "syncAllContracts"
RewardsManager:
proxy: true
Expand Down
3 changes: 0 additions & 3 deletions config/graph.arbitrum-one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ contracts:
- fn: "setSlasher"
slasher: "${{DisputeManager.address}}"
allowed: true
- fn: "setAssetHolder"
assetHolder: "${{AllocationExchange.address}}"
allowed: true
- fn: "syncAllContracts"
RewardsManager:
proxy: true
Expand Down
3 changes: 0 additions & 3 deletions config/graph.goerli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ contracts:
- fn: "setSlasher"
slasher: "${{DisputeManager.address}}"
allowed: true
- fn: "setAssetHolder"
assetHolder: "${{AllocationExchange.address}}"
allowed: true
- fn: "syncAllContracts"
RewardsManager:
proxy: true
Expand Down
3 changes: 0 additions & 3 deletions config/graph.localhost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ contracts:
- fn: "setSlasher"
slasher: "${{DisputeManager.address}}"
allowed: true
- fn: "setAssetHolder"
assetHolder: "${{AllocationExchange.address}}"
allowed: true
- fn: "syncAllContracts"
RewardsManager:
proxy: true
Expand Down
3 changes: 0 additions & 3 deletions config/graph.mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ contracts:
- fn: "setSlasher"
slasher: "${{DisputeManager.address}}"
allowed: true
- fn: "setAssetHolder"
assetHolder: "${{AllocationExchange.address}}"
allowed: true
- fn: "syncAllContracts"
RewardsManager:
proxy: true
Expand Down
14 changes: 0 additions & 14 deletions contracts/staking/IStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ interface IStakingBase is IStakingData {
uint32 cooldownBlocks
);

/**
* @dev Emitted when `caller` set `assetHolder` address as `allowed` to send funds
* to staking contract.
*/
event AssetHolderUpdate(address indexed caller, address indexed assetHolder, bool allowed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(GitHub won't let me comment on the correct LOC as you did not modify it but...)

The event RebateCollected uses assetHolder name for the query fees provider. We probably want to change that name for clarity, something like rebateProvider or provider, sender, wdyt?


/**
* @dev Emitted when `indexer` set `operator` access.
*/
Expand Down Expand Up @@ -219,14 +213,6 @@ interface IStakingBase is IStakingData {
uint32 _lambdaDenominator
) external;

/**
* @notice Set an address as allowed asset holder.
* @dev This function can only be called by the governor.
* @param _assetHolder Address of allowed source for state channel funds
* @param _allowed True if asset holder is allowed
*/
function setAssetHolder(address _assetHolder, bool _allowed) external;

/**
* @notice Authorize or unauthorize an address to be an operator for the caller.
* @param _operator Address to authorize or unauthorize
Expand Down
9 changes: 0 additions & 9 deletions contracts/staking/IStakingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,6 @@ interface IStakingExtension is IStakingData {
*/
function rewardsDestination(address _indexer) external view returns (address);

/**
* @notice Getter for assetHolders[_maybeAssetHolder]:
* returns true if the address is an asset holder, i.e. an entity that can collect
* query fees into the Staking contract.
* @param _maybeAssetHolder The address that may or may not be an asset holder
* @return True if the address is an asset holder
*/
function assetHolders(address _maybeAssetHolder) external view returns (bool);

/**
* @notice Getter for subgraphAllocations[_subgraphDeploymentId]:
* returns the amount of tokens allocated to a subgraph deployment.
Expand Down
29 changes: 10 additions & 19 deletions contracts/staking/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,6 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
);
}

/**
* @notice Set an address as allowed asset holder.
* @param _assetHolder Address of allowed source for state channel funds
* @param _allowed True if asset holder is allowed
*/
function setAssetHolder(address _assetHolder, bool _allowed) external override onlyGovernor {
require(_assetHolder != address(0), "!assetHolder");
__assetHolders[_assetHolder] = _allowed;
emit AssetHolderUpdate(msg.sender, _assetHolder, _allowed);
}

/**
* @notice Authorize or unauthorize an address to be an operator for the caller.
* @param _operator Address to authorize or unauthorize
Expand Down Expand Up @@ -354,7 +343,6 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M

/**
* @dev Collect and rebate query fees from state channels to the indexer
* Funds received are only accepted from a valid sender.
* To avoid reverting on the withdrawal from channel flow this function will accept calls with zero tokens.
* We use an exponential rebate formula to calculate the amount of tokens to rebate to the indexer.
* This implementation allows collecting multiple times on the same allocation, keeping track of the
Expand All @@ -366,13 +354,17 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
// Allocation identifier validation
require(_allocationID != address(0), "!alloc");

// The contract caller must be an authorized asset holder
require(__assetHolders[msg.sender] == true, "!assetHolder");

// Allocation must exist
AllocationState allocState = _getAllocationState(_allocationID);
require(allocState != AllocationState.Null, "!collect");

// If the query fees are zero, we don't want to revert
// but we also don't need to do anything, so just return
Copy link
Contributor

@tmigone tmigone Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This slightly changes the behavior of the function as we now are not emitting the RebatesCollected event when _tokens == 0. I can't think why this could be a problem, but wanted to make sure we consider it.

if (_tokens == 0) {
return;
}

// Get allocation
Allocation storage alloc = __allocations[_allocationID];
bytes32 subgraphDeploymentID = alloc.subgraphDeploymentID;

Expand All @@ -382,9 +374,8 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
uint256 queryRebates = 0; // Tokens to distribute to indexer
uint256 delegationRewards = 0; // Tokens to distribute to delegators

// Process query fees only if non-zero amount
if (queryFees > 0) {
// -- Pull tokens from the authorized sender --
{
// -- Pull tokens from the sender --
IGraphToken graphToken = graphToken();
TokenUtils.pullTokens(graphToken, msg.sender, queryFees);

Expand Down Expand Up @@ -789,7 +780,7 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M

// Creates an allocation
// Allocation identifiers are not reused
// The assetHolder address can send collected funds to the allocation
// Anyone can send collected funds to the allocation using collect()
Allocation memory alloc = Allocation(
_indexer,
_subgraphDeploymentID,
Expand Down
11 changes: 0 additions & 11 deletions contracts/staking/StakingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,6 @@
return __rewardsDestination[_indexer];
}

/**
* @notice Getter for assetHolders[_maybeAssetHolder]:
* returns true if the address is an asset holder, i.e. an entity that can collect
* query fees into the Staking contract.
* @param _maybeAssetHolder The address that may or may not be an asset holder
* @return True if the address is an asset holder
*/
function assetHolders(address _maybeAssetHolder) external view override returns (bool) {
return __assetHolders[_maybeAssetHolder];
}

/**
* @notice Getter for operatorAuth[_indexer][_maybeOperator]:
* returns true if the operator is authorized to operate on behalf of the indexer.
Expand All @@ -334,13 +323,13 @@
* @param _subgraphDeploymentId The subgraph deployment for which to query the allocations
* @return The amount of tokens allocated to the subgraph deployment
*/
function subgraphAllocations(bytes32 _subgraphDeploymentId)

Check warning on line 326 in contracts/staking/StakingExtension.sol

View check run for this annotation

Codecov / codecov/patch

contracts/staking/StakingExtension.sol#L326

Added line #L326 was not covered by tests
external
view
override
returns (uint256)
{
return __subgraphAllocations[_subgraphDeploymentId];

Check warning on line 332 in contracts/staking/StakingExtension.sol

View check run for this annotation

Codecov / codecov/patch

contracts/staking/StakingExtension.sol#L332

Added line #L332 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/staking/StakingStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ contract StakingV1Storage is Managed {

// -- Asset Holders --

/// @dev Allowed AssetHolders that can collect query fees: assetHolder => is allowed
mapping(address => bool) internal __assetHolders;
/// @dev DEPRECATED: Allowed AssetHolders: assetHolder => is allowed
mapping(address => bool) private __DEPRECATED_assetHolders; // solhint-disable-line var-name-mixedcase
}

/**
Expand Down
5 changes: 0 additions & 5 deletions e2e/deployment/config/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ describe('Staking configuration', () => {
expect(isSlasher).eq(true)
})

it('should allow AllocationExchange to collect query fees', async function () {
const allowed = await Staking.assetHolders(AllocationExchange.address)
expect(allowed).eq(true)
})

it('minimumIndexerStake should match "minimumIndexerStake" in the config file', async function () {
const value = await Staking.minimumIndexerStake()
const expected = getItemValue(graphConfig, `contracts/${contractName}/init/minimumIndexerStake`)
Expand Down
3 changes: 0 additions & 3 deletions test/disputes/poi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ describe('DisputeManager:POI', async () => {
// Give some funds to the fisherman
await grt.connect(governor.signer).mint(fisherman.address, fishermanTokens)
await grt.connect(fisherman.signer).approve(disputeManager.address, fishermanTokens)

// Allow the asset holder
await staking.connect(governor.signer).setAssetHolder(assetHolder.address, true)
})

beforeEach(async function () {
Expand Down
3 changes: 0 additions & 3 deletions test/disputes/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ describe('DisputeManager:Query', async () => {
await grt.connect(dst.signer).approve(disputeManager.address, fishermanTokens)
}

// Allow the asset holder
await staking.connect(governor.signer).setAssetHolder(assetHolder.address, true)

// Create an attestation
const attestation = await buildAttestation(receipt, indexer1ChannelKey.privKey)

Expand Down
1 change: 0 additions & 1 deletion test/payments/allocationExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('AllocationExchange', () => {
await grt.connect(governor.signer).mint(allocationExchange.address, exchangeTokens)

// Ensure the exchange is correctly setup
await staking.connect(governor.signer).setAssetHolder(allocationExchange.address, true)
await allocationExchange.connect(governor.signer).setAuthority(authority.address, true)
await allocationExchange.approveAll()
})
Expand Down
1 change: 0 additions & 1 deletion test/rewards/rewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ describe('Rewards', () => {

// allow the asset holder
const tokensToCollect = toGRT('10000')
await staking.connect(governor.signer).setAssetHolder(assetHolder.address, true)

// signal in two subgraphs in the same block
const subgraphs = [subgraphDeploymentID1, subgraphDeploymentID2]
Expand Down
Loading
Loading