Code Monkey home page Code Monkey logo

contracts's Introduction

The Graph

The Graph Protocol

A decentralized network for querying and indexing blockchain data.

Build CI E2E

PackagesDevelopmentDocsContributingSecurityLicense


The Graph is an indexing protocol for querying networks like Ethereum, IPFS, Polygon, and other blockchains. Anyone can build and Publish open APIs, called subgraphs, making data easily accessible.

Packages

This repository is a Yarn workspaces monorepo containing the following packages:

Package Latest version Description
contracts npm version Contracts enabling the open and permissionless decentralized network known as The Graph protocol.
eslint-graph-config npm version Shared linting and formatting rules for TypeScript projects.
token-distribution - Contracts managing token locks for network participants
sdk npm version TypeScript based SDK to interact with the protocol contracts
solhint-graph-config npm version Shared linting and formatting rules for Solidity projects.

Development

Setup

To set up this project you'll need git and yarn installed. Note that Yarn v4 is required to install the dependencies and build the project.

From your command line:

# Enable Yarn v4
corepack enable
yarn set version stable

# Clone this repository
$ git clone https://github.com/graphprotocol/contracts

# Go into the repository
$ cd contracts

# Install dependencies
$ yarn

# Build projects
$ yarn build

Versioning and publishing packages

We use changesets to manage package versioning, this ensures that all packages are versioned together in a consistent manner and helps with generating changelogs.

Step 1: Creating a changeset

A changeset is a file that describes the changes that have been made to the packages in the repository. To create a changeset, run the following command from the root of the repository:

$ yarn changeset

Changeset files are stored in the .changeset directory until they are packaged into a release. You can commit these files and even merge them into your main branch without publishing a release.

Step 2: Creating a package release

When you are ready to create a new package release, run the following command to package all changesets, this will also bump package versions and dependencies:

$ yarn changeset version

Step 3: Tagging the release

Note: this step is meant to be run on the main branch.

After creating a package release, you will need to tag the release commit with the version number. To do this, run the following command from the root of the repository:

$ yarn changeset tag
$ git push --follow-tags

Step 4: Publishing a package release

Note: this step is meant to be run on the main branch.

Packages are published and distributed via NPM. To publish a package, run the following command from the root of the repository:

# Publish the package
$ yarn npm publish --access public --tag <tag>

Alternatively, there is a GitHub action that can be manually triggered to publish a package.

Documentation

Coming soon

For now, each package has its own README with more specific documentation you can check out.

Contributing

Contributions are welcomed and encouraged! You can do so by:

  • Creating an issue
  • Opening a PR

If you are opening a PR, it is a good idea to first go to The Graph Discord or The Graph Forum and discuss your idea! Discussions on the forum or Discord are another great way to contribute.

Security

If you find a bug or security issue please go through the official channel, The Graph Security Bounties on Immunefi. Responsible disclosure procedures must be followed to receive bounties.

License

Copyright © 2021 The Graph Foundation

Licensed under GPL license.

contracts's People

Contributors

abarmat avatar arjunbhuptani avatar davekaj avatar dependabot[bot] avatar fordn avatar fubuloubu avatar geoknee avatar glmaljkovich avatar jannis avatar kyriediculous avatar maikol avatar mercuricchloride avatar nenadjaja avatar pcarranzav avatar retzion avatar shkfnly avatar snario avatar spalladino avatar thabokani avatar theodus avatar tmigone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

contracts's Issues

dApp / Contract Dashboard

Web3 UI connected to deployed contracts.

  • Show ownership data and upgradable contract params
  • Allow updating ownership of contracts
  • Allow updating governed parameters of contracts
  • ...

Add Truffle Test CI

  • Explore Truffle CI integration for this repo
  • Explore integration of Slither into CI

Rewards management (w/o payment channels)

More detailed design to land in the spec soon. In the meantime, this is what I propose for the current sprint:

Staking contract

  • Created by staking contract factory
  • Query fees paid to Staking Contract, denominated in GRT (must be able to receive Graph Tokens)
  • Is responsible for splitting rewards between Curator and Indexer
  • Enforces thawing period for Indexer (thawing period set by governance)
  • Curator rewards may be withdrawn immediately

Curator rewards

  • No longer paid via inflation
  • Curator rewards are paid as a cut of the fees collected by Indexer
  • Each "share" is entitled to a 1 basis point cut of fees
  • Curator shares issued according to a bonding curve (TBD)

