Skip to content

Commit 557a408

Browse files
committed
Combine subgraph and curating functions into 1 on GNS
Previously creating a named subgraph, and then curating on it were two distinct Steps. Now it is one step. The subgraph creating and updating and deprecating functions now just wrap the curate functions. Which are private functions. This is actually a lot simpler and cleaner. Tests were reduced quiet a bit, as we were able to remove a lot of duplicate require statements.
1 parent b105341 commit 557a408

File tree

3 files changed

+368
-368
lines changed

3 files changed

+368
-368
lines changed

addresses.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,5 +411,14 @@
411411
"ensPublicResolver": "0xc30F6CCc48F1eA5374aC618dfe5243ddD1e264E7",
412412
"ethereumDIDRegistry": "0xdCa7EF03e98e0DC2B855bE647C39ABe984fcF21B"
413413
},
414-
"mainnet": {}
414+
"rinkeby": {
415+
"ens": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
416+
"ensTestRegistrar": "0x327033bA7B23A6E3a3Ca165e44D619E3dd675f8b",
417+
"ensPublicResolver": "0xc30F6CCc48F1eA5374aC618dfe5243ddD1e264E7",
418+
"ethereumDIDRegistry": "0xdCa7EF03e98e0DC2B855bE647C39ABe984fcF21B"
419+
},
420+
"mainnet": {
421+
"ens": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
422+
"ethereumDIDRegistry": "0xdCa7EF03e98e0DC2B855bE647C39ABe984fcF21B"
423+
}
415424
}

contracts/GNS.sol

