-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[oseth-stats] add new osToken getStats methods (#247)
* [oseth-stats] add new osToken getStats methods * [oseth-stats] add getstats to next-release * [oseth-stats] format tables * [oseth-stats] format tables * [oseth-stats] update docs, add links
- Loading branch information
1 parent
2a837f4
commit adf4b94
Showing
10 changed files
with
153 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export { fetchOsTokenApyQuery } from './osTokenApyQuery.graphql' | ||
export type { OsTokenApyQueryPayload, OsTokenApyQueryVariables } from './osTokenApyQuery.graphql' | ||
|
||
export { fetchOsTokenStatsQuery } from './osTokenStatsQuery.graphql' | ||
export type { OsTokenStatsQueryPayload, OsTokenStatsQueryVariables } from './osTokenStatsQuery.graphql' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
query OsTokenStats( | ||
$first: Int | ||
$where: OsTokenStats_filter | ||
) { | ||
osTokenStats: osTokenStats_collection( | ||
interval: day | ||
first: $first | ||
where: $where | ||
) { | ||
apy | ||
timestamp | ||
totalAssets | ||
earnedAssets | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
id: getStats | ||
slug: /osToken/requests/getstats | ||
--- | ||
|
||
#### Description: | ||
|
||
Getting the osToken stats collection. With the help of this data it is possible to build a chart. | ||
|
||
#### Arguments: | ||
|
||
| Name | Type | Required | Description | | ||
|-----------|----------|----------|-------------------| | ||
| daysCount | `number` | **Yes** | The limit in days | | ||
|
||
#### Returns: | ||
|
||
```ts | ||
type Output = { | ||
apy: number | ||
time: number | ||
balance: number | ||
rewards: number | ||
} | ||
``` | ||
| Name | Description | | ||
|-----------|------------------------------------------------------------| | ||
| `time` | Date and time for each data point | | ||
| `apy` | Current APY based on time, rewards and balance. | | ||
| `rewards` | Number of assets earned by the osToken during the interval | | ||
| `balance` | Total assets in the osToken at the moment of time | | ||
#### Example: | ||
```ts | ||
await sdk.osToken.getStats({ | ||
daysCount: 30 | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { apiUrls, getTimestamp, validateArgs } from '../../../../utils' | ||
import modifyStats from './modifyStats' | ||
import graphql from '../../../../graphql' | ||
|
||
|
||
type GetStatsInput = { | ||
options: StakeWise.Options | ||
daysCount: number | ||
} | ||
|
||
const getStats = (input: GetStatsInput) => { | ||
const { options, daysCount } = input | ||
|
||
validateArgs.number({ daysCount }) | ||
|
||
const timestamp = String(getTimestamp(daysCount)) | ||
|
||
return graphql.subgraph.osToken.fetchOsTokenStatsQuery({ | ||
url: apiUrls.getSubgraphqlUrl(options), | ||
variables: { | ||
first: daysCount, | ||
where: { | ||
timestamp_gte: timestamp, | ||
}, | ||
}, | ||
modifyResult: modifyStats, | ||
}) | ||
} | ||
|
||
|
||
export default getStats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { formatEther } from 'ethers' | ||
|
||
import { ModifiedStats } from './types' | ||
import type { OsTokenStatsQueryPayload } from '../../../../graphql/subgraph/osToken' | ||
|
||
|
||
const modifyStats = (data: OsTokenStatsQueryPayload): ModifiedStats[] => { | ||
const osTokenStats = data?.osTokenStats || [] | ||
|
||
return osTokenStats.map((stat) => { | ||
const timeInSeconds = Number(stat.timestamp) / 1_000_000 | ||
const balance = Number(formatEther(stat.totalAssets || '0')) | ||
const rewards = Number(formatEther(stat.earnedAssets || '0')) | ||
|
||
return { | ||
balance, | ||
rewards, | ||
time: timeInSeconds, | ||
apy: Number(stat.apy), | ||
} | ||
}) | ||
} | ||
|
||
|
||
export default modifyStats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type ModifiedStats = { | ||
apy: number | ||
time: number | ||
balance: number | ||
rewards: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters