Skip to content

Commit

Permalink
fix: support ftm subgraph earnings (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstashh authored Oct 28, 2021
1 parent e4fb8a1 commit 28b21f8
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/interfaces/earnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ export class EarningsInterface<C extends ChainId> extends ServiceInterface<C> {
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
Expand Down Expand Up @@ -402,4 +401,26 @@ export class EarningsInterface<C extends ChainId> extends ServiceInterface<C> {
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;
}
}
}

0 comments on commit 28b21f8

Please sign in to comment.