diff --git a/src/interfaces/strategy.spec.ts b/src/interfaces/strategy.spec.ts index 638a3cfb..80036e51 100644 --- a/src/interfaces/strategy.spec.ts +++ b/src/interfaces/strategy.spec.ts @@ -130,6 +130,6 @@ describe("StrategyInterface", () => { const result = await strategyInterface.getHarvests({ strategyAddress: "" }); expect(result[0].apr).toEqual(260.89285714285717); - expect(result[1].apr).toEqual(0); + expect(result[1].apr).toBeUndefined(); }); }); diff --git a/src/interfaces/strategy.ts b/src/interfaces/strategy.ts index 6a4c1c14..1c9292f1 100644 --- a/src/interfaces/strategy.ts +++ b/src/interfaces/strategy.ts @@ -92,7 +92,7 @@ export class StrategyInterface extends ServiceInterface { loss, time: new Date(timestamp * 1000), estimatedTotalAssets, - apr: 0, // will be filled in using the `populateHarvestAprs` function + apr: undefined, // will be filled in using the `populateHarvestAprs` function }; }); @@ -108,11 +108,15 @@ export class StrategyInterface extends ServiceInterface { private populateHarvestAprs(harvests: HarvestData[]): HarvestData[] { // loop through the harvests, and calculate the apr by referencing the time since the previous harvest harvests.forEach((harvest, index) => { - // if the gain is 0 or if this is the last harvest then the apr is 0 - if (harvest.gain === BigNumber.from(0) || index + 1 === harvests.length) { + // if the gain is 0 then the apr is 0 + if (harvest.gain === BigNumber.from(0)) { harvests[index].apr = 0; return; + } else if (index + 1 === harvests.length) { + // if this is the oldest harvest leave the apy as undefined since there is no previous harvest to compare it against + return; } + const previousHarvest = harvests[index + 1]; // get the difference in days between this harvest and the one prior diff --git a/src/types/strategy.ts b/src/types/strategy.ts index 593433e6..894dc2fd 100644 --- a/src/types/strategy.ts +++ b/src/types/strategy.ts @@ -14,5 +14,5 @@ export interface HarvestData { loss: BigNumber; time: Date; estimatedTotalAssets: BigNumber; - apr: number; + apr?: number; }