From 99fcb34aadc2bbef149a5df3fd5201d6660d0e52 Mon Sep 17 00:00:00 2001 From: dfkadyr Date: Fri, 16 Feb 2024 12:57:06 +0300 Subject: [PATCH] [new-score]: remove score, add new score percentiles --- README.md | 34 +++++++------------ src/graphql/backend/vault/index.ts | 6 ++-- .../vault/scorePercentilesQuery.graphql | 7 ++++ .../backend/vault/scoringQuery.graphql | 10 ------ src/methods/vault/index.ts | 18 +++++----- .../requests/getScorePercentiles/index.ts | 25 ++++++++++++++ .../modifyScorePercentiles.spec.ts | 23 +++++++++++++ .../modifyScorePercentiles.ts | 16 +++++++++ .../requests/getScorePercentiles/types.ts | 5 +++ .../vault/requests/getScoring/index.ts | 30 ---------------- .../requests/getScoring/modifyScoring.spec.ts | 29 ---------------- .../requests/getScoring/modifyScoring.ts | 19 ----------- .../vault/requests/getScoring/types.ts | 6 ---- 13 files changed, 100 insertions(+), 128 deletions(-) create mode 100644 src/graphql/backend/vault/scorePercentilesQuery.graphql delete mode 100644 src/graphql/backend/vault/scoringQuery.graphql create mode 100644 src/methods/vault/requests/getScorePercentiles/index.ts create mode 100644 src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.spec.ts create mode 100644 src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.ts create mode 100644 src/methods/vault/requests/getScorePercentiles/types.ts delete mode 100644 src/methods/vault/requests/getScoring/index.ts delete mode 100644 src/methods/vault/requests/getScoring/modifyScoring.spec.ts delete mode 100644 src/methods/vault/requests/getScoring/modifyScoring.ts delete mode 100644 src/methods/vault/requests/getScoring/types.ts diff --git a/README.md b/README.md index 75f7fa9f..993816af 100644 --- a/README.md +++ b/README.md @@ -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** | @@ -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` diff --git a/src/graphql/backend/vault/index.ts b/src/graphql/backend/vault/index.ts index 4a8c7906..00ce3b17 100644 --- a/src/graphql/backend/vault/index.ts +++ b/src/graphql/backend/vault/index.ts @@ -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' @@ -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' diff --git a/src/graphql/backend/vault/scorePercentilesQuery.graphql b/src/graphql/backend/vault/scorePercentilesQuery.graphql new file mode 100644 index 00000000..d46843ef --- /dev/null +++ b/src/graphql/backend/vault/scorePercentilesQuery.graphql @@ -0,0 +1,7 @@ +query ScorePercentiles { + scorePercentiles { + percentile25, + percentile50, + percentile75 + } +} diff --git a/src/graphql/backend/vault/scoringQuery.graphql b/src/graphql/backend/vault/scoringQuery.graphql deleted file mode 100644 index 4de9dad8..00000000 --- a/src/graphql/backend/vault/scoringQuery.graphql +++ /dev/null @@ -1,10 +0,0 @@ -query Scoring($vaultAddress: String!) { - vaults(id: $vaultAddress) { - scoring { - consensusRewardsEarned, - consensusRewardsMissed, - executionMevEarned, - executionMevMissed - } - } -} diff --git a/src/methods/vault/index.ts b/src/methods/vault/index.ts index 163881c3..1faef0fc 100644 --- a/src/methods/vault/index.ts +++ b/src/methods/vault/index.ts @@ -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' @@ -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, diff --git a/src/methods/vault/requests/getScorePercentiles/index.ts b/src/methods/vault/requests/getScorePercentiles/index.ts new file mode 100644 index 00000000..65fb2371 --- /dev/null +++ b/src/methods/vault/requests/getScorePercentiles/index.ts @@ -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({ + url: apiUrls.getBackendUrl(options), + modifyResult: (data: ScorePercentilesQueryPayload) => modifyScorePercentiles(data), + }) + + return data +} + + +export default getScorePercentiles diff --git a/src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.spec.ts b/src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.spec.ts new file mode 100644 index 00000000..eb8d3e56 --- /dev/null +++ b/src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.spec.ts @@ -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, + }) + }) +}) diff --git a/src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.ts b/src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.ts new file mode 100644 index 00000000..a3e172f1 --- /dev/null +++ b/src/methods/vault/requests/getScorePercentiles/modifyScorePercentiles.ts @@ -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 diff --git a/src/methods/vault/requests/getScorePercentiles/types.ts b/src/methods/vault/requests/getScorePercentiles/types.ts new file mode 100644 index 00000000..e715de85 --- /dev/null +++ b/src/methods/vault/requests/getScorePercentiles/types.ts @@ -0,0 +1,5 @@ +export type ModifiedScorePercentiles = { + percentile25: number + percentile50: number + percentile75: number +} diff --git a/src/methods/vault/requests/getScoring/index.ts b/src/methods/vault/requests/getScoring/index.ts deleted file mode 100644 index 064b5139..00000000 --- a/src/methods/vault/requests/getScoring/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { ScoringQueryVariables, ScoringQueryPayload } from '../../../../graphql/backend/vault' -import { apiUrls, validateArgs } from '../../../../utils' -import graphql from '../../../../graphql' -import modifyScoring from './modifyScoring' -import { ModifiedScoring } from './types' - - -type GetScoringInput = { - options: StakeWise.Options - vaultAddress: ScoringQueryVariables['vaultAddress'] -} - -const getScoring = async (input: GetScoringInput) => { - const { options, vaultAddress } = input - - validateArgs.address({ vaultAddress }) - - const data = await graphql.backend.vault.fetchScoringQuery({ - url: apiUrls.getBackendUrl(options), - variables: { - vaultAddress: vaultAddress.toLowerCase(), - } as ScoringQueryVariables, - modifyResult: (data: ScoringQueryPayload) => modifyScoring(data), - }) - - return data -} - - -export default getScoring diff --git a/src/methods/vault/requests/getScoring/modifyScoring.spec.ts b/src/methods/vault/requests/getScoring/modifyScoring.spec.ts deleted file mode 100644 index f1e6b0c0..00000000 --- a/src/methods/vault/requests/getScoring/modifyScoring.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type { ScoringQueryPayload } from '../../../../graphql/backend/vault' -import modifyScoring from './modifyScoring' - - -describe('modifyScoring functions', () => { - const sampleInput: ScoringQueryPayload = { - vaults: [ - { - scoring: { - consensusRewardsEarned: '89163004', - consensusRewardsMissed: '478650', - executionMevEarned: '21005814693398160', - executionMevMissed: '0', - }, - }, - ], - } - - it('should correctly modify a single vault snapshot', () => { - const result = modifyScoring(sampleInput) - - expect(result).toEqual({ - consensusRewardsEarned: 89163004n, - consensusRewardsMissed: 478650n, - executionMevEarned: 21005814693398160n, - executionMevMissed: 0n, - }) - }) -}) diff --git a/src/methods/vault/requests/getScoring/modifyScoring.ts b/src/methods/vault/requests/getScoring/modifyScoring.ts deleted file mode 100644 index 1b1bf111..00000000 --- a/src/methods/vault/requests/getScoring/modifyScoring.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { ScoringQueryPayload } from '../../../../graphql/backend/vault' -import { ModifiedScoring } from './types' - - -const modifyScoring = (input: ScoringQueryPayload): ModifiedScoring => { - const { vaults } = input - - const { scoring } = vaults[0] - - return ({ - consensusRewardsEarned: BigInt(scoring?.consensusRewardsEarned || 0), - consensusRewardsMissed: BigInt(scoring?.consensusRewardsMissed || 0), - executionMevEarned: BigInt(scoring?.executionMevEarned || 0), - executionMevMissed: BigInt(scoring?.executionMevMissed || 0), - }) -} - - -export default modifyScoring diff --git a/src/methods/vault/requests/getScoring/types.ts b/src/methods/vault/requests/getScoring/types.ts deleted file mode 100644 index 7ce9d621..00000000 --- a/src/methods/vault/requests/getScoring/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type ModifiedScoring = { - consensusRewardsEarned: bigint, - consensusRewardsMissed: bigint, - executionMevEarned: bigint, - executionMevMissed: bigint, -}