@@ -33,16 +33,19 @@ contract GNS is Managed {
33
33
// Equates to Connector weight on bancor formula to be CW = 1
34
34
uint32 private constant defaultReserveRatio = 1000000 ;
35
35
36
+ // In parts per hundred
37
+ uint32 public changeFeePercentage = 50 ;
38
+
39
+ // Bonding curve formula
40
+ address public bondingCurve;
41
+
36
42
// Amount of nSignal you get with your minimum vSignal stake
37
43
uint256 private constant VSIGNAL_PER_MINIMUM_NSIGNAL = 1 ether ;
38
44
39
45
// Minimum amount of vSignal that must be staked to start the curve
40
46
// Set to 10**18, as vSignal has 18 decimals
41
47
uint256 public minimumVSignalStake = 10 ** 18 ;
42
48
43
- // Bonding curve formula
44
- address public bondingCurve;
45
-
46
49
// graphAccountID => subgraphNumber => subgraphDeploymentID
47
50
// subgraphNumber = A number associated to a graph accounts deployed subgraph. This
48
51
// is used to point to a subgraphID (graphAccountID + subgraphNumber)
@@ -203,6 +206,17 @@ contract GNS is Managed {
203
206
emit ParameterUpdated ("minimumVSignalStake " );
204
207
}
205
208
209
+ /**
210
+ * @dev Set the change fee percentage. This is used to prevent a subgraph owner to drain all
211
+ * the name curators tokens while upgrading or deprecating and is configurable in parts per hundred.
212
+ * @param _changeFeePercentage Change fee percentage
213
+ */
214
+ function setChangeFeePercentage (uint32 _changeFeePercentage ) external onlyGovernor {
215
+ require (_changeFeePercentage <= 100 , "Change fee must be 100 or less " );
216
+ changeFeePercentage = _changeFeePercentage;
217
+ emit ParameterUpdated ("changeFeePercentage " );
218
+ }
219
+
206
220
/**
207
221
* @dev Allows a graph account to set a default name
208
222
* @param _graphAccount Account that is setting their name
@@ -379,15 +393,13 @@ contract GNS is Managed {
379
393
namePool.subgraphDeploymentID,
380
394
vSignalOld
381
395
);
396
+ uint256 ownerFee = _ownerFee (withdrawalFees, _graphAccount);
382
397
namePool.vSignal = namePool.vSignal.sub (vSignalOld);
383
398
// Update name signals deployment ID to match the subgraphs deployment ID
384
399
namePool.subgraphDeploymentID = _newSubgraphDeploymentID;
385
400
386
401
// nSignal stays constant, but vSignal can change here
387
- uint256 vSignalNew = curation.mint (
388
- namePool.subgraphDeploymentID,
389
- (tokens + withdrawalFees)
390
- );
402
+ uint256 vSignalNew = curation.mint (namePool.subgraphDeploymentID, (tokens + ownerFee));
391
403
namePool.vSignal = vSignalNew;
392
404
emit NameSignalUpgrade (
393
405
_graphAccount,
@@ -463,12 +475,8 @@ contract GNS is Managed {
463
475
vSignal
464
476
);
465
477
466
- // Get the owner of the Name to reimburse the withdrawal fee
467
- require (
468
- graphToken ().transferFrom (_graphAccount, address (this ), withdrawalFees),
469
- "GNS: Error reimbursing withdrawal fees "
470
- );
471
- namePool.withdrawableGRT = tokens + withdrawalFees;
478
+ uint256 ownerFee = _ownerFee (withdrawalFees, _graphAccount);
479
+ namePool.withdrawableGRT = tokens + ownerFee;
472
480
}
473
481
// Set the NameCurationPool fields to make it disabled
474
482
namePool.disabled = true ;
@@ -573,6 +581,22 @@ contract GNS is Managed {
573
581
return (tokens, withdrawalFees);
574
582
}
575
583
584
+ /**
585
+ * @dev Calculate fee that owner will have to cover for upgrading or deprecating
586
+ * @param _owner Subgraph owner
587
+ * @param _withdrawalFees Total withdrawal fee for changing subgraphs
588
+ * @return Amount the owner must pay by transferring GRT to the GNS
589
+ */
590
+ function _ownerFee (uint256 _withdrawalFees , address _owner ) private returns (uint256 ) {
591
+ uint256 ownerFee = _withdrawalFees.mul (changeFeePercentage).div (100 );
592
+ // Get the owner of the Name to reimburse the withdrawal fee
593
+ require (
594
+ graphToken ().transferFrom (_owner, address (this ), ownerFee),
595
+ "GNS: Error reimbursing withdrawal fees "
596
+ );
597
+ return ownerFee;
598
+ }
599
+
576
600
/**
577
601
* @dev Calculate nSignal to be returned for an amount of tokens
578
602
* @param _graphAccount Subgraph owner
0 commit comments