Skip to content

Commit f2eb6cd

Browse files
authored
Merge pull request #46 from AugurProject/stop-accumulating-fees-after-fork
stop accumulating fees on parent after fork
2 parents 33b22fa + 16822e0 commit f2eb6cd

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

solidity/contracts/peripherals/SecurityPool.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,20 @@ contract SecurityPool is ISecurityPool {
101101

102102
function updateCollateralAmount() public {
103103
if (securityBondAllowance == 0) return;
104+
uint256 forkTime;
105+
(,,forkTime) = zoltar.universes(universeId);
104106
(uint64 endTime,,,) = zoltar.questions(questionId);
105-
uint256 clampedCurrentTimestamp = block.timestamp > endTime ? endTime : block.timestamp;
106-
uint256 clampedLastUpdatedFeeAccumulator = lastUpdatedFeeAccumulator > endTime ? endTime : lastUpdatedFeeAccumulator;
107-
uint256 timeDelta = clampedCurrentTimestamp - clampedLastUpdatedFeeAccumulator;
107+
uint256 feeEndDate = forkTime == 0 ? endTime : forkTime;
108+
uint256 clampedCurrentTimestamp = block.timestamp > feeEndDate ? feeEndDate : block.timestamp;
109+
uint256 timeDelta = clampedCurrentTimestamp - lastUpdatedFeeAccumulator;
108110
if (timeDelta == 0) return;
109111

110112
uint256 newCompleteSetCollateralAmount = completeSetCollateralAmount * SecurityPoolUtils.rpow(currentRetentionRate, timeDelta, SecurityPoolUtils.PRICE_PRECISION) / SecurityPoolUtils.PRICE_PRECISION;
111113
uint256 delta = completeSetCollateralAmount - newCompleteSetCollateralAmount;
112114
totalFeesOvedToVaults += delta;
113115
feeIndex += delta * SecurityPoolUtils.PRICE_PRECISION / securityBondAllowance;
114116
completeSetCollateralAmount = newCompleteSetCollateralAmount;
115-
lastUpdatedFeeAccumulator = block.timestamp;
117+
lastUpdatedFeeAccumulator = feeEndDate < block.timestamp ? feeEndDate : block.timestamp;
116118

117119
emit UpdateCollateralAmount(totalFeesOvedToVaults, completeSetCollateralAmount);
118120
}

solidity/ts/tests/testPeripherals.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('Peripherals Contract Test Suite', () => {
104104
assert.strictEqual(liquidatorVault.repDepositShare / PRICE_PRECISION, repDeposit+(repDeposit * 10n), 'liquidator should have all the rep in the pool')
105105
})
106106

107-
test('Open Interest Fees', async () => {
107+
test('Open Interest Fees (non forking)', async () => {
108108
const questionData = await getQuestionData(client, questionId)
109109
assert.strictEqual(questionData.endTime > dateToBigintSeconds(new Date), true, 'market has already ended')
110110
const securityPoolAllowance = repDeposit / 4n
@@ -169,12 +169,13 @@ describe('Peripherals Contract Test Suite', () => {
169169
assert.strictEqual(newCompleteSetBalances[1], 0n, 'Did not lose complete sets')
170170
assert.strictEqual(newCompleteSetBalances[2], 0n, 'Did not lose complete sets')
171171
assert.strictEqual(await getCurrentRetentionRate(client, securityPoolAddresses.securityPool), MAX_RETENTION_RATE, 'retention rate was not at max after zero complete sets');
172-
173172
// forking
174173
await createCompleteSet(client, securityPoolAddresses.securityPool, openInterestAmount)
175174
const repBalance = await getERC20Balance(client, getRepTokenAddress(genesisUniverse), securityPoolAddresses.securityPool)
175+
176176
await triggerFork(client, mockWindow, questionId)
177177
await forkSecurityPool(client, securityPoolAddresses.securityPool)
178+
const totalFeesOvedToVaultsRightAfterFork = await getTotalFeesOvedToVaults(client, securityPoolAddresses.securityPool)
178179
assert.strictEqual(await getSystemState(client, securityPoolAddresses.securityPool), SystemState.PoolForked, 'Parent is forked')
179180
assert.strictEqual(0n, await getERC20Balance(client, getRepTokenAddress(genesisUniverse), securityPoolAddresses.securityPool), 'Parents original rep is gone')
180181
await migrateVault(client, securityPoolAddresses.securityPool, QuestionOutcome.Yes)
@@ -189,6 +190,9 @@ describe('Peripherals Contract Test Suite', () => {
189190
await startTruthAuction(client, yesSecurityPool.securityPool)
190191
assert.strictEqual(await getSystemState(client, yesSecurityPool.securityPool), SystemState.Operational, 'yes System should be operational right away')
191192
assert.strictEqual(await getCompleteSetCollateralAmount(client, yesSecurityPool.securityPool), openInterestAmount, 'child contract did not record the amount correctly')
193+
194+
const totalFeesOvedToVaultsAfterFork = await getTotalFeesOvedToVaults(client, securityPoolAddresses.securityPool)
195+
assert.strictEqual(totalFeesOvedToVaultsRightAfterFork, totalFeesOvedToVaultsAfterFork, 'parents fees should be frozen')
192196
})
193197

194198
test('two security pools with disagreement', async () => {
@@ -367,4 +371,6 @@ describe('Peripherals Contract Test Suite', () => {
367371
assert.strictEqual(await getSystemState(client, yesSecurityPool.securityPool), SystemState.Operational, 'yes System should be operational right away')
368372
assert.strictEqual(await getCompleteSetCollateralAmount(client, yesSecurityPool.securityPool), 0n, 'child contract did not record the amount correctly')
369373
})
374+
375+
// - todo test that users can claim their stuff (shares+rep) even if zoltar forks after market ends
370376
})

0 commit comments

Comments
 (0)