-
Notifications
You must be signed in to change notification settings - Fork 160
[Preview] Rewards Eligibility Oracle (REO) #1235
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
Draft
RembrandtK
wants to merge
6
commits into
build-lint-upgrade
Choose a base branch
from
rewards-eligibility-oracle-2
base: build-lint-upgrade
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fed7913
feat: add Rewards Eligibility Oracle (REO)
RembrandtK 13f0ae0
refactor: consolidate test fixtures and fix documentation
RembrandtK f8233f3
refactor: address PR review feedback
RembrandtK e198a3b
feat: add test:coverage script to packages/contracts
RembrandtK 61e32c9
chore: not sure if this file format is stable or keeps changing
RembrandtK 39b161c
refactor(issuance): clean up Hardhat configuration with proper inheri…
RembrandtK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/contracts/contracts/tests/MockRewardsEligibilityOracle.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
// solhint-disable named-parameters-mapping | ||
|
||
pragma solidity 0.7.6; | ||
|
||
import { IRewardsEligibilityOracle } from "@graphprotocol/interfaces/contracts/issuance/eligibility/IRewardsEligibilityOracle.sol"; | ||
Check warning on line 7 in packages/contracts/contracts/tests/MockRewardsEligibilityOracle.sol
|
||
import { ERC165 } from "@openzeppelin/contracts/introspection/ERC165.sol"; | ||
Check warning on line 8 in packages/contracts/contracts/tests/MockRewardsEligibilityOracle.sol
|
||
|
||
/** | ||
* @title MockRewardsEligibilityOracle | ||
* @author Edge & Node | ||
* @notice A simple mock contract for the RewardsEligibilityOracle interface | ||
* @dev A simple mock contract for the RewardsEligibilityOracle interface | ||
*/ | ||
contract MockRewardsEligibilityOracle is IRewardsEligibilityOracle, ERC165 { | ||
/// @dev Mapping to store eligibility status for each indexer | ||
mapping(address => bool) private eligible; | ||
|
||
/// @dev Mapping to track which indexers have been explicitly set | ||
mapping(address => bool) private isSet; | ||
|
||
/// @dev Default response for indexers not explicitly set | ||
bool private defaultResponse; | ||
|
||
/** | ||
* @notice Constructor | ||
* @param newDefaultResponse Default response for isEligible | ||
*/ | ||
constructor(bool newDefaultResponse) { | ||
defaultResponse = newDefaultResponse; | ||
} | ||
|
||
/** | ||
* @notice Set whether a specific indexer is eligible | ||
* @param indexer The indexer address | ||
* @param eligibility Whether the indexer is eligible | ||
*/ | ||
function setIndexerEligible(address indexer, bool eligibility) external { | ||
eligible[indexer] = eligibility; | ||
isSet[indexer] = true; | ||
} | ||
|
||
/** | ||
* @notice Set the default response for indexers not explicitly set | ||
* @param newDefaultResponse The default response | ||
*/ | ||
function setDefaultResponse(bool newDefaultResponse) external { | ||
defaultResponse = newDefaultResponse; | ||
} | ||
|
||
/** | ||
* @inheritdoc IRewardsEligibilityOracle | ||
*/ | ||
function isEligible(address indexer) external view override returns (bool) { | ||
// If the indexer has been explicitly set, return that value | ||
if (isSet[indexer]) { | ||
return eligible[indexer]; | ||
} | ||
|
||
// Otherwise return the default response | ||
return defaultResponse; | ||
} | ||
|
||
/** | ||
* @inheritdoc ERC165 | ||
*/ | ||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { | ||
return interfaceId == type(IRewardsEligibilityOracle).interfaceId || super.supportsInterface(interfaceId); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/interfaces/contracts/issuance/eligibility/IRewardsEligibilityOracle.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.7.6 || ^0.8.0; | ||
|
||
/** | ||
* @title IRewardsEligibilityOracle | ||
* @author Edge & Node | ||
* @notice Interface to check if an indexer is eligible to receive rewards | ||
*/ | ||
interface IRewardsEligibilityOracle { | ||
/** | ||
* @notice Check if an indexer is eligible to receive rewards | ||
* @param indexer Address of the indexer | ||
* @return True if the indexer is eligible to receive rewards, false otherwise | ||
*/ | ||
function isEligible(address indexer) external view returns (bool); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../.markdownlint.json" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
skipFiles: ['test/'], | ||
providerOptions: { | ||
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect', | ||
network_id: 1337, | ||
}, | ||
istanbulFolder: './test/reports/coverage', | ||
configureYulOptimizer: true, | ||
mocha: { | ||
grep: '@skip-on-coverage', | ||
invert: true, | ||
}, | ||
reporter: ['html', 'lcov', 'text'], | ||
reporterOptions: { | ||
html: { | ||
directory: './test/reports/coverage/html', | ||
}, | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["solhint:recommended", "./../../.solhint.json"] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message could be more descriptive by including the address that failed the interface check. Consider changing to something like 'Contract at {address} does not support IRewardsEligibilityOracle interface' to aid in debugging.
Copilot uses AI. Check for mistakes.