Skip to content

Commit 80d5bbd

Browse files
committed
Fix owner tax percentage so it adds slightly more. Previous fix did not work
1 parent f32ad12 commit 80d5bbd

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

contracts/discovery/GNS.sol

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
371371

372372
// Take the owner cut of the curation tax, add it to the total
373373
uint32 curationTaxPercentage = curation.getCurationTaxPercentage();
374-
375374
uint256 tokensWithTax = _chargeOwnerTax(tokens, _graphAccount, curationTaxPercentage);
376375

377376
// Update pool: constant nSignal, vSignal can change
@@ -547,21 +546,32 @@ contract GNS is GNSV1Storage, GraphUpgradeable, IGNS {
547546
return 0;
548547
}
549548

550-
// calculate tax on current tokens
551-
uint256 topUpTax = _tokens.mul(_curationTaxPercentage).div(MAX_PPM);
552-
// take full tax, and multiply it by owner percentage to
553-
// find the amount owner needs to add
554-
uint256 ownerTax = topUpTax.mul(ownerTaxPercentage).div(MAX_PPM);
549+
// Tax on the total bonding curve funds
550+
uint256 taxOnOriginal = _tokens.mul(_curationTaxPercentage).div(MAX_PPM);
551+
// Total after the tax
552+
uint256 totalWithoutOwnerTax = _tokens.sub(taxOnOriginal);
553+
// The portion of tax that the owner will pay
554+
uint256 ownerTax = taxOnOriginal.mul(ownerTaxPercentage).div(MAX_PPM);
555+
556+
uint256 totalWithOwnerTax = totalWithoutOwnerTax.add(ownerTax);
557+
558+
// The total after tax, plus owner partial repay, divided by
559+
// the tax, to adjust it slightly upwards. ex:
560+
// 100 GRT, 5 GRT Tax, owner pays 100% --> 5 GRT
561+
// To get 100 in the protocol after tax, Owner deposits
562+
// ~5.26, as ~105.26 * .95 = 100
563+
uint256 totalAdjustedUp = totalWithOwnerTax.mul(MAX_PPM).div(
564+
uint256(MAX_PPM).sub(uint256(_curationTaxPercentage))
565+
);
566+
567+
uint256 ownerTaxAdjustedUp = totalAdjustedUp.sub(_tokens);
555568

556569
// Get the owner of the subgraph to reimburse the curation tax
557570
require(
558-
graphToken().transferFrom(_owner, address(this), ownerTax),
571+
graphToken().transferFrom(_owner, address(this), ownerTaxAdjustedUp),
559572
"GNS: Error reimbursing curation tax"
560573
);
561-
562-
// new amount is the total tokens before plus the owner tax
563-
uint256 totalSentToCuration = _tokens.add(ownerTax);
564-
return totalSentToCuration;
574+
return totalAdjustedUp;
565575
}
566576

567577
/**

test/gns.test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ describe('GNS', () => {
173173
const namePoolBefore = await gns.nameSignals(graphAccount, subgraphNumber)
174174

175175
// Check what selling all nSignal, which == selling all vSignal, should return for tokens
176+
// NOTE - no tax on burning on nSignal
176177
const { 1: tokensReceivedEstimate } = await gns.nSignalToTokens(
177178
graphAccount,
178179
subgraphNumber,
@@ -182,24 +183,34 @@ describe('GNS', () => {
182183
// Deposit 100, 5 is taxed, 95 GRT in curve
183184
// Upgrade - calculate 5% tax on 95 --> 4.75 GRT
184185
// Multiple by ownerPercentage --> 50% * 4.75 = 2.375 GRT
185-
// Owner adds 2.375 to the amount, we deposit 97.375 GRT into the curve
186-
// In the end there will be 92.5 GRT left after the taxation of
187-
// the upgrade
186+
// Owner adds 2.375 to 90.25, we deposit 92.625 GRT into the curve
187+
// Divide this by 0.95 to get exactly 97.5 total tokens to be deposited
188188

189189
// nSignalToTokens returns the amount of tokens with tax removed
190190
// already. So we must add in the tokens removed
191191
const MAX_PPM = 1000000
192-
const ownerFullTax = tokensReceivedEstimate.mul(curationTaxPercentage).div(MAX_PPM)
192+
const taxOnOriginal = tokensReceivedEstimate.mul(curationTaxPercentage).div(MAX_PPM)
193+
const totalWithoutOwnerTax = tokensReceivedEstimate.sub(taxOnOriginal)
194+
const ownerTax = taxOnOriginal.mul(ownerTaxPercentage).div(MAX_PPM)
193195

194-
const ownerTax = ownerFullTax.mul(ownerTaxPercentage).div(MAX_PPM)
195-
const upgradeTokenReturn = tokensReceivedEstimate.add(ownerTax)
196+
const totalWithOwnerTax = totalWithoutOwnerTax.add(ownerTax)
197+
198+
const totalAdjustedUp = totalWithOwnerTax.mul(MAX_PPM).div(MAX_PPM - curationTaxPercentage)
196199

197200
// Re-estimate amount of signal to get considering the owner tax paid by the owner
198201
const { 0: newVSignalEstimate, 1: newCurationTaxEstimate } = await curation.tokensToSignal(
199202
subgraphToPublish.subgraphDeploymentID,
200-
upgradeTokenReturn,
203+
totalAdjustedUp,
201204
)
202205

206+
console.log('taxOnOriginal: ', taxOnOriginal.toString())
207+
console.log('totalWithoutOwnerTax: ', totalWithoutOwnerTax.toString())
208+
console.log('ownerTax: ', ownerTax.toString())
209+
console.log('totalWithOwnerTax: ', totalWithOwnerTax.toString())
210+
console.log('total adj up: ', totalAdjustedUp.toString())
211+
212+
console.log('total adj up: ', totalAdjustedUp.toString())
213+
203214
const tx = gns
204215
.connect(account.signer)
205216
.publishNewVersion(
@@ -221,7 +232,7 @@ describe('GNS', () => {
221232
graphAccount,
222233
subgraphNumber,
223234
newVSignalEstimate,
224-
upgradeTokenReturn,
235+
totalAdjustedUp,
225236
subgraphToPublish.subgraphDeploymentID,
226237
)
227238

@@ -236,7 +247,7 @@ describe('GNS', () => {
236247
const [tokensAfterNewCurve, vSignalAfterNewCurve] = await getTokensAndVSignal(
237248
subgraphToPublish.subgraphDeploymentID,
238249
)
239-
expect(tokensAfterNewCurve).eq(upgradeTokenReturn.sub(newCurationTaxEstimate))
250+
expect(tokensAfterNewCurve).eq(totalAdjustedUp.sub(newCurationTaxEstimate))
240251
expect(vSignalAfterNewCurve).eq(newVSignalEstimate)
241252

242253
// Check the nSignal pool

0 commit comments

Comments
 (0)