@@ -4,9 +4,9 @@ pragma solidity ^0.7.6;
4
4
pragma abicoder v2;
5
5
6
6
import "@openzeppelin/contracts/math/SafeMath.sol " ;
7
+ import "@openzeppelin/contracts/utils/Address.sol " ;
7
8
8
9
import "../base/Multicall.sol " ;
9
- import "../base/SubgraphNFT.sol " ;
10
10
import "../bancor/BancorFormula.sol " ;
11
11
import "../upgrades/GraphUpgradeable.sol " ;
12
12
import "../utils/TokenUtils.sol " ;
@@ -38,6 +38,8 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
38
38
39
39
// -- Events --
40
40
41
+ event SubgraphNFTUpdated (address subgraphNFT );
42
+
41
43
/**
42
44
* @dev Emitted when graph account sets its default name
43
45
*/
@@ -143,16 +145,16 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
143
145
function initialize (
144
146
address _controller ,
145
147
address _bondingCurve ,
146
- address _tokenDescriptor
148
+ address _subgraphNFT
147
149
) external onlyImpl {
148
150
Managed._initialize (_controller);
149
151
150
152
// Dependencies
151
153
bondingCurve = _bondingCurve;
152
- __SubgraphNFT_init (_tokenDescriptor);
153
154
154
155
// Settings
155
156
_setOwnerTaxPercentage (500000 );
157
+ _setSubgraphNFT (_subgraphNFT);
156
158
}
157
159
158
160
/**
@@ -162,6 +164,8 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
162
164
graphToken ().approve (address (curation ()), MAX_UINT256);
163
165
}
164
166
167
+ // -- Config --
168
+
165
169
/**
166
170
* @dev Set the owner fee percentage. This is used to prevent a subgraph owner to drain all
167
171
* the name curators tokens while upgrading or deprecating and is configurable in parts per million.
@@ -171,14 +175,6 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
171
175
_setOwnerTaxPercentage (_ownerTaxPercentage);
172
176
}
173
177
174
- /**
175
- * @dev Set the token descriptor contract.
176
- * @param _tokenDescriptor Address of the contract that creates the NFT token URI
177
- */
178
- function setTokenDescriptor (address _tokenDescriptor ) external override onlyGovernor {
179
- _setTokenDescriptor (_tokenDescriptor);
180
- }
181
-
182
178
/**
183
179
* @dev Internal: Set the owner tax percentage. This is used to prevent a subgraph owner to drain all
184
180
* the name curators tokens while upgrading or deprecating and is configurable in parts per million.
@@ -190,6 +186,29 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
190
186
emit ParameterUpdated ("ownerTaxPercentage " );
191
187
}
192
188
189
+ /**
190
+ * @dev Set the NFT registry contract
191
+ * @param _subgraphNFT Address of the ERC721 contract
192
+ */
193
+ function setSubgraphNFT (address _subgraphNFT ) public onlyGovernor {
194
+ _setSubgraphNFT (_subgraphNFT);
195
+ }
196
+
197
+ /**
198
+ * @dev Internal: Set the NFT registry contract
199
+ * @param _subgraphNFT Address of the ERC721 contract
200
+ */
201
+ function _setSubgraphNFT (address _subgraphNFT ) private {
202
+ require (
203
+ _subgraphNFT != address (0 ) && Address.isContract (_subgraphNFT),
204
+ "NFT must be valid "
205
+ );
206
+ subgraphNFT = ISubgraphNFT (_subgraphNFT);
207
+ emit SubgraphNFTUpdated (_subgraphNFT);
208
+ }
209
+
210
+ // -- Actions --
211
+
193
212
/**
194
213
* @dev Allows a graph account to set a default name
195
214
* @param _graphAccount Account that is setting its name
@@ -217,6 +236,16 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
217
236
override
218
237
onlySubgraphAuth (_subgraphID)
219
238
{
239
+ _updateSubgraphMetadata (_subgraphID, _subgraphMetadata);
240
+ }
241
+
242
+ /**
243
+ * @dev Internal: Allows a subgraph owner to update the metadata of a subgraph they have published
244
+ * @param _subgraphID Subgraph ID
245
+ * @param _subgraphMetadata IPFS hash for the subgraph metadata
246
+ */
247
+ function _updateSubgraphMetadata (uint256 _subgraphID , bytes32 _subgraphMetadata ) internal {
248
+ _setSubgraphURI (_subgraphID, string (abi.encodePacked (_subgraphMetadata)));
220
249
emit SubgraphMetadataUpdated (_subgraphID, _subgraphMetadata);
221
250
}
222
251
@@ -241,12 +270,14 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
241
270
subgraphData.subgraphDeploymentID = _subgraphDeploymentID;
242
271
subgraphData.reserveRatio = defaultReserveRatio;
243
272
244
- // Mint the NFT. Use the subgraphID as tokenId.
245
- // This function will check the if tokenId already exists.
246
- _mint (subgraphOwner, subgraphID);
247
-
273
+ // Mint the NFT. Use the subgraphID as tokenID.
274
+ // This function will check the if tokenID already exists.
275
+ _mintNFT (subgraphOwner, subgraphID);
248
276
emit SubgraphPublished (subgraphID, _subgraphDeploymentID, defaultReserveRatio);
249
- emit SubgraphMetadataUpdated (subgraphID, _subgraphMetadata);
277
+
278
+ // Set the token metadata
279
+ _updateSubgraphMetadata (subgraphID, _subgraphMetadata);
280
+
250
281
emit SubgraphVersionUpdated (subgraphID, _subgraphDeploymentID, _versionMetadata);
251
282
}
252
283
@@ -356,7 +387,7 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
356
387
// subgraphData.subgraphDeploymentID = 0;
357
388
358
389
// Burn the NFT
359
- _burn (_subgraphID);
390
+ _burnNFT (_subgraphID);
360
391
361
392
emit SubgraphDeprecated (_subgraphID, subgraphData.withdrawableGRT);
362
393
}
@@ -637,21 +668,17 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
637
668
return 0 ;
638
669
}
639
670
640
- /**
641
- * @dev Return the URI describing a particular token ID for a Subgraph.
642
- * @param _subgraphID Subgraph ID
643
- * @return The URI of the ERC721-compliant metadata
644
- */
645
- function tokenURI (uint256 _subgraphID ) public view override returns (string memory ) {
646
- return tokenDescriptor.tokenURI (this , _subgraphID);
647
- }
648
-
649
671
/**
650
672
* @dev Create subgraphID for legacy subgraph and mint ownership NFT.
651
673
* @param _graphAccount Account that created the subgraph
652
674
* @param _subgraphNumber The sequence number of the created subgraph
675
+ * @param _subgraphMetadata IPFS hash for the subgraph metadata
653
676
*/
654
- function migrateLegacySubgraph (address _graphAccount , uint256 _subgraphNumber ) external {
677
+ function migrateLegacySubgraph (
678
+ address _graphAccount ,
679
+ uint256 _subgraphNumber ,
680
+ bytes32 _subgraphMetadata
681
+ ) external {
655
682
// Must be an existing legacy subgraph
656
683
bool legacySubgraphExists = legacySubgraphData[_graphAccount][_subgraphNumber]
657
684
.subgraphDeploymentID != 0 ;
@@ -675,9 +702,11 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
675
702
676
703
// Mint the NFT and send to owner
677
704
// The subgraph owner is the graph account that created it
678
- _mint (_graphAccount, subgraphID);
679
-
705
+ _mintNFT (_graphAccount, subgraphID);
680
706
emit LegacySubgraphClaimed (_graphAccount, _subgraphNumber);
707
+
708
+ // Set the token metadata
709
+ _updateSubgraphMetadata (subgraphID, _subgraphMetadata);
681
710
}
682
711
683
712
/**
@@ -757,4 +786,22 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
757
786
require (_isPublished (subgraphData) == true , "GNS: Must be active " );
758
787
return subgraphData;
759
788
}
789
+
790
+ // -- NFT --
791
+
792
+ function ownerOf (uint256 _tokenID ) public view override returns (address ) {
793
+ return subgraphNFT.ownerOf (_tokenID);
794
+ }
795
+
796
+ function _mintNFT (address _owner , uint256 _tokenID ) internal {
797
+ subgraphNFT.mint (_owner, _tokenID);
798
+ }
799
+
800
+ function _burnNFT (uint256 _tokenID ) internal {
801
+ subgraphNFT.burn (_tokenID);
802
+ }
803
+
804
+ function _setSubgraphURI (uint256 _tokenID , string memory _subgraphURI ) internal {
805
+ subgraphNFT.setSubgraphURI (_tokenID, _subgraphURI);
806
+ }
760
807
}
0 commit comments