Skip to content

Commit

Permalink
[new-score]: remove score, add new score percentiles
Browse files Browse the repository at this point in the history
  • Loading branch information
dfkadyr committed Feb 16, 2024
1 parent 568fa2b commit 99fcb34
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 128 deletions.
34 changes: 12 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const sdk = new StakeWiseSDK({ network: Network.Mainnet })
| [sdk.vault.getMaxWithdraw](#sdkvaultgetmaxwithdraw) | [sdk.osToken.getBaseData](#sdkostokengetbasedata) |
| [sdk.vault.getHarvestParams](#sdkvaultgetharvestparams) | [sdk.osToken.getSharesFromAssets](#sdkostokengetsharesfromassets) |
| [sdk.vault.getStakeBalance](#sdkvaultgetstakebalance) | [sdk.osToken.getAssetsFromShares](#sdkostokengetassetsfromshares) |
|[sdk.vault.getUserRewards](#sdkvaultgetuserrewards) | [sdk.vault.getScoring](#sdkvaultgetscoring) |
|[sdk.vault.getUserRewards](#sdkvaultgetuserrewards) | [sdk.vault.getScorePercentiles](#sdkvaultgetscorepercentiles)

##### Table of transactions:
| **Vault** | **osToken** |
Expand Down Expand Up @@ -205,42 +205,32 @@ await sdk.vault.getSnapshots({
})
```
---
### `sdk.vault.getScoring`
### `sdk.vault.getScorePercentiles`
#### Description:
Fetch components for performance score calculation.
#### Arguments:
| Name | Type | Type | Description |
|--------------|----------|-----------------|---------|
| vaultAddress | `string` | **Require** | - |
Fetch components for score percentiles calculation.
#### Returns:
```ts
type Output = {
consensusRewardsEarned: bigint
consensusRewardsMissed: bigint
executionMevEarned: bigint
executionMevMissed: bigint
percentile25: number
percentile50: number
percentile75: number
}
```
| Name | Description |
|------|-------------|
| `consensusRewardsEarned` | The total amount of consensus rewards earned by the Vault |
| `consensusRewardsMissed` | The total amount of consensus rewards missed by the Vault |
| `executionMevEarned` | The total amount of execution rewards earned by the Vault |
| `executionMevMissed` | The total amount of execution rewards missed by the Vault. It will include the ones missed due to the invalid fee recipient address set for the validator |
| Name | Description |
|------|-----------------------------------------------------------|
| `percentile25` | The value that corresponds to this percentage |
| `percentile50` | The value that corresponds to this percentage |
| `percentile75` | The value that corresponds to this percentage |
#### Example:
```ts
await sdk.vault.getScoring({
vaultAddress: '0x...',
})
await sdk.vault.getScorePercentiles()
```
---
### `sdk.vault.getUserRewards`
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,6 +1,3 @@
export { fetchScoringQuery } from './scoringQuery.graphql'
export type { ScoringQueryPayload, ScoringQueryVariables } from './scoringQuery.graphql'

export { fetchSnapshotsQuery } from './snapshotsQuery.graphql'
export type { SnapshotsQueryPayload, SnapshotsQueryVariables } from './snapshotsQuery.graphql'

Expand All @@ -9,3 +6,6 @@ export type { ValidatorsQueryPayload, ValidatorsQueryVariables } from './validat

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

export { fetchScorePercentilesQuery } from './scorePercentilesQuery.graphql'
export type { ScorePercentilesQueryPayload, ScorePercentilesQueryVariables } from './scorePercentilesQuery.graphql'
7 changes: 7 additions & 0 deletions src/graphql/backend/vault/scorePercentilesQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query ScorePercentiles {
scorePercentiles {
percentile25,
percentile50,
percentile75
}
}
10 changes: 0 additions & 10 deletions src/graphql/backend/vault/scoringQuery.graphql

This file was deleted.

18 changes: 9 additions & 9 deletions src/methods/vault/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Requests
import getVault from './requests/getVault'
import getSnapshots from './requests/getSnapshots'
import getValidators from './requests/getValidators'
import getUserRewards from './requests/getUserRewards'
import getMaxWithdraw from './requests/getMaxWithdraw'
import getStakeBalance from './requests/getStakeBalance'
import getHarvestParams from './requests/getHarvestParams'
import getStakerActions from './requests/getStakerActions'
import getScorePercentiles from './requests/getScorePercentiles'
import getExitQueuePositions from './requests/getExitQueuePositions'
import getSnapshots from './requests/getSnapshots'
import getScoring from './requests/getScoring'

// Transactions
import { deposit } from './transactions/deposit'
Expand All @@ -18,16 +18,16 @@ import { claimExitQueue } from './transactions/claimExitQueue'

export default {
requests: {
getVault,
getValidators,
getUserRewards,
getMaxWithdraw,
getStakeBalance,
getExitQueuePositions,
getScorePercentiles,
getHarvestParams,
getStakerActions,
getStakeBalance,
getUserRewards,
getMaxWithdraw,
getValidators,
getSnapshots,
getScoring,
getExitQueuePositions,
getVault,
},
transactions: {
deposit,
Expand Down
25 changes: 25 additions & 0 deletions src/methods/vault/requests/getScorePercentiles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { ScorePercentilesQueryPayload } from '../../../../graphql/backend/vault'
import { apiUrls } from '../../../../utils'
import graphql from '../../../../graphql'

import modifyScorePercentiles from './modifyScorePercentiles'
import { ModifiedScorePercentiles } from './types'


type GetScorePercentilesInput = {
options: StakeWise.Options
}

const getScorePercentiles = async (input: GetScorePercentilesInput) => {
const { options } = input

const data = await graphql.backend.vault.fetchScorePercentilesQuery<ModifiedScorePercentiles>({
url: apiUrls.getBackendUrl(options),
modifyResult: (data: ScorePercentilesQueryPayload) => modifyScorePercentiles(data),
})

return data
}


export default getScorePercentiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ScorePercentilesQueryPayload } from '../../../../graphql/backend/vault'
import modifyScorePercentiles from './modifyScorePercentiles'


describe('modifyScorePercentiles functions', () => {
const sampleInput: ScorePercentilesQueryPayload = {
scorePercentiles: {
percentile25: '95.00',
percentile50: '97.00',
percentile75: '98.00',
},
}

it('should correctly modify a score percentiles', () => {
const result = modifyScorePercentiles(sampleInput)

expect(result).toEqual({
percentile25: 95.00,
percentile50: 97.00,
percentile75: 98.00,
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ScorePercentilesQueryPayload } from '../../../../graphql/backend/vault'
import { ModifiedScorePercentiles } from './types'


const modifyScorePercentiles = (input: ScorePercentilesQueryPayload): ModifiedScorePercentiles => {
const { scorePercentiles } = input

return ({
percentile25: Number(scorePercentiles.percentile25),
percentile50: Number(scorePercentiles.percentile50),
percentile75: Number(scorePercentiles.percentile75),
})
}


export default modifyScorePercentiles
5 changes: 5 additions & 0 deletions src/methods/vault/requests/getScorePercentiles/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type ModifiedScorePercentiles = {
percentile25: number
percentile50: number
percentile75: number
}
30 changes: 0 additions & 30 deletions src/methods/vault/requests/getScoring/index.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/methods/vault/requests/getScoring/modifyScoring.spec.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/methods/vault/requests/getScoring/modifyScoring.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/methods/vault/requests/getScoring/types.ts

This file was deleted.

0 comments on commit 99fcb34

Please sign in to comment.