Skip to content

Commit

Permalink
Forfeit protocol fees on recovery mode disable (#1687)
Browse files Browse the repository at this point in the history
* Pay protocol fees on cache update

* Fix typo

* Add docs

* Add proto cache hook tests

* Add pause behavior and tests

* Fix tests

* Forfeit protocol fees on recovery mode disable

* Update pkg/pool-stable/contracts/ComposableStablePool.sol

Co-authored-by: EndymionJkb <[email protected]>

* Update pkg/pool-stable/test/ComposableStablePool.test.ts

Co-authored-by: EndymionJkb <[email protected]>

Co-authored-by: EndymionJkb <[email protected]>
  • Loading branch information
2 people authored and TomAFrench committed Nov 24, 2022
1 parent 77b4b10 commit ce7b9fc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/pool-stable/test/ComposableStablePool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,43 @@ describe('ComposableStablePool', () => {
});
});

it('rate increases when enabling recovery mode', async () => {
const initialRate = await pool.getRate();

// When enabling recovery mode, protocol fees are forfeit and the percentages drop to zero. This causes
// an increase in the rate, since the BPT's value increases (as it no longer carries any protocol debt).
await pool.enableRecoveryMode(admin);
const newRate = await pool.getRate();

expect(newRate).to.be.gt(initialRate);

// We can compute the new rate by computing the ratio of invariant and total supply, not considering any
// due protocol fees (because there should be none).
const scaledBalances = arrayFpMul(await pool.getBalances(), await pool.getScalingFactors()).filter(
(_, i) => i != bptIndex
);
const invariant = calculateInvariant(
scaledBalances,
(await pool.getAmplificationParameter()).value.div(AMP_PRECISION)
);

const virtualSupply = await pool.getVirtualSupply();

const rateAssumingNoProtocolFees = invariant.mul(FP_SCALING_FACTOR).div(virtualSupply);

expect(newRate).to.be.almostEqual(rateAssumingNoProtocolFees, 1e-6);
});

it('rate does not change when disabling recovery mode', async () => {
await pool.enableRecoveryMode(admin);

await expectNoRateChange(async () => {
// Disabling recovery mode should cause no rate changes - fees have already been forfeit when recovery
// mode was enabled.
await pool.disableRecoveryMode(admin);
});
});

function itReactsToProtocolFeePercentageChangesCorrectly(feeType: number) {
it('rate does not change on protocol fee update', async () => {
await expectNoRateChange(async () => {
Expand Down

0 comments on commit ce7b9fc

Please sign in to comment.