@@ -60,7 +60,7 @@ contract GNS is Governed, BancorFormula {
60
60
// -- Events --
61
61
62
62
/**
63
- * @dev TODO
63
+ * @dev Emitted when graph account sets their default name
64
64
*/
65
65
event SetDefaultName (
66
66
address graphAccount ,
@@ -69,6 +69,9 @@ contract GNS is Governed, BancorFormula {
69
69
string name
70
70
);
71
71
72
+ /**
73
+ * @dev Emitted when graph account sets a subgraphs metadata on IPFS
74
+ */
72
75
event SubgraphMetadataUpdated (
73
76
address graphAccount ,
74
77
uint256 subgraphNumber ,
@@ -99,8 +102,6 @@ contract GNS is Governed, BancorFormula {
99
102
event NameSignalEnabled (
100
103
address graphAccount ,
101
104
uint256 subgraphNumber ,
102
- uint256 vSignalCreated ,
103
- uint256 nSignalCreated ,
104
105
bytes32 subgraphDeploymentID ,
105
106
uint32 reserveRatio
106
107
);
@@ -197,6 +198,14 @@ contract GNS is Governed, BancorFormula {
197
198
emit ParameterUpdated ("minimumVSignalStake " );
198
199
}
199
200
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
+ */
200
209
function setDefaultName (
201
210
address _graphAccount ,
202
211
uint8 _nameSystem ,
@@ -206,12 +215,19 @@ contract GNS is Governed, BancorFormula {
206
215
emit SetDefaultName (_graphAccount, _nameSystem, _nameIdentifier, _name);
207
216
}
208
217
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
+ */
209
225
function updateSubgraphMetadata (
210
226
address _graphAccount ,
211
227
uint256 _subgraphNumber ,
212
- bytes32 _metadataHash
228
+ bytes32 _subgraphMetadata
213
229
) public onlyGraphAccountOwner (_graphAccount) {
214
- emit SubgraphMetadataUpdated (_graphAccount, _subgraphNumber, _metadataHash );
230
+ emit SubgraphMetadataUpdated (_graphAccount, _subgraphNumber, _subgraphMetadata );
215
231
}
216
232
217
233
/**
@@ -220,15 +236,21 @@ contract GNS is Governed, BancorFormula {
220
236
* @param _graphAccount Account that is publishing the subgraph
221
237
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
222
238
* @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
223
241
*/
224
242
function publishNewSubgraph (
225
243
address _graphAccount ,
226
244
bytes32 _subgraphDeploymentID ,
227
- bytes32 _versionMetadata
245
+ bytes32 _versionMetadata ,
246
+ bytes32 _subgraphMetadata ,
247
+ uint256 _graphTokens
228
248
) external onlyGraphAccountOwner (_graphAccount) {
229
249
uint256 subgraphNumber = graphAccountSubgraphNumbers[_graphAccount];
230
250
publishVersion (_graphAccount, subgraphNumber, _subgraphDeploymentID, _versionMetadata);
231
251
graphAccountSubgraphNumbers[_graphAccount]++ ;
252
+ updateSubgraphMetadata (_graphAccount, subgraphNumber, _subgraphMetadata);
253
+ enableNameSignal (_graphAccount, subgraphNumber, _graphTokens);
232
254
}
233
255
234
256
/**
@@ -250,11 +272,17 @@ contract GNS is Governed, BancorFormula {
250
272
isPublished (_graphAccount, _subgraphNumber),
251
273
"GNS: Cannot update version if not published, or has been deprecated "
252
274
);
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
+ );
253
280
publishVersion (_graphAccount, _subgraphNumber, _subgraphDeploymentID, _versionMetadata);
281
+ upgradeNameSignal (_graphAccount, _subgraphNumber, _subgraphDeploymentID);
254
282
}
255
283
256
284
/**
257
- * @dev Internal function used by both external publishing functions
285
+ * @dev Private function used by both external publishing functions
258
286
* @param _graphAccount Account that is publishing the subgraph
259
287
* @param _subgraphNumber Subgraph number for the account
260
288
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
@@ -265,7 +293,7 @@ contract GNS is Governed, BancorFormula {
265
293
uint256 _subgraphNumber ,
266
294
bytes32 _subgraphDeploymentID ,
267
295
bytes32 _versionMetadata
268
- ) internal {
296
+ ) private {
269
297
require (_subgraphDeploymentID != 0 , "GNS: Cannot set deploymentID to 0 in publish " );
270
298
271
299
// Stores a subgraph deployment ID, which indicates a version has been created
@@ -292,8 +320,11 @@ contract GNS is Governed, BancorFormula {
292
320
isPublished (_graphAccount, _subgraphNumber),
293
321
"GNS: Cannot deprecate a subgraph which does not exist "
294
322
);
323
+ bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
295
324
delete subgraphs[_graphAccount][_subgraphNumber];
296
325
emit SubgraphDeprecated (_graphAccount, _subgraphNumber);
326
+
327
+ disableNameSignal (_graphAccount, _subgraphNumber, subgraphDeploymentID);
297
328
}
298
329
299
330
/**
@@ -307,36 +338,19 @@ contract GNS is Governed, BancorFormula {
307
338
address _graphAccount ,
308
339
uint256 _subgraphNumber ,
309
340
uint256 _graphTokens
310
- ) external onlyGraphAccountOwner (_graphAccount) {
311
- // Checks
341
+ ) private {
312
342
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
- );
317
343
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
-
323
344
namePool.reserveRatio = defaultReserveRatio;
324
345
namePool.subgraphDeploymentID = subgraphDeploymentID;
325
-
326
- // Update values
327
- (uint256 vSignal , uint256 nSignal ) = _mintNSignal (
328
- _graphAccount,
329
- _subgraphNumber,
330
- _graphTokens
331
- );
332
346
emit NameSignalEnabled (
333
347
_graphAccount,
334
348
_subgraphNumber,
335
- vSignal,
336
- nSignal,
337
349
subgraphDeploymentID,
338
350
defaultReserveRatio
339
351
);
352
+
353
+ _mintNSignal (_graphAccount, _subgraphNumber, _graphTokens);
340
354
}
341
355
342
356
/**
@@ -349,16 +363,7 @@ contract GNS is Governed, BancorFormula {
349
363
address _graphAccount ,
350
364
uint256 _subgraphNumber ,
351
365
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 {
362
367
// This is to prevent the owner from front running their name curators signal by posting
363
368
// their own signal ahead, bringing the name curators in, and dumping on them
364
369
require (
@@ -367,10 +372,6 @@ contract GNS is Governed, BancorFormula {
367
372
);
368
373
369
374
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
370
- require (
371
- _newSubgraphDeploymentID != namePool.subgraphDeploymentID,
372
- "GNS: Cannot upgrade to the exact same subgraph deployment ID "
373
- );
374
375
require (
375
376
namePool.nSignal > 0 ,
376
377
"GNS: There must be nSignal on this subgraph for curve math to work "
@@ -385,7 +386,7 @@ contract GNS is Governed, BancorFormula {
385
386
);
386
387
namePool.vSignal = namePool.vSignal.sub (vSignalOld);
387
388
// Update name signals deployment ID to match the subgraphs deployment ID
388
- namePool.subgraphDeploymentID = subgraphDeploymentID ;
389
+ namePool.subgraphDeploymentID = _newSubgraphDeploymentID ;
389
390
390
391
// nSignal stays constant, but vSignal can change here
391
392
uint256 vSignalNew = curation.mint (
@@ -398,7 +399,7 @@ contract GNS is Governed, BancorFormula {
398
399
_subgraphNumber,
399
400
vSignalNew,
400
401
tokens + withdrawalFees,
401
- subgraphDeploymentID
402
+ _newSubgraphDeploymentID
402
403
);
403
404
}
404
405
@@ -413,26 +414,13 @@ contract GNS is Governed, BancorFormula {
413
414
uint256 _subgraphNumber ,
414
415
uint256 _tokens
415
416
) external {
416
- address nameCurator = msg .sender ;
417
417
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
418
418
require (namePool.disabled == false , "GNS: Cannot be disabled " );
419
419
require (
420
420
namePool.subgraphDeploymentID != 0 ,
421
421
"GNS: Must deposit on a name signal that exists "
422
422
);
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);
436
424
}
437
425
438
426
/**
@@ -450,24 +438,11 @@ contract GNS is Governed, BancorFormula {
450
438
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
451
439
uint256 curatorNSignal = namePool.curatorNSignal[nameCurator];
452
440
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
- );
462
441
require (
463
442
_nSignal <= curatorNSignal,
464
443
"GNS: Curator cannot withdraw more nSignal than they have "
465
444
);
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);
471
446
}
472
447
473
448
/**
@@ -476,21 +451,17 @@ contract GNS is Governed, BancorFormula {
476
451
* contract holds the GRT from burning the vSignal, which all curators can withdraw manually.
477
452
* @param _graphAccount Account that is deprecating their name curation
478
453
* @param _subgraphNumber Subgraph number
454
+ * @param _subgraphDeploymentID Subgraph deployment ID of the deprecating subgraph
479
455
*/
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 {
485
461
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 " );
491
462
uint256 vSignal = namePool.vSignal;
492
463
namePool.vSignal = 0 ;
493
- (uint256 tokens , uint256 withdrawalFees ) = curation.burn (subgraphDeploymentID , vSignal);
464
+ (uint256 tokens , uint256 withdrawalFees ) = curation.burn (_subgraphDeploymentID , vSignal);
494
465
495
466
// Get the owner of the Name to reimburse the withdrawal fee
496
467
require (
@@ -541,14 +512,15 @@ contract GNS is Governed, BancorFormula {
541
512
) private returns (uint256 , uint256 ) {
542
513
require (
543
514
token.transferFrom (msg .sender , address (this ), _tokens),
544
- "GNS: Cannot transfer tokens to stake "
515
+ "GNS: Cannot transfer tokens to mint n signal "
545
516
);
546
517
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
547
518
uint256 vSignal = curation.mint (namePool.subgraphDeploymentID, _tokens);
548
519
uint256 nSignal = vSignalToNSignal (_graphAccount, _subgraphNumber, vSignal);
549
520
namePool.vSignal = namePool.vSignal.add (vSignal);
550
521
namePool.nSignal = namePool.nSignal.add (nSignal);
551
522
namePool.curatorNSignal[msg .sender ] = namePool.curatorNSignal[msg .sender ].add (nSignal);
523
+ emit NSignalMinted (_graphAccount, _subgraphNumber, msg .sender , nSignal, vSignal);
552
524
return (vSignal, nSignal);
553
525
}
554
526
@@ -564,12 +536,16 @@ contract GNS is Governed, BancorFormula {
564
536
uint256 _subgraphNumber ,
565
537
uint256 _nSignal
566
538
) private returns (uint256 , uint256 ) {
539
+ address nameCurator = msg .sender ;
567
540
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
568
541
uint256 vSignal = nSignalToVSignal (_graphAccount, _subgraphNumber, _nSignal);
569
542
(uint256 tokens , ) = curation.burn (namePool.subgraphDeploymentID, vSignal);
570
543
namePool.vSignal = namePool.vSignal.sub (vSignal);
571
544
namePool.nSignal = namePool.nSignal.sub (_nSignal);
572
545
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);
573
549
return (vSignal, tokens);
574
550
}
575
551
0 commit comments