Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
handle case
Browse files Browse the repository at this point in the history
  • Loading branch information
felix2feng committed May 18, 2020
1 parent 5b76ab8 commit 30c8297
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
8 changes: 6 additions & 2 deletions contracts/core/fee-calculators/PerformanceFeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,13 @@ contract PerformanceFeeCalculator is IFeeCalculator {
// Thus, we need to reset the high water mark here so that users do not pay for profit fees
// since inception.
uint256 rebalancingSetValue = SetUSDValuation.calculateRebalancingSetValue(msg.sender, oracleWhiteList);
uint256 existingHighwatermark = feeState[msg.sender].highWatermark;

if (rebalancingSetValue > existingHighwatermark) {
feeState[msg.sender].lastProfitFeeTimestamp = block.timestamp;
feeState[msg.sender].highWatermark = rebalancingSetValue;
}

feeState[msg.sender].lastProfitFeeTimestamp = block.timestamp;
feeState[msg.sender].highWatermark = rebalancingSetValue;
feeState[msg.sender].profitFeePercentage = feePercentage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ contract('PerformanceFeeCalculator', accounts => {
});

describe('when the profit fee is initially 0 and a profit is marked', async () => {
const updatedBTCPrice = ether(8000);
const updatedETHPrice = ether(140);
let updatedBTCPrice: BigNumber;
let updatedETHPrice: BigNumber;

before(async () => {
customInitialFeePercentage = ether(0);
Expand All @@ -595,26 +595,60 @@ contract('PerformanceFeeCalculator', accounts => {
await blockchain.mineBlockAsync();
});

it('properly resets the watermark', async () => {
await subject();
describe('and there is a profit', async () => {
before(async () => {
updatedBTCPrice = ether(8000);
updatedETHPrice = ether(140);
});

const rebalancingSetValue = await valuationHelper.calculateRebalancingSetTokenValueAsync(
rebalancingSetToken,
usdOracleWhiteList,
);
after(async () => {
updatedBTCPrice = undefined;
updatedETHPrice = undefined;
});

it('properly resets the watermark', async () => {
await subject();

const rebalancingSetValue = await valuationHelper.calculateRebalancingSetTokenValueAsync(
rebalancingSetToken,
usdOracleWhiteList,
);

const postFeeState: any = await feeCalculator.feeState.callAsync(rebalancingSetToken.address);

expect(postFeeState.highWatermark).to.bignumber.equal(rebalancingSetValue);
});

const postFeeState: any = await feeCalculator.feeState.callAsync(rebalancingSetToken.address);
it('sets the last profit fee timestamp correctly', async () => {
await subject();

expect(postFeeState.highWatermark).to.bignumber.equal(rebalancingSetValue);
const lastBlock = await web3.eth.getBlock('latest');

const feeState: any = await feeCalculator.feeState.callAsync(rebalancingSetToken.address);
expect(feeState.lastProfitFeeTimestamp).to.be.bignumber.equal(lastBlock.timestamp);
});
});

it('sets the last profit fee timestamp correctly', async () => {
await subject();
describe('when there is no profit', async () => {
before(async () => {
updatedBTCPrice = ether(7000);
updatedETHPrice = ether(100);
});

after(async () => {
updatedBTCPrice = undefined;
updatedETHPrice = undefined;
});

it('does not reset the watermark', async () => {
const preFeeState: any = await feeCalculator.feeState.callAsync(rebalancingSetToken.address);

await subject();

const lastBlock = await web3.eth.getBlock('latest');
const postFeeState: any = await feeCalculator.feeState.callAsync(rebalancingSetToken.address);

const feeState: any = await feeCalculator.feeState.callAsync(rebalancingSetToken.address);
expect(feeState.lastProfitFeeTimestamp).to.be.bignumber.equal(lastBlock.timestamp);
expect(postFeeState.highWatermark).to.bignumber.equal(preFeeState.highWatermark);
});
});
});

Expand Down

0 comments on commit 30c8297

Please sign in to comment.