From 28b21f8da680c0f2c042f013f591592733eca6ed Mon Sep 17 00:00:00 2001 From: jstashh <19509999+jstashh@users.noreply.github.com> Date: Thu, 28 Oct 2021 16:45:58 +0100 Subject: [PATCH] fix: support ftm subgraph earnings (#155) --- src/interfaces/earnings.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/interfaces/earnings.ts b/src/interfaces/earnings.ts index 734aa789..91003c9f 100644 --- a/src/interfaces/earnings.ts +++ b/src/interfaces/earnings.ts @@ -208,12 +208,11 @@ export class EarningsInterface extends ServiceInterface { blockNumber = await this.ctx.provider.read.getBlockNumber(); } - blockNumber -= 100; // subgraph might be slightly behind latest block + blockNumber -= this.blockOffset(); // subgraph might be slightly behind latest block - const blocksPerDay = 6500; const blocks = Array.from(Array(fromDaysAgo).keys()) .reverse() - .map(day => blockNumber - day * blocksPerDay); + .map(day => blockNumber - day * this.blocksPerDay()); const response = (await this.yearn.services.subgraph.fetchQuery(ASSET_HISTORIC_EARNINGS(blocks), { id: vault @@ -402,4 +401,26 @@ export class EarningsInterface extends ServiceInterface { date.setDate(date.getDate() - daysAgo); return date; } + + private blocksPerDay(): number { + switch (this.chainId) { + case 1: + case 1337: + case 42161: + return 5760; + case 250: + return 86400; + } + } + + private blockOffset(): number { + switch (this.chainId) { + case 1: + case 1337: + case 42161: + return 100; + case 250: + return 1000; + } + } }