Skip to content

Commit

Permalink
[new apy]: rename getSnapshots, PR improves
Browse files Browse the repository at this point in the history
  • Loading branch information
dfkadyr committed Dec 25, 2023
1 parent 5471c26 commit 1df04ed
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 265 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const sdk = new StakeWiseSDK({ network: Network.Mainnet })
| **Vault** | **osToken** | **Utils** |
|------|-------------|------|
| [sdk.vault.getStakerActions](#sdkvaultgetstakeractions) | [sdk.osToken.getBurnAmount](#sdkostokengetburnamount) | [sdk.utils.getRewardsPerYear](#sdkutilsgetrewardsperyear) |
| [sdk.vault.getVaultSnapshots](#sdkvaultgetvaultsnapshots) | [sdk.osToken.getHealthFactor](#sdkostokengethealthfactor) | [sdk.utils.getSwiseUsdPrice](#sdkutilsgetswiseusdprice) |
| [sdk.vault.getSnapshots](#sdkvaultgetsnapshots) | [sdk.osToken.getHealthFactor](#sdkostokengethealthfactor) | [sdk.utils.getSwiseUsdPrice](#sdkutilsgetswiseusdprice) |
| [sdk.vault.getExitQueuePositions](#sdkvaultgetexitqueuepositions) | [sdk.osToken.getAPY](#sdkostokengetapy) | [sdk.utils.getTransactions](#sdkutilsgettransactions) |
| [sdk.vault.getValidators](#sdkvaultgetvalidators) | [sdk.osToken.getPosition](#sdkostokengetposition) |
| [sdk.vault.getVault](#sdkvaultgetvault) | [sdk.osToken.getMaxMint](#sdkostokengetmaxmint) |
Expand Down Expand Up @@ -164,7 +164,7 @@ await sdk.vault.getStakerActions({
})
```
---
### `sdk.vault.getVaultSnapshots`
### `sdk.vault.getSnapshots`

#### Description:

Expand All @@ -182,14 +182,14 @@ TVL and APY snapshots for the vault. With the help of this data it is possible t
#### Returns:

```ts
type VaultSnapshot = {
type Snapshot = {
APY: number
TVL: string
}

type Output = {
days: Record<number, VaultSnapshot>
first: VaultSnapshot
days: Record<number, Snapshot>
first: Snapshot
}
```
Expand All @@ -201,7 +201,7 @@ type Output = {
#### Example:
```ts
await sdk.vault.getVaultSnapshots({
await sdk.vault.getSnapshots({
vaultAddress: '0x...',
dateFrom: 1695730032793,
})
Expand Down
6 changes: 3 additions & 3 deletions src/graphql/backend/vault/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { fetchSnapshotsQuery } from './snapshotsQuery.graphql'
export type { SnapshotsQueryPayload, SnapshotsQueryVariables } from './snapshotsQuery.graphql'

export { fetchValidatorsQuery } from './validatorsQuery.graphql'
export type { ValidatorsQueryPayload, ValidatorsQueryVariables } from './validatorsQuery.graphql'

export { fetchUserRewardsQuery } from './userRewardsQuery.graphql'
export type { UserRewardsQueryPayload, UserRewardsQueryVariables } from './userRewardsQuery.graphql'

export { fetchVaultSnapshotsQuery } from './vaultSnapshotsQuery.graphql'
export type { VaultSnapshotsQueryPayload, VaultSnapshotsQueryVariables } from './vaultSnapshotsQuery.graphql'
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
query VaultSnapshots($vaultAddress: String! $dateFrom: DateAsTimestamp! $dateTo: DateAsTimestamp $first: Int) {
query Snapshots($vaultAddress: String! $dateFrom: DateAsTimestamp! $dateTo: DateAsTimestamp $first: Int) {
vaultSnapshots(
vaultAddress: $vaultAddress
dateFrom: $dateFrom
dateTo: $dateTo
first: $first
) {
date,
rewardPerAsset: weeklyApy
weeklyApy
totalAssets
}
firstSnapshots: vaultSnapshots(vaultAddress: $vaultAddress, dateFrom: $dateFrom, first: 1) {
date
totalAssets
rewardPerAsset: weeklyApy
weeklyApy
}
}
15 changes: 0 additions & 15 deletions src/graphql/subgraph/daySnapshots/daySnapshotsQuery.graphql

This file was deleted.

2 changes: 0 additions & 2 deletions src/graphql/subgraph/daySnapshots/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/graphql/subgraph/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * as vault from './vault'
export * as osToken from './osToken'
export * as exitQueue from './exitQueue'
export * as daySnapshots from './daySnapshots'
export * as transactions from './transactions'
export * as allocatorActions from './allocatorActions'
4 changes: 2 additions & 2 deletions src/methods/vault/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getStakeBalance from './requests/getStakeBalance'
import getHarvestParams from './requests/getHarvestParams'
import getStakerActions from './requests/getStakerActions'
import getExitQueuePositions from './requests/getExitQueuePositions'
import getVaultSnapshots from './requests/getVaultSnapshots'
import getSnapshots from './requests/getSnapshots'

// Transactions
import { deposit } from './transactions/deposit'
Expand All @@ -24,7 +24,7 @@ export default {
getStakeBalance,
getHarvestParams,
getStakerActions,
getVaultSnapshots,
getSnapshots,
getExitQueuePositions,
},
transactions: {
Expand Down
39 changes: 0 additions & 39 deletions src/methods/vault/requests/getDaySnapshots/index.ts

This file was deleted.

This file was deleted.

35 changes: 0 additions & 35 deletions src/methods/vault/requests/getDaySnapshots/modifyDaySnapshots.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/methods/vault/requests/getDaySnapshots/types.ts

This file was deleted.

33 changes: 33 additions & 0 deletions src/methods/vault/requests/getSnapshots/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { SnapshotsQueryVariables } from '../../../../graphql/backend/vault'
import { apiUrls, validateArgs } from '../../../../utils'
import modifySnapshots from './modifySnapshots'
import graphql from '../../../../graphql'
import { ModifiedSnapshots } from './types'


type GetSnapshotsInput = {
options: StakeWise.Options
vaultAddress: SnapshotsQueryVariables['vaultAddress']
dateFrom: SnapshotsQueryVariables['dateFrom']
}

const getSnapshots = async (input: GetSnapshotsInput) => {
const { options, vaultAddress, dateFrom } = input

validateArgs.address({ vaultAddress })
validateArgs.string({ dateFrom })

const data = await graphql.backend.vault.fetchSnapshotsQuery<ModifiedSnapshots>({
url: apiUrls.getBackendUrl(options),
variables: {
vaultAddress: vaultAddress.toLowerCase(),
dateFrom,
} as SnapshotsQueryVariables,
modifyResult: modifySnapshots,
})

return data
}


export default getSnapshots
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import type { VaultSnapshotsQueryPayload } from '../../../../graphql/backend/vault'
import modifyVaultSnapshots, { modifyVaultSnapshot } from './modifyVaultSnapshots'
import type { SnapshotsQueryPayload } from '../../../../graphql/backend/vault'
import modifySnapshots, { modifySnapshot } from './modifySnapshots'


describe('modifyVaultSnapshot and modifyVaultSnapshots functions', () => {
const sampleInput: VaultSnapshotsQueryPayload = {
const sampleInput: SnapshotsQueryPayload = {
vaultSnapshots: [
{
date: '1700870400',
totalAssets: '3906945363776011390139',
rewardPerAsset: '1.8793377858',
weeklyApy: '1.8793377858',
},
{
date: '1700956800',
totalAssets: '3907107984571011390139',
rewardPerAsset: '1.6767640360',
weeklyApy: '1.6767640360',
},
],
firstSnapshots: [
{
date: '1700870400',
totalAssets: '3906945363776011390139',
rewardPerAsset: '1.8793377858',
weeklyApy: '1.8793377858',
},
],
}

it('should correctly modify a single vault snapshot', () => {
const vaultSnapshot = sampleInput.vaultSnapshots[0]

const result = modifyVaultSnapshot(vaultSnapshot)
const result = modifySnapshot(vaultSnapshot)

expect(result).toEqual({
APY: Number(vaultSnapshot.rewardPerAsset),
APY: Number(vaultSnapshot.weeklyApy),
TVL: 3906.945363776011,
})
})
Expand All @@ -40,21 +40,21 @@ describe('modifyVaultSnapshot and modifyVaultSnapshots functions', () => {
const expectedResult = {
days: {
1700870400: {
APY: Number(sampleInput.vaultSnapshots[0].rewardPerAsset),
APY: Number(sampleInput.vaultSnapshots[0].weeklyApy),
TVL: 3906.945363776011,
},
1700956800: {
APY: Number(sampleInput.vaultSnapshots[1].rewardPerAsset),
APY: Number(sampleInput.vaultSnapshots[1].weeklyApy),
TVL: 3907.1079845710115,
},
},
first: {
APY: Number(sampleInput.firstSnapshots[0].rewardPerAsset),
APY: Number(sampleInput.firstSnapshots[0].weeklyApy),
TVL: 3906.945363776011,
},
}

const result = modifyVaultSnapshots(sampleInput)
const result = modifySnapshots(sampleInput)

expect(result).toEqual(expectedResult)
})
Expand Down
Loading

0 comments on commit 1df04ed

Please sign in to comment.