Lines changed: 60 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ contract GNS is Governed, BancorFormula {
6060
// -- Events --
6161

6262
/**
63-
* @dev TODO
63+
* @dev Emitted when graph account sets their default name
6464
*/
6565
event SetDefaultName(
6666
address graphAccount,
@@ -69,6 +69,9 @@ contract GNS is Governed, BancorFormula {
6969
string name
7070
);
7171

72+
/**
73+
* @dev Emitted when graph account sets a subgraphs metadata on IPFS
74+
*/
7275
event SubgraphMetadataUpdated(
7376
address graphAccount,
7477
uint256 subgraphNumber,
@@ -99,8 +102,6 @@ contract GNS is Governed, BancorFormula {
99102
event NameSignalEnabled(
100103
address graphAccount,
101104
uint256 subgraphNumber,
102-
uint256 vSignalCreated,
103-
uint256 nSignalCreated,
104105
bytes32 subgraphDeploymentID,
105106
uint32 reserveRatio
106107
);
@@ -197,6 +198,14 @@ contract GNS is Governed, BancorFormula {
197198
emit ParameterUpdated("minimumVSignalStake");
198199
}
199200

201+
/**
202+
* @dev Allows a graph account to publish a new subgraph, which means a new subgraph number
203+
* will be used.
204+
* @param _graphAccount Account that is publishing the subgraph
205+
* @param _nameSystem Name system account already has ownership of a name in
206+
* @param _nameIdentifier The unique identifier that is used to identify the name in the system
207+
* @param _name The name being set as default
208+
*/
200209
function setDefaultName(
201210
address _graphAccount,
202211
uint8 _nameSystem,
@@ -206,12 +215,19 @@ contract GNS is Governed, BancorFormula {
206215
emit SetDefaultName(_graphAccount, _nameSystem, _nameIdentifier, _name);
207216
}
208217

218+
/**
219+
* @dev Allows a graph account to publish a new subgraph, which means a new subgraph number
220+
* will be used.
221+
* @param _graphAccount Account that is publishing the subgraph
222+
* @param _subgraphNumber Subgraph deployment ID of the version, linked to the name
223+
* @param _subgraphMetadata IPFS hash for the subgraph metadata
224+
*/
209225
function updateSubgraphMetadata(
210226
address _graphAccount,
211227
uint256 _subgraphNumber,
212-
bytes32 _metadataHash
228+
bytes32 _subgraphMetadata
213229
) public onlyGraphAccountOwner(_graphAccount) {
214-
emit SubgraphMetadataUpdated(_graphAccount, _subgraphNumber, _metadataHash);
230+
emit SubgraphMetadataUpdated(_graphAccount, _subgraphNumber, _subgraphMetadata);
215231
}
216232

217233
/**
@@ -220,15 +236,21 @@ contract GNS is Governed, BancorFormula {
220236
* @param _graphAccount Account that is publishing the subgraph
221237
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
222238
* @param _versionMetadata IPFS hash for the subgraph version metadata
239+
* @param _subgraphMetadata IPFS hash for the subgraph metadata
240+
* @param _graphTokens Graph tokens deposited to initialze the curve
223241
*/
224242
function publishNewSubgraph(
225243
address _graphAccount,
226244
bytes32 _subgraphDeploymentID,
227-
bytes32 _versionMetadata
245+
bytes32 _versionMetadata,
246+
bytes32 _subgraphMetadata,
247+
uint256 _graphTokens
228248
) external onlyGraphAccountOwner(_graphAccount) {
229249
uint256 subgraphNumber = graphAccountSubgraphNumbers[_graphAccount];
230250
publishVersion(_graphAccount, subgraphNumber, _subgraphDeploymentID, _versionMetadata);
231251
graphAccountSubgraphNumbers[_graphAccount]++;
252+
updateSubgraphMetadata(_graphAccount, subgraphNumber, _subgraphMetadata);
253+
enableNameSignal(_graphAccount, subgraphNumber, _graphTokens);
232254
}
233255

234256
/**
@@ -250,11 +272,17 @@ contract GNS is Governed, BancorFormula {
250272
isPublished(_graphAccount, _subgraphNumber),
251273
"GNS: Cannot update version if not published, or has been deprecated"
252274
);
275+
bytes32 oldSubgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
276+
require(
277+
_subgraphDeploymentID != oldSubgraphDeploymentID,
278+
"GNS: Cannot publish a new version with the same subgraph deployment ID"
279+
);
253280
publishVersion(_graphAccount, _subgraphNumber, _subgraphDeploymentID, _versionMetadata);
281+
upgradeNameSignal(_graphAccount, _subgraphNumber, _subgraphDeploymentID);
254282
}
255283

256284
/**
257-
* @dev Internal function used by both external publishing functions
285+
* @dev Private function used by both external publishing functions
258286
* @param _graphAccount Account that is publishing the subgraph
259287
* @param _subgraphNumber Subgraph number for the account
260288
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
@@ -265,7 +293,7 @@ contract GNS is Governed, BancorFormula {
265293
uint256 _subgraphNumber,
266294
bytes32 _subgraphDeploymentID,
267295
bytes32 _versionMetadata
268-
) internal {
296+
) private {
269297
require(_subgraphDeploymentID != 0, "GNS: Cannot set deploymentID to 0 in publish");
270298

271299
// Stores a subgraph deployment ID, which indicates a version has been created
@@ -292,8 +320,11 @@ contract GNS is Governed, BancorFormula {
292320
isPublished(_graphAccount, _subgraphNumber),
293321
"GNS: Cannot deprecate a subgraph which does not exist"
294322
);
323+
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
295324
delete subgraphs[_graphAccount][_subgraphNumber];
296325
emit SubgraphDeprecated(_graphAccount, _subgraphNumber);
326+
327+
disableNameSignal(_graphAccount, _subgraphNumber, subgraphDeploymentID);
297328
}
298329

299330
/**
@@ -307,36 +338,19 @@ contract GNS is Governed, BancorFormula {
307338
address _graphAccount,
308339
uint256 _subgraphNumber,
309340
uint256 _graphTokens
310-
) external onlyGraphAccountOwner(_graphAccount) {
311-
// Checks
341+
) private {
312342
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
313-
require(
314-
namePool.reserveRatio == 0,
315-
"GNS: Enable name signal was already called for this subgraph number"
316-
);
317343
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
318-
require(
319-
subgraphDeploymentID != 0,
320-
"GNS: Cannot enable name signal on a subgraph without a deployment ID"
321-
);
322-
323344
namePool.reserveRatio = defaultReserveRatio;
324345
namePool.subgraphDeploymentID = subgraphDeploymentID;
325-
326-
// Update values
327-
(uint256 vSignal, uint256 nSignal) = _mintNSignal(
328-
_graphAccount,
329-
_subgraphNumber,
330-
_graphTokens
331-
);
332346
emit NameSignalEnabled(
333347
_graphAccount,
334348
_subgraphNumber,
335-
vSignal,
336-
nSignal,
337349
subgraphDeploymentID,
338350
defaultReserveRatio
339351
);
352+
353+
_mintNSignal(_graphAccount, _subgraphNumber, _graphTokens);
340354
}
341355

342356
/**
@@ -349,16 +363,7 @@ contract GNS is Governed, BancorFormula {
349363
address _graphAccount,
350364
uint256 _subgraphNumber,
351365
bytes32 _newSubgraphDeploymentID
352-
) external onlyGraphAccountOwner(_graphAccount) {
353-
require(_newSubgraphDeploymentID != 0, "GNS: Deployment ID cannot be 0");
354-
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
355-
// Subgraph owner must first update the numbered subgraph to point to this deploymentID
356-
// Then they can direct the name curators vSignal to this new name curation curve
357-
require(
358-
_newSubgraphDeploymentID == subgraphDeploymentID,
359-
"GNS: Owner did not update subgraph deployment ID"
360-
);
361-
366+
) private {
362367
// This is to prevent the owner from front running their name curators signal by posting
363368
// their own signal ahead, bringing the name curators in, and dumping on them
364369
require(
@@ -367,10 +372,6 @@ contract GNS is Governed, BancorFormula {
367372
);
368373

369374
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
370-
require(
371-
_newSubgraphDeploymentID != namePool.subgraphDeploymentID,
372-
"GNS: Cannot upgrade to the exact same subgraph deployment ID"
373-
);
374375
require(
375376
namePool.nSignal > 0,
376377
"GNS: There must be nSignal on this subgraph for curve math to work"
@@ -385,7 +386,7 @@ contract GNS is Governed, BancorFormula {
385386
);
386387
namePool.vSignal = namePool.vSignal.sub(vSignalOld);
387388
// Update name signals deployment ID to match the subgraphs deployment ID
388-
namePool.subgraphDeploymentID = subgraphDeploymentID;
389+
namePool.subgraphDeploymentID = _newSubgraphDeploymentID;
389390

390391
// nSignal stays constant, but vSignal can change here
391392
uint256 vSignalNew = curation.mint(
@@ -398,7 +399,7 @@ contract GNS is Governed, BancorFormula {
398399
_subgraphNumber,
399400
vSignalNew,
400401
tokens + withdrawalFees,
401-
subgraphDeploymentID
402+
_newSubgraphDeploymentID
402403
);
403404
}
404405

@@ -413,26 +414,13 @@ contract GNS is Governed, BancorFormula {
413414
uint256 _subgraphNumber,
414415
uint256 _tokens
415416
) external {
416-
address nameCurator = msg.sender;
417417
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
418418
require(namePool.disabled == false, "GNS: Cannot be disabled");
419419
require(
420420
namePool.subgraphDeploymentID != 0,
421421
"GNS: Must deposit on a name signal that exists"
422422
);
423-
424-
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
425-
426-
// This happens when the owner updates the deploymentID, but has not yet updated the
427-
// name signal to point here. Preventing users from staking on name
428-
// NOTE - might be possible to combine this into one function, but lots of rework
429-
require(
430-
namePool.subgraphDeploymentID == subgraphDeploymentID,
431-
"GNS: Name owner updated version without updating name signal"
432-
);
433-
434-
(uint256 vSignal, uint256 nSignal) = _mintNSignal(_graphAccount, _subgraphNumber, _tokens);
435-
emit NSignalMinted(_graphAccount, _subgraphNumber, msg.sender, nSignal, vSignal);
423+
_mintNSignal(_graphAccount, _subgraphNumber, _tokens);
436424
}
437425

438426
/**
@@ -450,24 +438,11 @@ contract GNS is Governed, BancorFormula {
450438
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
451439
uint256 curatorNSignal = namePool.curatorNSignal[nameCurator];
452440
require(namePool.disabled == false, "GNS: Cannot be disabled");
453-
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
454-
455-
// This happens when the owner updates the deploymentID, but has not yet updated the
456-
// name signal to point here. Preventing users from staking on name
457-
// NOTE - might be possible to combine this into one function, but lots of rework
458-
require(
459-
namePool.subgraphDeploymentID == subgraphDeploymentID,
460-
"GNS: Name owner updated version without updating name signal"
461-
);
462441
require(
463442
_nSignal <= curatorNSignal,
464443
"GNS: Curator cannot withdraw more nSignal than they have"
465444
);
466-
467-
(uint256 vSignal, uint256 tokens) = _burnNSignal(_graphAccount, _subgraphNumber, _nSignal);
468-
// Return the tokens to the nameCurator
469-
require(token.transfer(nameCurator, tokens), "GNS: Error sending nameCurators tokens");
470-
emit NSignalBurned(_graphAccount, _subgraphNumber, msg.sender, _nSignal, vSignal, tokens);
445+
_burnNSignal(_graphAccount, _subgraphNumber, _nSignal);
471446
}
472447

473448
/**
@@ -476,21 +451,17 @@ contract GNS is Governed, BancorFormula {
476451
* contract holds the GRT from burning the vSignal, which all curators can withdraw manually.
477452
* @param _graphAccount Account that is deprecating their name curation
478453
* @param _subgraphNumber Subgraph number
454+
* @param _subgraphDeploymentID Subgraph deployment ID of the deprecating subgraph
479455
*/
480-
function disableNameSignal(address _graphAccount, uint256 _subgraphNumber)
481-
external
482-
onlyGraphAccountOwner(_graphAccount)
483-
{
484-
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
456+
function disableNameSignal(
457+
address _graphAccount,
458+
uint256 _subgraphNumber,
459+
bytes32 _subgraphDeploymentID
460+
) private {
485461
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
486-
require(
487-
namePool.subgraphDeploymentID == subgraphDeploymentID, // TODO EDGE CASE - when both subgraph ids are 0, this will fail, leading something to be deprecated before it exists
488-
"GNS: Name owner updated version without updating name signal"
489-
);
490-
require(namePool.disabled == false, "GNS: Cannot be disabled twice");
491462
uint256 vSignal = namePool.vSignal;
492463
namePool.vSignal = 0;
493-
(uint256 tokens, uint256 withdrawalFees) = curation.burn(subgraphDeploymentID, vSignal);
464+
(uint256 tokens, uint256 withdrawalFees) = curation.burn(_subgraphDeploymentID, vSignal);
494465

495466
// Get the owner of the Name to reimburse the withdrawal fee
496467
require(
@@ -541,14 +512,15 @@ contract GNS is Governed, BancorFormula {
541512
) private returns (uint256, uint256) {
542513
require(
543514
token.transferFrom(msg.sender, address(this), _tokens),
544-
"GNS: Cannot transfer tokens to stake"
515+
"GNS: Cannot transfer tokens to mint n signal"
545516
);
546517
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
547518
uint256 vSignal = curation.mint(namePool.subgraphDeploymentID, _tokens);
548519
uint256 nSignal = vSignalToNSignal(_graphAccount, _subgraphNumber, vSignal);
549520
namePool.vSignal = namePool.vSignal.add(vSignal);
550521
namePool.nSignal = namePool.nSignal.add(nSignal);
551522
namePool.curatorNSignal[msg.sender] = namePool.curatorNSignal[msg.sender].add(nSignal);
523+
emit NSignalMinted(_graphAccount, _subgraphNumber, msg.sender, nSignal, vSignal);
552524
return (vSignal, nSignal);
553525
}
554526

@@ -564,12 +536,16 @@ contract GNS is Governed, BancorFormula {
564536
uint256 _subgraphNumber,
565537
uint256 _nSignal
566538
) private returns (uint256, uint256) {
539+
address nameCurator = msg.sender;
567540
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
568541
uint256 vSignal = nSignalToVSignal(_graphAccount, _subgraphNumber, _nSignal);
569542
(uint256 tokens, ) = curation.burn(namePool.subgraphDeploymentID, vSignal);
570543
namePool.vSignal = namePool.vSignal.sub(vSignal);
571544
namePool.nSignal = namePool.nSignal.sub(_nSignal);
572545
namePool.curatorNSignal[msg.sender] = namePool.curatorNSignal[msg.sender].sub(_nSignal);
546+
// Return the tokens to the nameCurator
547+
require(token.transfer(nameCurator, tokens), "GNS: Error sending nameCurators tokens");
548+
emit NSignalBurned(_graphAccount, _subgraphNumber, msg.sender, _nSignal, vSignal, tokens);
573549
return (vSignal, tokens);
574550
}
575551

0 commit comments

Comments
 (0)