@@ -5,8 +5,10 @@ pragma experimental ABIEncoderV2;
5
5
6
6
import "@openzeppelin/contracts/math/SafeMath.sol " ;
7
7
8
+ import "../base/Multicall.sol " ;
8
9
import "../bancor/BancorFormula.sol " ;
9
10
import "../upgrades/GraphUpgradeable.sol " ;
11
+ import "../utils/TokenUtils.sol " ;
10
12
11
13
import "./IGNS.sol " ;
12
14
import "./GNSStorage.sol " ;
@@ -17,10 +19,14 @@ import "./GNSStorage.sol";
17
19
* used in the scope of the Graph Network. It translates subgraph names into subgraph versions.
18
20
* Each version is associated with a Subgraph Deployment. The contract has no knowledge of
19
21
* human-readable names. All human readable names emitted in events.
22
+ * The contract implements a multicall behaviour to support batching multiple calls in a single
23
+ * transaction.
20
24
*/
21
- contract GNS is GNSV1Storage , GraphUpgradeable , IGNS {
25
+ contract GNS is GNSV1Storage , GraphUpgradeable , IGNS , Multicall {
22
26
using SafeMath for uint256 ;
23
27
28
+ // -- Constants --
29
+
24
30
uint256 private constant MAX_UINT256 = 2 ** 256 - 1 ;
25
31
26
32
// 100% in parts per million
@@ -136,16 +142,28 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
136
142
uint256 withdrawnGRT
137
143
);
138
144
145
+ // -- Modifiers --
146
+
139
147
/**
140
- @dev Modifier that allows a function to be called by owner of a graph account
141
- @param _graphAccount Address of the graph account
142
- */
143
- modifier onlyGraphAccountOwner (address _graphAccount ) {
148
+ * @dev Check if the owner is the graph account
149
+ * @param _graphAccount Address of the graph account
150
+ */
151
+ function _isGraphAccountOwner (address _graphAccount ) private view {
144
152
address graphAccountOwner = erc1056Registry.identityOwner (_graphAccount);
145
153
require (graphAccountOwner == msg .sender , "GNS: Only graph account owner can call " );
154
+ }
155
+
156
+ /**
157
+ * @dev Modifier that allows a function to be called by owner of a graph account
158
+ * @param _graphAccount Address of the graph account
159
+ */
160
+ modifier onlyGraphAccountOwner (address _graphAccount ) {
161
+ _isGraphAccountOwner (_graphAccount);
146
162
_;
147
163
}
148
164
165
+ // -- Functions --
166
+
149
167
/**
150
168
* @dev Initialize this contract.
151
169
*/
@@ -408,10 +426,7 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
408
426
);
409
427
410
428
// Pull tokens from sender
411
- require (
412
- graphToken ().transferFrom (msg .sender , address (this ), _tokensIn),
413
- "GNS: Cannot transfer tokens to mint n signal "
414
- );
429
+ TokenUtils.pullTokens (graphToken (), msg .sender , _tokensIn);
415
430
416
431
// Get name signal to mint for tokens deposited
417
432
(uint256 vSignal , ) = curation ().mint (namePool.subgraphDeploymentID, _tokensIn, 0 );
@@ -461,11 +476,8 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
461
476
namePool.nSignal = namePool.nSignal.sub (_nSignal);
462
477
namePool.curatorNSignal[msg .sender ] = namePool.curatorNSignal[msg .sender ].sub (_nSignal);
463
478
464
- // Return the tokens to the nameCurator
465
- require (
466
- graphToken ().transfer (msg .sender , tokens),
467
- "GNS: Error sending nameCurators tokens "
468
- );
479
+ // Return the tokens to the curator
480
+ TokenUtils.pushTokens (graphToken (), msg .sender , tokens);
469
481
470
482
emit NSignalBurned (_graphAccount, _subgraphNumber, msg .sender , _nSignal, vSignal, tokens);
471
483
}
@@ -482,6 +494,7 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
482
494
483
495
// If no nSignal, then no need to burn vSignal
484
496
if (namePool.nSignal != 0 ) {
497
+ // Note: No slippage, burn at any cost
485
498
namePool.withdrawableGRT = curation ().burn (
486
499
namePool.subgraphDeploymentID,
487
500
namePool.vSignal,
@@ -522,10 +535,8 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
522
535
namePool.nSignal = namePool.nSignal.sub (curatorNSignal);
523
536
namePool.withdrawableGRT = namePool.withdrawableGRT.sub (tokensOut);
524
537
525
- require (
526
- graphToken ().transfer (msg .sender , tokensOut),
527
- "GNS: Error withdrawing tokens for nameCurator "
528
- );
538
+ // Return tokens to the curator
539
+ TokenUtils.pushTokens (graphToken (), msg .sender , tokensOut);
529
540
530
541
emit GRTWithdrawn (_graphAccount, _subgraphNumber, msg .sender , curatorNSignal, tokensOut);
531
542
}
@@ -567,10 +578,8 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
567
578
uint256 ownerTaxAdjustedUp = totalAdjustedUp.sub (_tokens);
568
579
569
580
// Get the owner of the subgraph to reimburse the curation tax
570
- require (
571
- graphToken ().transferFrom (_owner, address (this ), ownerTaxAdjustedUp),
572
- "GNS: Error reimbursing curation tax "
573
- );
581
+ TokenUtils.pullTokens (graphToken (), _owner, ownerTaxAdjustedUp);
582
+
574
583
return totalAdjustedUp;
575
584
}
576
585
@@ -587,8 +596,8 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
587
596
uint256 _tokensIn
588
597
)
589
598
public
590
- override
591
599
view
600
+ override
592
601
returns (
593
602
uint256 ,
594
603
uint256 ,
@@ -615,7 +624,7 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
615
624
address _graphAccount ,
616
625
uint256 _subgraphNumber ,
617
626
uint256 _nSignalIn
618
- ) public override view returns (uint256 , uint256 ) {
627
+ ) public view override returns (uint256 , uint256 ) {
619
628
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
620
629
uint256 vSignal = nSignalToVSignal (_graphAccount, _subgraphNumber, _nSignalIn);
621
630
uint256 tokensOut = curation ().signalToTokens (namePool.subgraphDeploymentID, vSignal);
@@ -633,7 +642,7 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
633
642
address _graphAccount ,
634
643
uint256 _subgraphNumber ,
635
644
uint256 _vSignalIn
636
- ) public override view returns (uint256 ) {
645
+ ) public view override returns (uint256 ) {
637
646
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
638
647
639
648
// Handle initialization by using 1:1 version to name signal
@@ -661,7 +670,7 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
661
670
address _graphAccount ,
662
671
uint256 _subgraphNumber ,
663
672
uint256 _nSignalIn
664
- ) public override view returns (uint256 ) {
673
+ ) public view override returns (uint256 ) {
665
674
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
666
675
return
667
676
BancorFormula (bondingCurve).calculateSaleReturn (
@@ -683,7 +692,7 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
683
692
address _graphAccount ,
684
693
uint256 _subgraphNumber ,
685
694
address _curator
686
- ) public override view returns (uint256 ) {
695
+ ) public view override returns (uint256 ) {
687
696
return nameSignals[_graphAccount][_subgraphNumber].curatorNSignal[_curator];
688
697
}
689
698
@@ -695,8 +704,8 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
695
704
*/
696
705
function isPublished (address _graphAccount , uint256 _subgraphNumber )
697
706
public
698
- override
699
707
view
708
+ override
700
709
returns (bool )
701
710
{
702
711
return subgraphs[_graphAccount][_subgraphNumber] != 0 ;
0 commit comments