Participation rewards

  • Paid via inflation
  • Issued in proportion to the amount of tokens staked for curation for the subgraph being indexed.
  • Proportionality constant set via governance.

User Stories Progress/Coverage

User Story Coverage

  • DApp developer can deploy a subgraph for the first time
    • Governance registers gnsDomains and assigns owner
    • Domain owner can add subdomain(s)
  • DApp developer can “update” a deployed subgraph
    • Domain owner can update subDomain(s)
    • Domain owner can delete subDomain(s)
    • Domain owner transfer domain
  • Curator can bet on the future usefulness of a dataset to the network
    • Curator can find subgraphIds by subdomain via GNS logs
    • Curator can stake GraphTokens to curate subgraphId
      • Revise bonding curve for curation staking
    • Curator can update Staking for Curation
    • Curator can withdraw Staking for Curation
      • A Curator can log out and withdraw their stake
  • Query Node can discover Indexing Nodes capable of returning data for a particular query.
    • Query Node can find Indexing Nodes for a subgraphId mapped to a subdomain name
      • Query Node can find subgraphIds by subdomain via GNS logs
      • Staking public mapping indexingNodes maps subgraphId to list of addresses to Indexing Nodes
  • Indexing Nodes can stake Graph Tokens to index a particular dataset
    • Indexing Node can find subgraphIds by subdomain via GNS logs
    • Indexing Node can stake Graph Tokens for Indexing a subgraphId
    • Indexing Node can update Staking for Indexing
    • Indexing Node can withdraw Staking for Indexing after cool-down period
  • Indexing Nodes receive a participation reward for providing work to the network.
    • Indexing Node can use claimRewards function to receive any rewards due to them
      (WIP...)
  • A fisherman can dispute an invalid query response, and if successful, the offending Indexing Node will be slashed
    • Create a dispute for the arbitrator to resolve
    • The arbitrator can verify a dispute as being valid.
    • Use the correct attestation data structure from spec (EIP712)
    • Slash Stake: In successful dispute, slashingPercent of slashing amount goes to Fisherman, the rest goes to Graph DAO (where they are possibly burned).

TBD

  • Token holder can delegate tokens to an Indexing Node to receive a participation reward.
  • A dapp end user can pay ETH micropayments to an Indexing Node in return for retrieving data
  • Graph leadership team can upgrade key contracts and set key network parameters

Contract Requirements

The user stories above help define the requirements for the contracts being built. The following is a snapshot of the requirements we have defined in the contract source code comments.

GraphToken Requirements

  • req 01 The Graph Token shall implement the ERC20 Token Standard
  • req 02 The Graph Token shall allow tokens staked in the protocol to be burned
  • req 03 The Graph Token shall allow tokens to be minted to reward protocol participants
  • req 04 The Graph Token shall only allow designated accounts the authority to mint
    • Note: for example, the Payment Channel Hub and Rewards Manager contracts
  • req 05 The Graph Token shall allow the protocol Governance to modify the accounts that have minting authority
  • req 06 The Graph Token shall allow the protocol Governance to mint new tokens
  • req 07 The Graph Token shall mint an initial distribution of tokens

GNS Requirements

  • req 01 Maps owners to domains
  • req 02 Maps domain names to subgraphIds
  • req 03 Maps subdomain names to domains of subgraphIds
  • req 04 Event to emit human-readable names

Staking Requirements

Curator Requirements

  • req c01 Any User can stake Graph Tokens to be included as a Curator for a given subgraphId.
  • req c02 The amount of tokens to stake required to become a Curator must be greater than or
    equal to the minimum curation staking amount.
  • req c03 Only Governance can change the minimum curation staking amount.
  • req c04 A Curator is issued shares according to a pre-defined bonding curve depending on
    equal to the total amount of Curation stake for a given subgraphId if they
    successfully stake on a given subgraphId.
  • req c05 A Curator can add any amount of stake for a given subgraphId at any time, as long as
    their total amount remains more than minimumCurationStakingAmount.
  • req c06 A Curator can remove any amount of their stake for a given subgraphId at any time, as
    long as their total amount remains more than minimumCurationStakingAmount.
  • req c07 A Curator can remove all of their stake for a given subgraphId at any time.

