Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions solidity/contracts/peripherals/SecurityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,20 @@ contract SecurityPool is ISecurityPool {

function updateCollateralAmount() public {
if (securityBondAllowance == 0) return;
uint256 forkTime;
(,,forkTime) = zoltar.universes(universeId);
(uint64 endTime,,,) = zoltar.questions(questionId);
uint256 clampedCurrentTimestamp = block.timestamp > endTime ? endTime : block.timestamp;
uint256 clampedLastUpdatedFeeAccumulator = lastUpdatedFeeAccumulator > endTime ? endTime : lastUpdatedFeeAccumulator;
uint256 timeDelta = clampedCurrentTimestamp - clampedLastUpdatedFeeAccumulator;
uint256 feeEndDate = forkTime == 0 ? endTime : forkTime;
uint256 clampedCurrentTimestamp = block.timestamp > feeEndDate ? feeEndDate : block.timestamp;
uint256 timeDelta = clampedCurrentTimestamp - lastUpdatedFeeAccumulator;
if (timeDelta == 0) return;

uint256 newCompleteSetCollateralAmount = completeSetCollateralAmount * SecurityPoolUtils.rpow(currentRetentionRate, timeDelta, SecurityPoolUtils.PRICE_PRECISION) / SecurityPoolUtils.PRICE_PRECISION;
uint256 delta = completeSetCollateralAmount - newCompleteSetCollateralAmount;
totalFeesOvedToVaults += delta;
feeIndex += delta * SecurityPoolUtils.PRICE_PRECISION / securityBondAllowance;
completeSetCollateralAmount = newCompleteSetCollateralAmount;
lastUpdatedFeeAccumulator = block.timestamp;
lastUpdatedFeeAccumulator = feeEndDate < block.timestamp ? feeEndDate : block.timestamp;

emit UpdateCollateralAmount(totalFeesOvedToVaults, completeSetCollateralAmount);
}
Expand Down
10 changes: 8 additions & 2 deletions solidity/ts/tests/testPeripherals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Peripherals Contract Test Suite', () => {
assert.strictEqual(liquidatorVault.repDepositShare / PRICE_PRECISION, repDeposit+(repDeposit * 10n), 'liquidator should have all the rep in the pool')
})

test('Open Interest Fees', async () => {
test('Open Interest Fees (non forking)', async () => {
const questionData = await getQuestionData(client, questionId)
assert.strictEqual(questionData.endTime > dateToBigintSeconds(new Date), true, 'market has already ended')
const securityPoolAllowance = repDeposit / 4n
Expand Down Expand Up @@ -169,12 +169,13 @@ describe('Peripherals Contract Test Suite', () => {
assert.strictEqual(newCompleteSetBalances[1], 0n, 'Did not lose complete sets')
assert.strictEqual(newCompleteSetBalances[2], 0n, 'Did not lose complete sets')
assert.strictEqual(await getCurrentRetentionRate(client, securityPoolAddresses.securityPool), MAX_RETENTION_RATE, 'retention rate was not at max after zero complete sets');

// forking
await createCompleteSet(client, securityPoolAddresses.securityPool, openInterestAmount)
const repBalance = await getERC20Balance(client, getRepTokenAddress(genesisUniverse), securityPoolAddresses.securityPool)

await triggerFork(client, mockWindow, questionId)
await forkSecurityPool(client, securityPoolAddresses.securityPool)
const totalFeesOvedToVaultsRightAfterFork = await getTotalFeesOvedToVaults(client, securityPoolAddresses.securityPool)
assert.strictEqual(await getSystemState(client, securityPoolAddresses.securityPool), SystemState.PoolForked, 'Parent is forked')
assert.strictEqual(0n, await getERC20Balance(client, getRepTokenAddress(genesisUniverse), securityPoolAddresses.securityPool), 'Parents original rep is gone')
await migrateVault(client, securityPoolAddresses.securityPool, QuestionOutcome.Yes)
Expand All @@ -189,6 +190,9 @@ describe('Peripherals Contract Test Suite', () => {
await startTruthAuction(client, yesSecurityPool.securityPool)
assert.strictEqual(await getSystemState(client, yesSecurityPool.securityPool), SystemState.Operational, 'yes System should be operational right away')
assert.strictEqual(await getCompleteSetCollateralAmount(client, yesSecurityPool.securityPool), openInterestAmount, 'child contract did not record the amount correctly')

const totalFeesOvedToVaultsAfterFork = await getTotalFeesOvedToVaults(client, securityPoolAddresses.securityPool)
assert.strictEqual(totalFeesOvedToVaultsRightAfterFork, totalFeesOvedToVaultsAfterFork, 'parents fees should be frozen')
})

test('two security pools with disagreement', async () => {
Expand Down Expand Up @@ -367,4 +371,6 @@ describe('Peripherals Contract Test Suite', () => {
assert.strictEqual(await getSystemState(client, yesSecurityPool.securityPool), SystemState.Operational, 'yes System should be operational right away')
assert.strictEqual(await getCompleteSetCollateralAmount(client, yesSecurityPool.securityPool), 0n, 'child contract did not record the amount correctly')
})

// - todo test that users can claim their stuff (shares+rep) even if zoltar forks after market ends
})