Skip to content

Commit

Permalink
fix: don't include new apy in gross apy (#281)
Browse files Browse the repository at this point in the history
* don't include new apy in gross apy

* return early if the apy is new

Co-authored-by: Karelian Pie <[email protected]>

* add tests from @karelianpie

* fix missing bracket

Co-authored-by: Karelian Pie <[email protected]>
  • Loading branch information
patcito and karelianpie authored Apr 17, 2022
1 parent 00e49c3 commit e399055
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/interfaces/earnings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,25 @@ describe("EarningsInterface", () => {
});

describe("when there is an account", () => {
const accountAddress: Address = "0x001";
const apyMock = createMockApy({
net_apy: 42,
});
const accountEarningsResponse = createMockAccountEarningsResponse();
const tokensValueInUsdcMock: jest.Mock<Promise<BigNumber>> = jest.fn();

beforeEach(() => {
subgraphFetchQueryMock.mockResolvedValue(accountEarningsResponse);
visionApyMock.mockResolvedValue({
[accountAddress]: apyMock,
});
getAddressMock.mockReturnValue(accountAddress);
(earningsInterface as any).tokensValueInUsdc = tokensValueInUsdcMock;
tokensValueInUsdcMock.mockResolvedValue(new BigNumber(10));
getAddressMock.mockReturnValue("0x001");
});

it("should return an empty EarningsUserData", async () => {
const accountAddress: Address = "0x001";
visionApyMock.mockResolvedValue({
[accountAddress]: createMockApy({
net_apy: 42,
}),
});
getAddressMock.mockReturnValue(accountAddress);

const actual = await earningsInterface.accountAssetsData(accountAddress);

expect(visionApyMock).toHaveBeenCalledTimes(1);
Expand All @@ -221,6 +222,25 @@ describe("EarningsInterface", () => {
holdings: "10",
});
});

it("should filter out new vaults for the estimated yield calculation", async () => {
const accountAddress: Address = "0x001";
visionApyMock.mockResolvedValue({
[accountAddress]: createMockApy({
net_apy: 42,
type: "new",
}),
});

const actual = await earningsInterface.accountAssetsData(accountAddress);

expect(visionApyMock).toHaveBeenCalledTimes(1);
expect(visionApyMock).toHaveBeenCalledWith([accountAddress]);
expect(getAddressMock).toHaveBeenCalledTimes(1);
expect(actual).toMatchObject({
estimatedYearlyYield: "0",
});
});
});
});

Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/earnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ export class EarningsInterface<C extends ChainId> extends ServiceInterface<C> {
? BigZero
: assetsData
.map((datum) => {
if (apys[datum.assetAddress]?.type === "new") {
return BigZero;
}
const apy = apys[datum.assetAddress]?.net_apy || 0;
return new BigNumber(apy).times(datum.balanceUsdc).div(holdings);
})
Expand Down

0 comments on commit e399055

Please sign in to comment.