Skip to content

Commit 13a4149

Browse files
committed
feat: transferrable subgraphs using an NFT
- make the subgraph to use a single primary key - major refactor of data structures - refactor variable names and add migrate legacy subgraph - get subgraph data depending if legacy or new subgraph - improve validations - refactor all subgraph checks - update tests - NFT burn and mint
1 parent 6962037 commit 13a4149

File tree

9 files changed

+777
-847
lines changed

9 files changed

+777
-847
lines changed

contracts/base/SubgraphNFT.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
pragma solidity ^0.7.4;
4+
5+
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
6+
7+
abstract contract SubgraphNFT is ERC721Upgradeable {
8+
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {}
9+
}

contracts/discovery/GNS.sol

Lines changed: 371 additions & 372 deletions
Large diffs are not rendered by default.

contracts/discovery/GNSStorage.sol

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
pragma solidity ^0.7.6;
44
pragma abicoder v2;
55

6+
import "../base/SubgraphNFT.sol";
67
import "../governance/Managed.sol";
78

89
import "./erc1056/IEthereumDIDRegistry.sol";
910
import "./IGNS.sol";
1011

11-
contract GNSV1Storage is Managed {
12+
abstract contract GNSV1Storage is Managed {
1213
// -- State --
1314

1415
// In parts per hundred
@@ -17,17 +18,33 @@ contract GNSV1Storage is Managed {
1718
// Bonding curve formula
1819
address public bondingCurve;
1920

20-
// graphAccountID => subgraphNumber => subgraphDeploymentID
21-
// subgraphNumber = A number associated to a graph accounts deployed subgraph. This
22-
// is used to point to a subgraphID (graphAccountID + subgraphNumber)
23-
mapping(address => mapping(uint256 => bytes32)) public subgraphs;
21+
// Stores what subgraph deployment a particular legacy subgraph targets
22+
// A subgraph is defined by (graphAccountID, subgraphNumber)
23+
// A subgraph can target one subgraph deployment (bytes32 hash)
24+
// (graphAccountID, subgraphNumber) => subgraphDeploymentID
25+
mapping(address => mapping(uint256 => bytes32)) internal legacySubgraphs;
2426

25-
// graphAccountID => subgraph deployment counter
26-
mapping(address => uint256) public graphAccountSubgraphNumbers;
27+
// Every time an account creates a subgraph it increases a per-account sequence ID
28+
// account => seqID
29+
mapping(address => uint256) public nextAccountSeqID;
2730

28-
// graphAccountID => subgraphNumber => NameCurationPool
29-
mapping(address => mapping(uint256 => IGNS.NameCurationPool)) public nameSignals;
31+
// Stores all the signal deposited on a legacy subgraph
32+
// (graphAccountID, subgraphNumber) => SubgraphData
33+
mapping(address => mapping(uint256 => IGNS.SubgraphData)) public legacySubgraphData;
3034

31-
// ERC-1056 contract reference
32-
IEthereumDIDRegistry public erc1056Registry;
35+
// [DEPRECATED] ERC-1056 contract reference
36+
// This contract is used for managing identities
37+
IEthereumDIDRegistry private __DEPRECATED_erc1056Registry;
38+
}
39+
40+
abstract contract GNSV2Storage is GNSV1Storage, SubgraphNFT {
41+
// TODO: review order of storage
42+
43+
// Use it whenever a legacy (v1) subgraph NFT was claimed to maintain compatibility
44+
// Keep a reference from subgraphID => (graphAccount, subgraphNumber)
45+
mapping(uint256 => IGNS.LegacySubgraphKey) public legacySubgraphKeys;
46+
47+
// Store data for all NFT-based (v2) subgraphs
48+
// subgraphID => SubgraphData
49+
mapping(uint256 => IGNS.SubgraphData) public subgraphs;
3350
}

contracts/discovery/IGNS.sol

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ pragma solidity ^0.7.6;
55
interface IGNS {
66
// -- Pool --
77

8-
struct NameCurationPool {
9-
uint256 vSignal; // The token of the subgraph deployment bonding curve
10-
uint256 nSignal; // The token of the name curation bonding curve
8+
struct SubgraphData {
9+
uint256 vSignal; // The token of the subgraph-deployment bonding curve
10+
uint256 nSignal; // The token of the subgraph bonding curve
1111
mapping(address => uint256) curatorNSignal;
1212
bytes32 subgraphDeploymentID;
1313
uint32 reserveRatio;
1414
bool disabled;
1515
uint256 withdrawableGRT;
1616
}
1717

18+
struct LegacySubgraphKey {
19+
address account;
20+
uint256 accountSeqID;
21+
}
22+
1823
// -- Configuration --
1924

2025
function approveAll() external;
@@ -30,53 +35,41 @@ interface IGNS {
3035
string calldata _name
3136
) external;
3237

33-
function updateSubgraphMetadata(
34-
address _graphAccount,
35-
uint256 _subgraphNumber,
36-
bytes32 _subgraphMetadata
37-
) external;
38+
function updateSubgraphMetadata(uint256 _subgraphID, bytes32 _subgraphMetadata) external;
3839

3940
function publishNewSubgraph(
40-
address _graphAccount,
4141
bytes32 _subgraphDeploymentID,
4242
bytes32 _versionMetadata,
4343
bytes32 _subgraphMetadata
4444
) external;
4545

4646
function publishNewVersion(
47-
address _graphAccount,
48-
uint256 _subgraphNumber,
47+
uint256 _subgraphID,
4948
bytes32 _subgraphDeploymentID,
5049
bytes32 _versionMetadata
5150
) external;
5251

53-
function deprecateSubgraph(address _graphAccount, uint256 _subgraphNumber) external;
52+
function deprecateSubgraph(uint256 _subgraphID) external;
5453

5554
// -- Curation --
5655

57-
function mintNSignal(
58-
address _graphAccount,
59-
uint256 _subgraphNumber,
56+
function mintSignal(
57+
uint256 _subgraphID,
6058
uint256 _tokensIn,
6159
uint256 _nSignalOutMin
6260
) external;
6361

64-
function burnNSignal(
65-
address _graphAccount,
66-
uint256 _subgraphNumber,
62+
function burnSignal(
63+
uint256 _subgraphID,
6764
uint256 _nSignal,
6865
uint256 _tokensOutMin
6966
) external;
7067

71-
function withdraw(address _graphAccount, uint256 _subgraphNumber) external;
68+
function withdraw(uint256 _subgraphID) external;
7269

7370
// -- Getters --
7471

75-
function tokensToNSignal(
76-
address _graphAccount,
77-
uint256 _subgraphNumber,
78-
uint256 _tokensIn
79-
)
72+
function tokensToNSignal(uint256 _subgraphID, uint256 _tokensIn)
8073
external
8174
view
8275
returns (
@@ -85,32 +78,25 @@ interface IGNS {
8578
uint256
8679
);
8780

88-
function nSignalToTokens(
89-
address _graphAccount,
90-
uint256 _subgraphNumber,
91-
uint256 _nSignalIn
92-
) external view returns (uint256, uint256);
93-
94-
function vSignalToNSignal(
95-
address _graphAccount,
96-
uint256 _subgraphNumber,
97-
uint256 _vSignalIn
98-
) external view returns (uint256);
81+
function nSignalToTokens(uint256 _subgraphID, uint256 _nSignalIn)
82+
external
83+
view
84+
returns (uint256, uint256);
9985

100-
function nSignalToVSignal(
101-
address _graphAccount,
102-
uint256 _subgraphNumber,
103-
uint256 _nSignalIn
104-
) external view returns (uint256);
86+
function vSignalToNSignal(uint256 _subgraphID, uint256 _vSignalIn)
87+
external
88+
view
89+
returns (uint256);
10590

106-
function getCuratorNSignal(
107-
address _graphAccount,
108-
uint256 _subgraphNumber,
109-
address _curator
110-
) external view returns (uint256);
91+
function nSignalToVSignal(uint256 _subgraphID, uint256 _nSignalIn)
92+
external
93+
view
94+
returns (uint256);
11195

112-
function isPublished(address _graphAccount, uint256 _subgraphNumber)
96+
function getCuratorSignal(uint256 _subgraphID, address _curator)
11397
external
11498
view
115-
returns (bool);
99+
returns (uint256);
100+
101+
function isPublished(uint256 _subgraphID) external view returns (bool);
116102
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@nomiclabs/hardhat-etherscan": "^2.1.1",
2626
"@nomiclabs/hardhat-waffle": "^2.0.1",
2727
"@openzeppelin/contracts": "^3.4.1",
28+
"@openzeppelin/contracts-upgradeable": "3.4.2",
2829
"@openzeppelin/hardhat-upgrades": "^1.6.0",
2930
"@tenderly/hardhat-tenderly": "^1.0.11",
3031
"@typechain/ethers-v5": "^7.0.0",

0 commit comments

Comments
 (0)