Skip to content

Commit 9dbe135

Browse files
committed
Remove mint from creating a name signal
1 parent 557a408 commit 9dbe135

File tree

3 files changed

+52
-76
lines changed

3 files changed

+52
-76
lines changed

contracts/GNS.sol

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ contract GNS is Governed, BancorFormula {
199199
}
200200

201201
/**
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
202+
* @dev Allows a graph account to set a default name
203+
* @param _graphAccount Account that is setting their name
205204
* @param _nameSystem Name system account already has ownership of a name in
206205
* @param _nameIdentifier The unique identifier that is used to identify the name in the system
207206
* @param _name The name being set as default
@@ -216,10 +215,9 @@ contract GNS is Governed, BancorFormula {
216215
}
217216

218217
/**
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
218+
* @dev Allows a graph account update the metadata of a subgraph they have published
219+
* @param _graphAccount Account that owns the subgraph
220+
* @param _subgraphNumber Subgraph number
223221
* @param _subgraphMetadata IPFS hash for the subgraph metadata
224222
*/
225223
function updateSubgraphMetadata(
@@ -237,20 +235,18 @@ contract GNS is Governed, BancorFormula {
237235
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
238236
* @param _versionMetadata IPFS hash for the subgraph version metadata
239237
* @param _subgraphMetadata IPFS hash for the subgraph metadata
240-
* @param _graphTokens Graph tokens deposited to initialze the curve
241238
*/
242239
function publishNewSubgraph(
243240
address _graphAccount,
244241
bytes32 _subgraphDeploymentID,
245242
bytes32 _versionMetadata,
246-
bytes32 _subgraphMetadata,
247-
uint256 _graphTokens
243+
bytes32 _subgraphMetadata
248244
) external onlyGraphAccountOwner(_graphAccount) {
249245
uint256 subgraphNumber = graphAccountSubgraphNumbers[_graphAccount];
250-
publishVersion(_graphAccount, subgraphNumber, _subgraphDeploymentID, _versionMetadata);
246+
_publishVersion(_graphAccount, subgraphNumber, _subgraphDeploymentID, _versionMetadata);
251247
graphAccountSubgraphNumbers[_graphAccount]++;
252248
updateSubgraphMetadata(_graphAccount, subgraphNumber, _subgraphMetadata);
253-
enableNameSignal(_graphAccount, subgraphNumber, _graphTokens);
249+
_enableNameSignal(_graphAccount, subgraphNumber);
254250
}
255251

256252
/**
@@ -277,8 +273,8 @@ contract GNS is Governed, BancorFormula {
277273
_subgraphDeploymentID != oldSubgraphDeploymentID,
278274
"GNS: Cannot publish a new version with the same subgraph deployment ID"
279275
);
280-
publishVersion(_graphAccount, _subgraphNumber, _subgraphDeploymentID, _versionMetadata);
281-
upgradeNameSignal(_graphAccount, _subgraphNumber, _subgraphDeploymentID);
276+
_publishVersion(_graphAccount, _subgraphNumber, _subgraphDeploymentID, _versionMetadata);
277+
_upgradeNameSignal(_graphAccount, _subgraphNumber, _subgraphDeploymentID);
282278
}
283279

284280
/**
@@ -288,7 +284,7 @@ contract GNS is Governed, BancorFormula {
288284
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
289285
* @param _versionMetadata IPFS hash for the subgraph version metadata
290286
*/
291-
function publishVersion(
287+
function _publishVersion(
292288
address _graphAccount,
293289
uint256 _subgraphNumber,
294290
bytes32 _subgraphDeploymentID,
@@ -324,21 +320,16 @@ contract GNS is Governed, BancorFormula {
324320
delete subgraphs[_graphAccount][_subgraphNumber];
325321
emit SubgraphDeprecated(_graphAccount, _subgraphNumber);
326322

327-
disableNameSignal(_graphAccount, _subgraphNumber, subgraphDeploymentID);
323+
_disableNameSignal(_graphAccount, _subgraphNumber, subgraphDeploymentID);
328324
}
329325

330326
/**
331327
* @dev Enable name signal on a graph accounts numbered subgraph, which points to a subgraph
332328
* deployment
333329
* @param _graphAccount Graph account enabling name signal
334330
* @param _subgraphNumber Subgraph number being used
335-
* @param _graphTokens Graph tokens deposited to initialze the curve
336331
*/
337-
function enableNameSignal(
338-
address _graphAccount,
339-
uint256 _subgraphNumber,
340-
uint256 _graphTokens
341-
) private {
332+
function _enableNameSignal(address _graphAccount, uint256 _subgraphNumber) private {
342333
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
343334
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
344335
namePool.reserveRatio = defaultReserveRatio;
@@ -349,8 +340,6 @@ contract GNS is Governed, BancorFormula {
349340
subgraphDeploymentID,
350341
defaultReserveRatio
351342
);
352-
353-
_mintNSignal(_graphAccount, _subgraphNumber, _graphTokens);
354343
}
355344

356345
/**
@@ -359,7 +348,7 @@ contract GNS is Governed, BancorFormula {
359348
* @param _subgraphNumber Subgraph number being used
360349
* @param _newSubgraphDeploymentID Deployment ID being upgraded to
361350
*/
362-
function upgradeNameSignal(
351+
function _upgradeNameSignal(
363352
address _graphAccount,
364353
uint256 _subgraphNumber,
365354
bytes32 _newSubgraphDeploymentID
@@ -453,25 +442,30 @@ contract GNS is Governed, BancorFormula {
453442
* @param _subgraphNumber Subgraph number
454443
* @param _subgraphDeploymentID Subgraph deployment ID of the deprecating subgraph
455444
*/
456-
function disableNameSignal(
445+
function _disableNameSignal(
457446
address _graphAccount,
458447
uint256 _subgraphNumber,
459448
bytes32 _subgraphDeploymentID
460449
) private {
461450
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
462451
uint256 vSignal = namePool.vSignal;
463452
namePool.vSignal = 0;
464-
(uint256 tokens, uint256 withdrawalFees) = curation.burn(_subgraphDeploymentID, vSignal);
465-
466-
// Get the owner of the Name to reimburse the withdrawal fee
467-
require(
468-
token.transferFrom(_graphAccount, address(this), withdrawalFees),
469-
"GNS: Error reimbursing withdrawal fees"
470-
);
453+
// If no nSignal, then no need to burn vSignal
454+
if (namePool.nSignal != 0) {
455+
(uint256 tokens, uint256 withdrawalFees) = curation.burn(
456+
_subgraphDeploymentID,
457+
vSignal
458+
);
471459

460+
// Get the owner of the Name to reimburse the withdrawal fee
461+
require(
462+
token.transferFrom(_graphAccount, address(this), withdrawalFees),
463+
"GNS: Error reimbursing withdrawal fees"
464+
);
465+
namePool.withdrawableGRT = tokens + withdrawalFees;
466+
}
472467
// Set the NameCurationPool fields to make it disabled
473468
namePool.disabled = true;
474-
namePool.withdrawableGRT = tokens + withdrawalFees;
475469
emit NameSignalDisabled(_graphAccount, _subgraphNumber, namePool.withdrawableGRT);
476470
}
477471

@@ -630,10 +624,6 @@ contract GNS is Governed, BancorFormula {
630624
uint256 _vSignal
631625
) public view returns (uint256) {
632626
NameCurationPool memory namePool = nameSignals[_graphAccount][_subgraphNumber];
633-
require(
634-
namePool.disabled == false,
635-
"GNS: Name cannot be disabled to call vSignalToNSignal()"
636-
);
637627
uint256 vSignal = _vSignal;
638628
uint256 nSignalInit = 0;
639629
uint32 reserveRatio = namePool.reserveRatio;

contracts/bancor/BancorFormula.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ contract BancorFormula {
233233
_reserveBalance > 0 &&
234234
_reserveRatio > 0 &&
235235
_reserveRatio <= MAX_RATIO &&
236-
_sellAmount <= _supply
236+
_sellAmount <= _supply,
237+
"invalid parameters"
237238
);
238239

239240
// special case for 0 sell amount

test/gns.test.ts

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('GNS', () => {
3535

3636
const tokens1000 = toGRT('1000')
3737
const tokens10000 = toGRT('10000')
38+
const tokens100000 = toGRT('100000')
3839
const withdrawalPercentage = 50000
3940
let subgraph0: Subgraph
4041
let subgraph1: Subgraph
@@ -69,21 +70,15 @@ describe('GNS', () => {
6970
account: Account,
7071
graphAccount: string,
7172
subgraphNumber: number,
72-
graphTokens: BigNumber,
7373
subgraphToPublish = subgraph0, // Defaults to subgraph created in before()
7474
): Promise<ContractTransaction> => {
75-
const signals = await gns.tokensToNSignal(graphAccount, subgraphNumber, graphTokens)
76-
const vSigEstimate = signals[0]
77-
const nSigEstimate = signals[1]
78-
7975
const tx = gns
8076
.connect(account.signer)
8177
.publishNewSubgraph(
8278
graphAccount,
8379
subgraphToPublish.subgraphDeploymentID,
8480
subgraphToPublish.versionMetadata,
8581
subgraphToPublish.subgraphMetadata,
86-
graphTokens,
8782
)
8883
await expect(tx)
8984
.emit(gns, 'SubgraphPublished')
@@ -102,17 +97,9 @@ describe('GNS', () => {
10297
subgraphToPublish.subgraphMetadata,
10398
)
10499

105-
const tokensVSig = await getTokensAndVSig(subgraph0.subgraphDeploymentID)
106-
const tokensAfter = tokensVSig[0]
107-
const vSigCuration = tokensVSig[1]
108-
expect(graphTokens).eq(tokensAfter)
109-
110100
const pool = await gns.nameSignals(graphAccount, subgraphNumber)
111-
const vSigPool = pool[0]
112-
const nSig = pool[1]
113-
expect(vSigCuration).eq(vSigPool).eq(vSigEstimate)
114-
expect(nSigEstimate).eq(nSig)
115-
101+
const reserveRatio = pool[3]
102+
expect(reserveRatio).eq(1000000)
116103
return tx
117104
}
118105
const publishNewVersion = async (
@@ -332,7 +319,7 @@ describe('GNS', () => {
332319
const tx = gns.connect(account.signer).mintNSignal(graphAccount, subgraphNumber0, graphTokens)
333320
await expect(tx)
334321
.emit(gns, 'NSignalMinted')
335-
.withArgs(graphAccount, subgraphNumber0, other.address, nSigEstimate, vSigEstimate)
322+
.withArgs(graphAccount, subgraphNumber0, account.address, nSigEstimate, vSigEstimate)
336323

337324
const tokensVSig = await getTokensAndVSig(subgraph0.subgraphDeploymentID)
338325
const tokensAfter = tokensVSig[0]
@@ -462,12 +449,12 @@ describe('GNS', () => {
462449
subgraph1 = createSubgraph(me, '1')
463450
defaultName = createDefaultName('graph')
464451
// Give some funds to the signers and approve gns contract to use funds on signers behalf
465-
await grt.connect(governor.signer).mint(me.address, tokens10000)
466-
await grt.connect(governor.signer).mint(other.address, tokens10000)
467-
await grt.connect(me.signer).approve(gns.address, tokens10000)
468-
await grt.connect(me.signer).approve(curation.address, tokens10000)
469-
await grt.connect(other.signer).approve(gns.address, tokens10000)
470-
await grt.connect(other.signer).approve(curation.address, tokens10000)
452+
await grt.connect(governor.signer).mint(me.address, tokens100000)
453+
await grt.connect(governor.signer).mint(other.address, tokens100000)
454+
await grt.connect(me.signer).approve(gns.address, tokens100000)
455+
await grt.connect(me.signer).approve(curation.address, tokens100000)
456+
await grt.connect(other.signer).approve(gns.address, tokens100000)
457+
await grt.connect(other.signer).approve(curation.address, tokens100000)
471458

472459
// Update withdrawal fee to test the functionality of it in disableNameSignal()
473460
await curation.connect(governor.signer).setWithdrawalFeePercentage(withdrawalPercentage)
@@ -517,22 +504,22 @@ describe('GNS', () => {
517504
describe('isPublished', function () {
518505
it('should return if the subgraph is published', async function () {
519506
expect(await gns.isPublished(subgraph0.graphAccount.address, 0)).eq(false)
520-
await publishNewSubgraph(me, me.address, 0, tokens1000)
507+
await publishNewSubgraph(me, me.address, 0)
521508
expect(await gns.isPublished(subgraph0.graphAccount.address, 0)).eq(true)
522509
})
523510
})
524511

525512
describe('publishNewSubgraph', async function () {
526513
it('should publish a new subgraph and first version with it', async function () {
527-
await publishNewSubgraph(me, me.address, 0, tokens1000)
514+
await publishNewSubgraph(me, me.address, 0)
528515
// State updated
529516
const deploymentID = await gns.subgraphs(subgraph0.graphAccount.address, 0)
530517
expect(subgraph0.subgraphDeploymentID).eq(deploymentID)
531518
})
532519

533520
it('should publish a new subgraph with an incremented value', async function () {
534-
await publishNewSubgraph(me, me.address, 0, tokens1000)
535-
await publishNewSubgraph(me, me.address, 1, tokens1000, subgraph1)
521+
await publishNewSubgraph(me, me.address, 0)
522+
await publishNewSubgraph(me, me.address, 1, subgraph1)
536523
const deploymentID = await gns.subgraphs(subgraph1.graphAccount.address, 1)
537524
expect(subgraph1.subgraphDeploymentID).eq(deploymentID)
538525
})
@@ -545,7 +532,6 @@ describe('GNS', () => {
545532
ethers.constants.HashZero,
546533
subgraph0.versionMetadata,
547534
subgraph0.subgraphMetadata,
548-
tokens1000,
549535
)
550536
await expect(tx).revertedWith('GNS: Only graph account owner can call')
551537
})
@@ -558,15 +544,15 @@ describe('GNS', () => {
558544
ethers.constants.HashZero,
559545
subgraph0.versionMetadata,
560546
subgraph0.subgraphMetadata,
561-
tokens1000,
562547
)
563548
await expect(tx).revertedWith('GNS: Cannot set deploymentID to 0 in publish')
564549
})
565550
})
566551

567552
describe('publishNewVersion', async function () {
568553
beforeEach(async () => {
569-
await publishNewSubgraph(me, me.address, 0, tokens1000)
554+
await publishNewSubgraph(me, me.address, 0)
555+
await mintNSignal(me, me.address, 0, tokens10000)
570556
})
571557
it('should publish a new version on an existing subgraph', async function () {
572558
await publishNewVersion(me, me.address, 0, subgraph1)
@@ -655,7 +641,8 @@ describe('GNS', () => {
655641

656642
describe('deprecateSubgraph', async function () {
657643
beforeEach(async () => {
658-
await publishNewSubgraph(me, me.address, 0, tokens1000)
644+
await publishNewSubgraph(me, me.address, 0)
645+
await mintNSignal(me, me.address, 0, tokens10000)
659646
})
660647
it('should deprecate a subgraph', async function () {
661648
await deprecateSubgraph(me, me.address, 0)
@@ -693,11 +680,11 @@ describe('GNS', () => {
693680
const subgraphNumber0 = 0
694681
describe('mintNSignal()', async function () {
695682
it('should deposit into the name signal curve', async function () {
696-
await publishNewSubgraph(me, me.address, subgraphNumber0, tokens1000)
683+
await publishNewSubgraph(me, me.address, subgraphNumber0)
697684
await mintNSignal(other, me.address, subgraphNumber0, tokens10000)
698685
})
699686
it('should fail when name signal is disabled', async function () {
700-
await publishNewSubgraph(me, me.address, subgraphNumber0, tokens1000)
687+
await publishNewSubgraph(me, me.address, subgraphNumber0)
701688
await deprecateSubgraph(me, me.address, 0)
702689
const tx = gns.connect(me.signer).mintNSignal(me.address, subgraphNumber0, tokens1000)
703690
await expect(tx).revertedWith('GNS: Cannot be disabled')
@@ -709,7 +696,7 @@ describe('GNS', () => {
709696
})
710697
describe('burnNSignal()', async function () {
711698
beforeEach(async () => {
712-
await publishNewSubgraph(me, me.address, subgraphNumber0, tokens1000)
699+
await publishNewSubgraph(me, me.address, subgraphNumber0)
713700
await mintNSignal(other, me.address, subgraphNumber0, tokens10000)
714701
})
715702
it('should withdraw from the name signal curve', async function () {
@@ -733,7 +720,7 @@ describe('GNS', () => {
733720
})
734721
describe('withdraw()', async function () {
735722
beforeEach(async () => {
736-
await publishNewSubgraph(me, me.address, subgraphNumber0, tokens1000)
723+
await publishNewSubgraph(me, me.address, subgraphNumber0)
737724
await mintNSignal(other, me.address, subgraphNumber0, tokens10000)
738725
})
739726
it('should withdraw GRT from a disabled name signal', async function () {
@@ -747,13 +734,11 @@ describe('GNS', () => {
747734
it('should fail when there is no more GRT to withdraw', async function () {
748735
await deprecateSubgraph(me, me.address, 0)
749736
await withdraw(other, me.address, subgraphNumber0)
750-
await withdraw(me, me.address, subgraphNumber0)
751737
const tx = gns.connect(other.signer).withdraw(me.address, subgraphNumber0)
752738
await expect(tx).revertedWith('GNS: No more GRT to withdraw')
753739
})
754740
it('should fail if the curator has no nSignal', async function () {
755741
await deprecateSubgraph(me, me.address, 0)
756-
await withdraw(me, me.address, subgraphNumber0)
757742
const tx = gns.connect(me.signer).withdraw(me.address, subgraphNumber0)
758743
await expect(tx).revertedWith('GNS: Curator must have some nSignal to withdraw GRT')
759744
})

0 commit comments

Comments
 (0)