Indexer Requirements

  • req i01 Any User can stake Graph Tokens to be included as an Indexer for a given subgraphId.
  • req i02 The amount of tokens to stake required to become an Indexer must be greater than or
    equal to the minimum indexing staking amount.
  • req i03 Only Governance can change the minimum indexing staking amount.
  • req i04 An Indexer can start the process of removing their stake for a given subgraphId at
    any time.
  • req i05 An Indexer may withdraw their stake for a given subgraphId after the process has
    been started and a cooling period has elapsed.
  • req i06 An Indexer can update Stake for a given subgraphId. The minimum indexing staking
    amount will be adjusted for the amountStaked previously by the Indexer on the given
    subgraphId in order to allow staker to stake less than the minimumIndexingStakingAmount
    if the new total amountStaked is greater than the minimumIndexingStakingAmount.

Slashing Requirements

  • req s01 The Dispute Manager contract can burn the staked Tokens of any Indexer.
  • req s02 Only Governance can change the Dispute Manager contract address.
  • reg s03 Only Governance can update slashingPercent.

Fisherman Requirements

  • req f01 A fisherman can provide a bond, a valid read request and an invalid read response which has been signed by a current indexing node to create a dispute.
  • req f02 If the dispute is validated by arbitration, the fisherman should receive a reward proportional to the amount staked by the indexing node.

Dispute Arbitrator Requirements

  • req a01 The arbitrator can rule to accept a proposed dispute, which will trigger a slashing of the indexing node that the dispute concerns.
  • req a02 The arbitrator can rule to reject a proposed dispute, which will slash the bond posted by the fisherman who proposed it.

RewardsManager Requirements

  • req 01 Has the ability to mint tokens according to the reward rules specified in mechanism design of technical specification.
  • req 02 Governance contract can update parameters { curatorRewardRate, targetParticipationRate, yearlyInflationRate }
  • req 03 claimRewards function
  • req 04 uint256 for yearly inflation rate
  • req 05 a mapping that records the usage in queries of each index chain , which would look like mapping( indexChainID bytes32 -> queryAmount uint256)

ServiceRegistry Requirements

  • req 01 Maps Ethereum Addresses to URLs
  • req 02 No other contracts depend on this, rather is consumed by users of The Graph.

Truffle deployment Scripts

Structure the deployment of contracts in a way that governance, staking, etc are all done in the right order passing the right params along to subsequent deployed contracts.

Compilation Warnings

compilation warnings encountered:

