Skip to content

Commit

Permalink
fix: set apr as undefined for oldest queried
Browse files Browse the repository at this point in the history
  • Loading branch information
jstashh authored and karelianpie committed Jun 4, 2022
1 parent 6b71dcb commit de5b710
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
10 changes: 7 additions & 3 deletions src/interfaces/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class StrategyInterface<T extends ChainId> extends ServiceInterface<T> {
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
};
});

Expand All @@ -108,11 +108,15 @@ export class StrategyInterface<T extends ChainId> extends ServiceInterface<T> {
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
Expand Down
2 changes: 1 addition & 1 deletion src/types/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export interface HarvestData {
loss: BigNumber;
time: Date;
estimatedTotalAssets: BigNumber;
apr: number;
apr?: number;
}

0 comments on commit de5b710

Please sign in to comment.