From e39905577aa149c7bc404fda17889e3610db59e4 Mon Sep 17 00:00:00 2001 From: Patrick Aljord Date: Sun, 17 Apr 2022 12:43:46 +0400 Subject: [PATCH] fix: don't include new apy in gross apy (#281) * don't include new apy in gross apy * return early if the apy is new Co-authored-by: Karelian Pie <78794805+karelianpie@users.noreply.github.com> * add tests from @karelianpie * fix missing bracket Co-authored-by: Karelian Pie <78794805+karelianpie@users.noreply.github.com> --- src/interfaces/earnings.spec.ts | 36 +++++++++++++++++++++++++-------- src/interfaces/earnings.ts | 3 +++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/interfaces/earnings.spec.ts b/src/interfaces/earnings.spec.ts index 2e1f4d00..0e8285cb 100644 --- a/src/interfaces/earnings.spec.ts +++ b/src/interfaces/earnings.spec.ts @@ -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> = 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); @@ -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", + }); + }); }); }); diff --git a/src/interfaces/earnings.ts b/src/interfaces/earnings.ts index 1ee876c9..846e9bb8 100644 --- a/src/interfaces/earnings.ts +++ b/src/interfaces/earnings.ts @@ -156,6 +156,9 @@ export class EarningsInterface extends ServiceInterface { ? 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); })