Skip to content

Commit

Permalink
Clean up test with proper fee computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarid27 committed Oct 24, 2024
1 parent fde5ad7 commit 45d1c6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/EventHandlers/CLPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,33 @@ function updateCLPoolFees(
token0Instance: Token | undefined,
token1Instance: Token | undefined
) {

let tokenUpdateData = {
totalFees0: clPoolAggregator.totalFees0,
totalFees1: clPoolAggregator.totalFees1,
totalFeesUSD: clPoolAggregator.totalFeesUSD,
};

if (token0Instance) {
tokenUpdateData.totalFees0 += normalizeTokenAmountTo1e18(
const incomingFees0 = normalizeTokenAmountTo1e18(
event.params.amount0,
Number(token0Instance.decimals)
);
tokenUpdateData.totalFees0 += incomingFees0;
tokenUpdateData.totalFeesUSD += multiplyBase1e18(
tokenUpdateData.totalFees0,
incomingFees0,
token0Instance.pricePerUSDNew
);
}

if (token1Instance) {
tokenUpdateData.totalFees1 += normalizeTokenAmountTo1e18(
const incomingFees1 = normalizeTokenAmountTo1e18(
event.params.amount1,
Number(token1Instance.decimals)
);
tokenUpdateData.totalFees1 += incomingFees1;
tokenUpdateData.totalFeesUSD += multiplyBase1e18(
tokenUpdateData.totalFees1,
incomingFees1,
token1Instance.pricePerUSDNew
);
}
Expand Down
5 changes: 5 additions & 0 deletions test/EventHandlers/CLPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ describe("CLPool Event Handlers", () => {
eventFees.amount1 * (10n ** 18n) / 10n ** 6n
)
, "It should normalize fees here");
expect(diff.totalFeesUSD).to.equal(
mockCLPoolAggregator.totalFeesUSD +
(eventFees.amount0 * mockToken0.pricePerUSDNew / 10n ** 18n) +
( (eventFees.amount1 / 10n ** 6n) * mockToken1.pricePerUSDNew)
, "It should correctly update total fees in USD");
});
});
});
Expand Down

0 comments on commit 45d1c6e

Please sign in to comment.