Skip to content

Commit

Permalink
[oseth-stats] add new osToken getStats methods (#247)
Browse files Browse the repository at this point in the history
* [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
dfkadyr-stakewise authored Feb 6, 2025
1 parent 2a837f4 commit adf4b94
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 13 deletions.
16 changes: 15 additions & 1 deletion changelog/next-release.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# New
### 1. [sdk.osToken.getStats](https://sdk.stakewise.io/osToken/requests/getstats)

#### Description:

Getting the osToken stats collection. With the help of this data it is possible to build a chart.

#### Example:
```ts
await sdk.osToken.getStats({
daysCount: 30
})
```

# Updates
### 1. `sdk.boost.getData`
### 1. [sdk.boost.getData](https://sdk.stakewise.io/boost/requests/getdata)

#### New output fields:

Expand Down
3 changes: 3 additions & 0 deletions src/graphql/subgraph/osToken/index.ts
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'
15 changes: 15 additions & 0 deletions src/graphql/subgraph/osToken/osTokenStatsQuery.graphql
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
}
}
6 changes: 6 additions & 0 deletions src/methods/osToken/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Requests
import getStats from './requests/getStats'
import getAPY from './requests/getOsTokenAPY'
import getMaxMint from './requests/getMaxMint'
import getRate from './requests/getOsTokenRate'
Expand Down Expand Up @@ -61,6 +62,11 @@ export default {
* @see https://sdk.stakewise.io/utils/getpermitsignature
*/
getPermitSignature,
/**
* @description Returns the osToken stats collection. With the help of this data it is possible to build a chart.
* @see https://sdk.stakewise.io/osToken/requests/getstats
*/
getStats,
},
transactions: {
/**
Expand Down
40 changes: 40 additions & 0 deletions src/methods/osToken/requests/getStats/getStats.md
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
})
```
31 changes: 31 additions & 0 deletions src/methods/osToken/requests/getStats/index.ts
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
25 changes: 25 additions & 0 deletions src/methods/osToken/requests/getStats/modifyStats.ts
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
6 changes: 6 additions & 0 deletions src/methods/osToken/requests/getStats/types.ts
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
}
12 changes: 6 additions & 6 deletions src/methods/vault/requests/getUserStats/getUserStats.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ type Output = {
}
```
| 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 user in current vault during the interval in ETH |
| `balance` | Total assets by the user in current vault at the moment of time in ETH |
| 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 user in current vault during the interval |
| `balance` | Total assets by the user in current vault at the moment of time |
#### Example:
Expand Down
12 changes: 6 additions & 6 deletions src/methods/vault/requests/getVaultStats/getVaultStats.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ type Output = {
}
```
| 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 vault during the interval in ETH |
| `balance` | Total assets in the vault at the moment of time in ETH |
| 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 vault during the interval |
| `balance` | Total assets in the vault at the moment of time |
#### Example:
Expand Down

0 comments on commit adf4b94

Please sign in to comment.