/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:78:29: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setArbitrator (address _newArbitrator) public onlyGovernance returns (bool success)
^--------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:78:84: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setArbitrator (address _newArbitrator) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:90:29: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function createDispute (bytes memory _readRequest, bytes memory _readResponse) public returns (bytes32 disputeId)
^-----------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:90:56: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function createDispute (bytes memory _readRequest, bytes memory _readResponse) public returns (bytes32 disputeId)
^------------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:90:100: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function createDispute (bytes memory _readRequest, bytes memory _readResponse) public returns (bytes32 disputeId)
^---------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:99:40: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateSlashingPercentage (uint256 _slashingPercent) public onlyGovernance returns (bool success)
^----------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:99:97: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateSlashingPercentage (uint256 _slashingPercent) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:108:29: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function verifyDispute (bytes32 _disputeId) public onlyArbitrator returns (bool success)
^----------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:108:80: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function verifyDispute (bytes32 _disputeId) public onlyArbitrator returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:66:39: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateCuratorRewardRate (uint256 _newCuratorRewardRate) public onlyGovernance returns (bool success)
^---------------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:66:101: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateCuratorRewardRate (uint256 _newCuratorRewardRate) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:75:45: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateTargetParticipationRate (uint256 _newTargetParticipationRate) public onlyGovernance returns (bool success)
^---------------------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:75:113: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateTargetParticipationRate (uint256 _newTargetParticipationRate) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:84:41: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateYearlyInflationRate (uint256 _newYearlyInflationRate) public onlyGovernance returns (bool success)
^-----------------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:84:105: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function updateYearlyInflationRate (uint256 _newYearlyInflationRate) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:96:32: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function mintRewardTokens (address _account, uint256 _value) public onlyGovernance returns (bool success)
^--------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:96:50: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function mintRewardTokens (address _account, uint256 _value) public onlyGovernance returns (bool success)
^------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:96:97: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function mintRewardTokens (address _account, uint256 _value) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:106:28: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function claimRewards (bytes32 _validatorId, bool _addToStake) public returns (uint256 rewaredAmount)
^------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:106:50: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function claimRewards (bytes32 _validatorId, bool _addToStake) public returns (uint256 rewaredAmount)
^--------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:106:84: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function claimRewards (bytes32 _validatorId, bool _addToStake) public returns (uint256 rewaredAmount)
^-------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:96:47: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setMinimumCurationStakingAmount (uint256 _minimumCurationStakingAmount) public onlyGovernance returns (bool success)
^-----------------------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:96:117: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setMinimumCurationStakingAmount (uint256 _minimumCurationStakingAmount) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:105:47: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setMinimumIndexingStakingAmount (uint256 _minimumIndexingStakingAmount) public onlyGovernance returns (bool success)
^-----------------------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:105:117: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setMinimumIndexingStakingAmount (uint256 _minimumIndexingStakingAmount) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:114:34: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setMaximumIndexers (uint256 _maximumIndexers) public onlyGovernance returns (bool success)
^----------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:114:91: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function setMaximumIndexers (uint256 _maximumIndexers) public onlyGovernance returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:129:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
bytes32 _subgraphId,
^-----------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:130:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
address _staker,
^-------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:131:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
uint256 _value,
^------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:132:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
bytes memory _indexingRecords
^---------------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:133:23: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
) public returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:146:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
bytes32 _subgraphId,
^-----------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:147:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
address _staker,
^-------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:148:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
uint256 _value
^------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:149:23: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
) public returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:163:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
address _from,
^-----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:164:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
uint256 _value,
^------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:165:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
address _token,
^------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:166:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
bytes memory _data
^----------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:176:26: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function slashStake (bytes memory _disputeId) public onlyArbitrator returns (bool success)
^---------------------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:176:82: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function slashStake (bytes memory _disputeId) public onlyArbitrator returns (bool success)
^----------^
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:78:5: Warning: Function state mutability can be restricted to view
function setArbitrator (address _newArbitrator) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:90:5: Warning: Function state mutability can be restricted to pure
function createDispute (bytes memory _readRequest, bytes memory _readResponse) public returns (bytes32 disputeId)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:99:5: Warning: Function state mutability can be restricted to view
function updateSlashingPercentage (uint256 _slashingPercent) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/DisputeManager.sol:108:5: Warning: Function state mutability can be restricted to view
function verifyDispute (bytes32 _disputeId) public onlyArbitrator returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/GNS.sol:102:5: Warning: Function state mutability can be restricted to view
function getDomainOwner (bytes32 _domainHash) external returns (address owner) {
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:66:5: Warning: Function state mutability can be restricted to view
function updateCuratorRewardRate (uint256 _newCuratorRewardRate) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:75:5: Warning: Function state mutability can be restricted to view
function updateTargetParticipationRate (uint256 _newTargetParticipationRate) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:84:5: Warning: Function state mutability can be restricted to view
function updateYearlyInflationRate (uint256 _newYearlyInflationRate) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:96:5: Warning: Function state mutability can be restricted to view
function mintRewardTokens (address _account, uint256 _value) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/RewardsManager.sol:106:5: Warning: Function state mutability can be restricted to pure
function claimRewards (bytes32 _validatorId, bool _addToStake) public returns (uint256 rewaredAmount)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:96:5: Warning: Function state mutability can be restricted to view
function setMinimumCurationStakingAmount (uint256 _minimumCurationStakingAmount) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:105:5: Warning: Function state mutability can be restricted to view
function setMinimumIndexingStakingAmount (uint256 _minimumIndexingStakingAmount) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:114:5: Warning: Function state mutability can be restricted to view
function setMaximumIndexers (uint256 _maximumIndexers) public onlyGovernance returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:128:5: Warning: Function state mutability can be restricted to pure
function stakeGraphTokensForIndexing (
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:145:5: Warning: Function state mutability can be restricted to pure
function stakeGraphTokensForCuration (
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:162:5: Warning: Function state mutability can be restricted to pure
function receiveApproval (
^ (Relevant source part starts here and spans across multiple lines).
,/Users/reuven/Projects/TheGraph/contracts/contracts/Staking.sol:176:5: Warning: Function state mutability can be restricted to view
function slashStake (bytes memory _disputeId) public onlyArbitrator returns (bool success)
^ (Relevant source part starts here and spans across multiple lines).

Graph Name Service contract

Top level domains are owned by Ethereum account, which may assign names within that top level domain to Subgraph IDs. Registry does not need to support infinitely nestable names. Registrary may be cenralized, using the Graph DAO contract, for now.

ERC 777 Compatibility

Our staking contract currently implements a tokensReceived hook, as defined in EIP 777.

We don't yet fully implement the spec, however, either for our staking contract nor for our token contract.

We should evaluate whether it makes sense to adopt the EIP 777 spec fully:

  • For our staking contract
  • For our token contract

Test Indexing Staking

  • Check that any user can stake.
  • Log in
  • Log out - initialize
  • Log out - cool down
  • Log out - finalize
  • All indexers log in then out -> tokens >= amountStaked
  • Logged in Indexer can be slashed anytime (even cool down)

Dispute management

From #55:
A fisherman can dispute an invalid query response, and if successful, the offending Indexing Node will be slashed

  • Create a dispute for the arbitrator to resolve
  • The arbitrator can verify a dispute as being valid.
  • Use the correct attestation data structure from spec (EIP712)
  • Slash Stake: In successful dispute, slashingPercent of slashing amount goes to Fisherman, the rest goes to Graph DAO (where they are possibly burned).

Test Curator Staking

  • Check that any user can stake.
  • Log in - issued shares according to bonding curve
  • Log out - remove shares according to bonding curve
  • All users log in then out -> shares >= 0

Review GNS requirements for Domains vs. Subdomains

Requirements state that gnsDomains mapping should map Domain Names (_domainHash) to subgraphIds

It appears that only a "Subdomain" may map to a subgraphId.

I see the Domain struct contains only an owner and subgraphId does not factor into Domain anywhere. Any "subdomain" that gets added, altered, or removed emits an event log to provide an indexing opportunity for mapping subdomainHashs to subdomainSubgraphIds.

Let's confirm that this is the intended behavior and adjust our requirements accordingly.

Curation Staking should return remainder of purchase amount

During testing, we noticed that stakeGraphTokensForCuration() does not return the remaining purchase amount for a given amount of shares. Since there are not fractional shares currently (which we would not recommend implementing), any amount of shares purchased using stakeToShares() is (correctly) rounded down to the nearest whole number increment of shares.

However, the purchase amount of reserve tokens above and beyond that amount is never refunded to the staker, causing the reserve token share pool to grow larger without issuing a corresponding amount of shares. This will increase the purchase price in future staking amounts, which may be undesirable behavior.

We do not believe this leads to a loss of funds, but the remainder should be returned to the staker so as to keep the desired behavior intact. This can be done by calculating sharesToStake() with the total number of shares after this function executes in order to calculate the number of tokens above and beyond the amount required to purchase that number of shares, and issue the refund back to the staker.

Security analysis: minor, may lead to inconsistent behavior in staking price, but no loss of funds projected

Removed `indexed` from string `domainName`

event domainAdded(string indexed domainName, bytes32 indexed domainHash, address indexed owner);

When we index a string, the EVM hashes the domain name hash, so that the string can fit into a bytes32, which is required for an indexed topic.

If we just make it non-indexed, it will be emitted as a string across multiple bytes32 in the logs

Move PRD into Requirements.md file

Transfer the requirements and discussion in the PRD into a Requirements.md file within this repository.

Ensure the requirements file is up to date with the current @req tags in the contracts. Note differences.

Staking - Review the previous tests

Review the previously written tests. They will have changed a bit since I changed the staking contract, and I need to check if any test cases have been missed.

EIP 712 Updates

  • Verify correct implementation of EIP 712 message type w/ State Channel
    • Protocol Name and Version are correct
    • Verifying contract address (Do we need this?)
    • Salt is safe to use (subgraphId)
  • subgraphId used in Domain Seperator, no longer a necessary field in the attestation msg?

Governance plugin

A JavaScript pluggin that encodes transaction data for use with the multisig, the dapp, etc.

Gnosis MultiSigWallet contract

It requires some upgrading. I will first commit the contract exactly as it comes form Gnosis. I will then commit the upgraded changes for review in a PR.

Remove installed_contracts directory

We checked in a dependency directly into the codebase installed via ethPM functionality in Truffle.

Explore if it is possible to have this be installed locally (not checked in), and whether that is safe to do (e.g. npm package injection).

From this conversation: #57 (comment)

Documentation for Upgrade Path and Parameter Configuration

  • Analyze and document contract upgradeability process for normal and emergency scenarios
  • Analyze and document all governance parameters for how to use them to protect against undesired behaviors or incentivize certain actions to occur

Suggested pre-audit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.