From f2c4fbdc3997d822a38ba12348b5be78df435be5 Mon Sep 17 00:00:00 2001 From: dfkadyr-stakewise Date: Fri, 7 Mar 2025 10:03:23 +0300 Subject: [PATCH 1/4] [base-apy] add SSV token support and refactor APY components --- changelog/next-release.md | 16 +++++ src/graphql/subgraph/vault/vaultQuery.graphql | 1 + .../vault/requests/getVault/getVault.md | 70 ++++++++++--------- .../requests/getVault/modifyVault.spec.ts | 2 + .../vault/requests/getVault/modifyVault.ts | 2 + src/methods/vault/requests/getVault/types.ts | 2 + src/utils/configs/chiado.ts | 2 + src/utils/configs/gnosis.ts | 2 + src/utils/configs/holesky.ts | 4 +- src/utils/configs/mainnet.ts | 2 + src/utils/constants/tokens.ts | 1 + 11 files changed, 69 insertions(+), 35 deletions(-) diff --git a/changelog/next-release.md b/changelog/next-release.md index 1e9e1772..c2d71edb 100644 --- a/changelog/next-release.md +++ b/changelog/next-release.md @@ -16,3 +16,19 @@ type Output = { |---------------------|-------------------------| | `assets` | Balance in ETH | | `totalEarnedAssets` | Total earned rewards | + + +### 2. [sdk.vault.getVault](https://sdk.stakewise.io/vault/requests/getvault) + +#### Add new output item: + +```ts +type Output = { + baseApy: number +} +``` +| Name | Description | +|-----------|--------------------------------------------------------------| +| `baseApy` | The vault average weekly base APY (without extra incentives) | + +### 3. Add SSV token to config diff --git a/src/graphql/subgraph/vault/vaultQuery.graphql b/src/graphql/subgraph/vault/vaultQuery.graphql index 09b45a5e..c306a65a 100644 --- a/src/graphql/subgraph/vault/vaultQuery.graphql +++ b/src/graphql/subgraph/vault/vaultQuery.graphql @@ -10,6 +10,7 @@ query Vault($address: ID!) { admin version isErc20 + baseApy imageUrl capacity mevEscrow diff --git a/src/methods/vault/requests/getVault/getVault.md b/src/methods/vault/requests/getVault/getVault.md index de7290d7..f065bc74 100644 --- a/src/methods/vault/requests/getVault/getVault.md +++ b/src/methods/vault/requests/getVault/getVault.md @@ -18,6 +18,7 @@ Returns the master data of the vault ```ts type Output = { apy: number + baseApy: number version: number isErc20: boolean capacity: string @@ -50,40 +51,41 @@ type Output = { } ``` -| Name | Description | -|-----------------------------|-------------------------------------------------| -| `version` | Vault version | -| `apy` | Current vault apy | -| `isErc20` | Does the vault have its own ERC20 token | -| `capacity` | Maximum TVL of Vault | -| `createdAt` | Date of Creation | -| `feePercent` | Commission rate | -| `isPrivate` | Whether the vault is private | -| `isGenesis` | Is a stakewise vault | -| `queuedShares` | The total number of queued shares | -| `isBlocklist` | Whether the vault has blocklist | -| `vaultAdmin` | Vault administrator address | -| `totalAssets` | TVL of Vault | -| `feeRecipient` | Vault fee address | -| `whitelistManager` | Whitelist manager | -| `vaultAddress` | Address of vault | -| `mevRecipient` | Validator fee recipient | -| `whitelistCount` | Number of addresses in the [whitelist](/vault/requests/getwhitelist) | -| `blocklistCount` | Number of addresses in the [blocklist](/vault/requests/getblocklist) | -| `imageUrl` | Link for vault logo | -| `blocklistManager` | Blocklist manager | -| `depositDataManager` | Keys manager address | -| `isSmoothingPool` | Smoothing poll or Vault escrow | -| `tokenName` | ERC20 token name | -| `tokenSymbol` | ERC20 token symbol | -| `displayName` | Name of vault | -| `allocatorMaxBoostApy` | The average max boost APY earned in this vault by the allocator | -| `osTokenHolderMaxBoostApy` | The average max boost APY earned in this vault by the osToken holder | -| `description` | Description of vault | -| `whitelist` | List of authorized users for deposits | -| `blocklist` | List of blocked users for deposits | -| `performance` | Vault performance indicator (percent) | -| `osTokenConfig` | contains the ltvPercent, which is the percentage used to calculate how much a user can mint in OsToken shares, and thresholdPercent, which is the liquidation threshold percentage used to calculate the health factor for the OsToken position | +| Name | Description | +|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `version` | Vault version | +| `apy` | Current vault apy | +| `baseApy` | The vault average weekly base APY (without extra incentives) | +| `isErc20` | Does the vault have its own ERC20 token | +| `capacity` | Maximum TVL of Vault | +| `createdAt` | Date of Creation | +| `feePercent` | Commission rate | +| `isPrivate` | Whether the vault is private | +| `isGenesis` | Is a stakewise vault | +| `queuedShares` | The total number of queued shares | +| `isBlocklist` | Whether the vault has blocklist | +| `vaultAdmin` | Vault administrator address | +| `totalAssets` | TVL of Vault | +| `feeRecipient` | Vault fee address | +| `whitelistManager` | Whitelist manager | +| `vaultAddress` | Address of vault | +| `mevRecipient` | Validator fee recipient | +| `whitelistCount` | Number of addresses in the [whitelist](/vault/requests/getwhitelist) | +| `blocklistCount` | Number of addresses in the [blocklist](/vault/requests/getblocklist) | +| `imageUrl` | Link for vault logo | +| `blocklistManager` | Blocklist manager | +| `depositDataManager` | Keys manager address | +| `isSmoothingPool` | Smoothing poll or Vault escrow | +| `tokenName` | ERC20 token name | +| `tokenSymbol` | ERC20 token symbol | +| `displayName` | Name of vault | +| `allocatorMaxBoostApy` | The average max boost APY earned in this vault by the allocator | +| `osTokenHolderMaxBoostApy` | The average max boost APY earned in this vault by the osToken holder | +| `description` | Description of vault | +| `whitelist` | List of authorized users for deposits | +| `blocklist` | List of blocked users for deposits | +| `performance` | Vault performance indicator (percent) | +| `osTokenConfig` | contains the ltvPercent, which is the percentage used to calculate how much a user can mint in OsToken shares, and thresholdPercent, which is the liquidation threshold percentage used to calculate the health factor for the OsToken position | #### Example: diff --git a/src/methods/vault/requests/getVault/modifyVault.spec.ts b/src/methods/vault/requests/getVault/modifyVault.spec.ts index a31ec746..57674769 100644 --- a/src/methods/vault/requests/getVault/modifyVault.spec.ts +++ b/src/methods/vault/requests/getVault/modifyVault.spec.ts @@ -26,6 +26,7 @@ describe('modifyVault', () => { allocatorMaxBoostApy: '123.2', osTokenHolderMaxBoostApy: '123.2', apy: '2.80', + baseApy: '0.80', queuedShares: '0', blocklistCount: '0', whitelistCount: '0', @@ -52,6 +53,7 @@ describe('modifyVault', () => { it('should correctly transform the vault data', () => { const expectedModifiedVault: ModifiedVault = { apy: 2.80, + baseApy: 0.80, isErc20: true, feePercent: 2, version: 1, diff --git a/src/methods/vault/requests/getVault/modifyVault.ts b/src/methods/vault/requests/getVault/modifyVault.ts index c385af3c..f536e721 100644 --- a/src/methods/vault/requests/getVault/modifyVault.ts +++ b/src/methods/vault/requests/getVault/modifyVault.ts @@ -23,6 +23,7 @@ const modifyVault = (input: ModifyVaultInput): ModifiedVault => { admin, address, version, + baseApy, mevEscrow, createdAt, feePercent, @@ -43,6 +44,7 @@ const modifyVault = (input: ModifyVaultInput): ModifiedVault => { return { ...rest, apy: Number(apy), + baseApy: Number(baseApy), version: Number(version), isSmoothingPool: !mevEscrow, feePercent: feePercent / 100, diff --git a/src/methods/vault/requests/getVault/types.ts b/src/methods/vault/requests/getVault/types.ts index bcfa34d3..9b1a7232 100644 --- a/src/methods/vault/requests/getVault/types.ts +++ b/src/methods/vault/requests/getVault/types.ts @@ -6,6 +6,7 @@ export type ModifiedVault = Omit< 'apy' | 'admin' | 'address' + | 'baseApy' | 'version' | 'createdAt' | 'mevEscrow' @@ -18,6 +19,7 @@ export type ModifiedVault = Omit< | 'osTokenHolderMaxBoostApy' > & { apy: number + baseApy: number version: number createdAt: number vaultAdmin: string diff --git a/src/utils/configs/chiado.ts b/src/utils/configs/chiado.ts index 14750f6c..7ac05589 100644 --- a/src/utils/configs/chiado.ts +++ b/src/utils/configs/chiado.ts @@ -14,6 +14,7 @@ export default { }, addresses: { tokens: { + ssv: ZeroAddress, swise: '0x460d2c6c3254809949a7d0b4646ce15F77e9c545', mintToken: '0x0b4F6bFB694790051E0203Db83edbB5888099556', depositToken: '0x19C653Da7c37c66208fbfbE8908A5051B57b4C70', @@ -48,6 +49,7 @@ export default { }, }, tokens: { + ssv: constants.tokens.ssv, swise: constants.tokens.swise, mintToken: constants.tokens.osGNO, nativeToken: constants.tokens.xdai, diff --git a/src/utils/configs/gnosis.ts b/src/utils/configs/gnosis.ts index e342257f..dd5ab606 100644 --- a/src/utils/configs/gnosis.ts +++ b/src/utils/configs/gnosis.ts @@ -14,6 +14,7 @@ export default { }, addresses: { tokens: { + ssv: ZeroAddress, swise: '0xfdA94F056346d2320d4B5E468D6Ad099b2277746', mintToken: '0xF490c80aAE5f2616d3e3BDa2483E30C4CB21d1A0', depositToken: '0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb', @@ -48,6 +49,7 @@ export default { }, }, tokens: { + ssv: constants.tokens.ssv, swise: constants.tokens.swise, mintToken: constants.tokens.osGNO, nativeToken: constants.tokens.xdai, diff --git a/src/utils/configs/holesky.ts b/src/utils/configs/holesky.ts index da82a369..0c605e1f 100644 --- a/src/utils/configs/holesky.ts +++ b/src/utils/configs/holesky.ts @@ -14,9 +14,10 @@ export default { }, addresses: { tokens: { + ssv: ZeroAddress, + depositToken: ZeroAddress, swise: '0x484871C6D54a3dAEBeBBDB0AB7a54c97D72986Bb', mintToken: '0xF603c5A3F774F05d4D848A9bB139809790890864', - depositToken: ZeroAddress, v2RewardToken: '0x2ee2E20702B5881a1171c5dbEd01C3d1e49Bf632', v2StakedToken: '0x91167861c590Fd68bEbE662951fBE30C9B23D759', }, @@ -48,6 +49,7 @@ export default { }, }, tokens: { + ssv: constants.tokens.ssv, swise: constants.tokens.swise, mintToken: constants.tokens.osETH, nativeToken: constants.tokens.eth, diff --git a/src/utils/configs/mainnet.ts b/src/utils/configs/mainnet.ts index 8333fc50..b567b150 100644 --- a/src/utils/configs/mainnet.ts +++ b/src/utils/configs/mainnet.ts @@ -19,6 +19,7 @@ export default { }, addresses: { tokens: { + ssv: '0x9d65ff81a3c488d585bbfb0bfe3c7707c7917f54', swise: '0x48C3399719B582dD63eB5AADf12A40B4C3f52FA2', mintToken: '0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38', depositToken: ZeroAddress, @@ -53,6 +54,7 @@ export default { }, }, tokens: { + ssv: constants.tokens.ssv, swise: constants.tokens.swise, mintToken: constants.tokens.osETH, nativeToken: constants.tokens.eth, diff --git a/src/utils/constants/tokens.ts b/src/utils/constants/tokens.ts index 0f889cc5..b91b0e99 100644 --- a/src/utils/constants/tokens.ts +++ b/src/utils/constants/tokens.ts @@ -1,6 +1,7 @@ export default { // Mainnet eth: 'ETH', + ssv: 'SSV', swise: 'SWISE', osETH: 'osETH', From 85fb9e872f6c8648569de9def35d5fab972acbab Mon Sep 17 00:00:00 2001 From: dfkadyr-stakewise Date: Fri, 7 Mar 2025 11:05:47 +0300 Subject: [PATCH 2/4] [base-apy] update md doc --- .../vault/requests/getVault/getVault.md | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/methods/vault/requests/getVault/getVault.md b/src/methods/vault/requests/getVault/getVault.md index f065bc74..af87f8ac 100644 --- a/src/methods/vault/requests/getVault/getVault.md +++ b/src/methods/vault/requests/getVault/getVault.md @@ -51,41 +51,41 @@ type Output = { } ``` -| Name | Description | -|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `version` | Vault version | -| `apy` | Current vault apy | -| `baseApy` | The vault average weekly base APY (without extra incentives) | -| `isErc20` | Does the vault have its own ERC20 token | -| `capacity` | Maximum TVL of Vault | -| `createdAt` | Date of Creation | -| `feePercent` | Commission rate | -| `isPrivate` | Whether the vault is private | -| `isGenesis` | Is a stakewise vault | -| `queuedShares` | The total number of queued shares | -| `isBlocklist` | Whether the vault has blocklist | -| `vaultAdmin` | Vault administrator address | -| `totalAssets` | TVL of Vault | -| `feeRecipient` | Vault fee address | -| `whitelistManager` | Whitelist manager | -| `vaultAddress` | Address of vault | -| `mevRecipient` | Validator fee recipient | -| `whitelistCount` | Number of addresses in the [whitelist](/vault/requests/getwhitelist) | -| `blocklistCount` | Number of addresses in the [blocklist](/vault/requests/getblocklist) | -| `imageUrl` | Link for vault logo | -| `blocklistManager` | Blocklist manager | -| `depositDataManager` | Keys manager address | -| `isSmoothingPool` | Smoothing poll or Vault escrow | -| `tokenName` | ERC20 token name | -| `tokenSymbol` | ERC20 token symbol | -| `displayName` | Name of vault | -| `allocatorMaxBoostApy` | The average max boost APY earned in this vault by the allocator | -| `osTokenHolderMaxBoostApy` | The average max boost APY earned in this vault by the osToken holder | -| `description` | Description of vault | -| `whitelist` | List of authorized users for deposits | -| `blocklist` | List of blocked users for deposits | -| `performance` | Vault performance indicator (percent) | -| `osTokenConfig` | contains the ltvPercent, which is the percentage used to calculate how much a user can mint in OsToken shares, and thresholdPercent, which is the liquidation threshold percentage used to calculate the health factor for the OsToken position | +| Name | Description | +|-----------------------------|-------------------------------------------------| +| `version` | Vault version | +| `apy` | Current vault apy | +| `baseApy` | The vault average weekly base APY (without extra incentives) | +| `isErc20` | Does the vault have its own ERC20 token | +| `capacity` | Maximum TVL of Vault | +| `createdAt` | Date of Creation | +| `feePercent` | Commission rate | +| `isPrivate` | Whether the vault is private | +| `isGenesis` | Is a stakewise vault | +| `queuedShares` | The total number of queued shares | +| `isBlocklist` | Whether the vault has blocklist | +| `vaultAdmin` | Vault administrator address | +| `totalAssets` | TVL of Vault | +| `feeRecipient` | Vault fee address | +| `whitelistManager` | Whitelist manager | +| `vaultAddress` | Address of vault | +| `mevRecipient` | Validator fee recipient | +| `whitelistCount` | Number of addresses in the [whitelist](/vault/requests/getwhitelist) | +| `blocklistCount` | Number of addresses in the [blocklist](/vault/requests/getblocklist) | +| `imageUrl` | Link for vault logo | +| `blocklistManager` | Blocklist manager | +| `depositDataManager` | Keys manager address | +| `isSmoothingPool` | Smoothing poll or Vault escrow | +| `tokenName` | ERC20 token name | +| `tokenSymbol` | ERC20 token symbol | +| `displayName` | Name of vault | +| `allocatorMaxBoostApy` | The average max boost APY earned in this vault by the allocator | +| `osTokenHolderMaxBoostApy` | The average max boost APY earned in this vault by the osToken holder | +| `description` | Description of vault | +| `whitelist` | List of authorized users for deposits | +| `blocklist` | List of blocked users for deposits | +| `performance` | Vault performance indicator (percent) | +| `osTokenConfig` | contains the ltvPercent, which is the percentage used to calculate how much a user can mint in OsToken shares, and thresholdPercent, which is the liquidation threshold percentage used to calculate the health factor for the OsToken position | #### Example: From cb08eccb71b8168756d22909c8fed7a8bf044578 Mon Sep 17 00:00:00 2001 From: dfkadyr-stakewise Date: Fri, 7 Mar 2025 16:25:20 +0300 Subject: [PATCH 3/4] [base-apy] add getPeriodicDistributions method --- changelog/next-release.md | 19 +++++- src/graphql/subgraph/vault/index.ts | 3 + .../vault/periodicDistributionsQuery.graphql | 13 +++++ src/methods/vault/index.ts | 6 ++ .../getPeriodicDistributions.md | 40 +++++++++++++ .../getPeriodicDistributions/index.ts | 33 +++++++++++ .../modifyPeriodicDistributions.spec.ts | 58 +++++++++++++++++++ .../modifyPeriodicDistributions.ts | 33 +++++++++++ .../getPeriodicDistributions/types.d.ts | 14 +++++ 9 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 src/graphql/subgraph/vault/periodicDistributionsQuery.graphql create mode 100644 src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md create mode 100644 src/methods/vault/requests/getPeriodicDistributions/index.ts create mode 100644 src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.spec.ts create mode 100644 src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.ts create mode 100644 src/methods/vault/requests/getPeriodicDistributions/types.d.ts diff --git a/changelog/next-release.md b/changelog/next-release.md index c2d71edb..4112c87b 100644 --- a/changelog/next-release.md +++ b/changelog/next-release.md @@ -1,5 +1,20 @@ # New ---- +### 1. Add SSV token to config + +### 2. Add new method [sdk.vault.getPeriodicDistributions](https://sdk.stakewise.io/vault/requests/getperiodicdistributions) +Getting the periodic distribution of additional incentives + +```ts +type Output = Array<{ + apy: string + token: string +}> +``` + +| Name | Description | +|---------------------|-------------------------| +| `apy` | The average weekly apy of the distribution | +| `token` | The address of the token that is distributed | # Updates ### 1. [sdk.vault.getStakeBalance](https://sdk.stakewise.io/vault/requests/getstakebalance) @@ -30,5 +45,3 @@ type Output = { | Name | Description | |-----------|--------------------------------------------------------------| | `baseApy` | The vault average weekly base APY (without extra incentives) | - -### 3. Add SSV token to config diff --git a/src/graphql/subgraph/vault/index.ts b/src/graphql/subgraph/vault/index.ts index 7bd250b2..cc63fdb5 100644 --- a/src/graphql/subgraph/vault/index.ts +++ b/src/graphql/subgraph/vault/index.ts @@ -18,3 +18,6 @@ export type { WhitelistAccountsQueryPayload, WhitelistAccountsQueryVariables } f export { fetchBlocklistAccountsQuery } from './blocklistAccountsQuery.graphql' export type { BlocklistAccountsQueryPayload, BlocklistAccountsQueryVariables } from './blocklistAccountsQuery.graphql' + +export { fetchPeriodicDistributionsQuery } from './periodicDistributionsQuery.graphql' +export type { PeriodicDistributionsQueryPayload, PeriodicDistributionsQueryVariables } from './periodicDistributionsQuery.graphql' diff --git a/src/graphql/subgraph/vault/periodicDistributionsQuery.graphql b/src/graphql/subgraph/vault/periodicDistributionsQuery.graphql new file mode 100644 index 00000000..d92aa15a --- /dev/null +++ b/src/graphql/subgraph/vault/periodicDistributionsQuery.graphql @@ -0,0 +1,13 @@ +query PeriodicDistributions($vaultAddress: Bytes!, $startTimestamp: BigInt, $endTimestamp: BigInt) { + periodicDistributions( + where: { + data: $vaultAddress, + distributionType: VAULT, + endTimestamp_gte: $endTimestamp + startTimestamp_lte: $startTimestamp, + } + ) { + apy + token + } +} diff --git a/src/methods/vault/index.ts b/src/methods/vault/index.ts index 1d9f1b37..99b82093 100644 --- a/src/methods/vault/index.ts +++ b/src/methods/vault/index.ts @@ -13,6 +13,7 @@ import getHarvestParams from './requests/getHarvestParams' import getStakerActions from './requests/getStakerActions' import getRewardSplitters from './requests/getRewardSplitters' import getExitQueuePositions from './requests/getExitQueuePositions' +import getPeriodicDistributions from './requests/getPeriodicDistributions' // Transactions import { default as create } from './transactions/create' @@ -104,6 +105,11 @@ export default { * @see https://sdk.stakewise.io/vault/requests/getuserapy */ getUserApy, + /** + * @description Getting the periodic distribution of additional incentives. + * @see https://sdk.stakewise.io/vault/requests/getperiodicdistributions + */ + getPeriodicDistributions, }, transactions: { /** diff --git a/src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md b/src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md new file mode 100644 index 00000000..ed40e1a2 --- /dev/null +++ b/src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md @@ -0,0 +1,40 @@ +--- +id: getPeriodicDistributions +slug: /vault/requests/getperiodicdistributions +--- + +#### Description: + +Getting the periodic distribution of additional incentives + +#### Arguments: + +| Name | Type | Required | Description | +|--------------|----------|----------|---------------------------| +| vaultAddress | `string` | **Yes** | The address of the vault | +| endTimestamp | `string` | **Yes** | The timestamp when the distribution ends | +| startTimestamp | `string` | **Yes** | The timestamp when the distribution starts | + +#### Returns: + +```ts +type Output = Array<{ + apy: string + token: string +}> +``` + +| Name | Description | +|---------------------|-------------------------| +| `apy` | The average weekly apy of the distribution | +| `token` | The address of the token that is distributed | + +#### Example: + +```ts +await sdk.vault.getPeriodicDistributions({ + userAddress: '0x...', + endTimestamp: '1741346116', + startTimestamp: '1741346116', +}) +``` diff --git a/src/methods/vault/requests/getPeriodicDistributions/index.ts b/src/methods/vault/requests/getPeriodicDistributions/index.ts new file mode 100644 index 00000000..cb94e6b6 --- /dev/null +++ b/src/methods/vault/requests/getPeriodicDistributions/index.ts @@ -0,0 +1,33 @@ +import type { PeriodicDistributionsQueryPayload } from '../../../../graphql/subgraph/vault' +import { apiUrls, validateArgs } from '../../../../utils' +import graphql from '../../../../graphql' + +import modifyPeriodicDistributions from './modifyPeriodicDistributions' + + +type GetPeriodicDistributionsInput = { + vaultAddress: string + endTimestamp: string + startTimestamp: string + options: StakeWise.Options +} + +const getPeriodicDistributions = (values: GetPeriodicDistributionsInput) => { + const { options, vaultAddress, startTimestamp, endTimestamp } = values + + validateArgs.address({ vaultAddress }) + validateArgs.string({ startTimestamp, endTimestamp }) + + return graphql.subgraph.vault.fetchPeriodicDistributionsQuery({ + url: apiUrls.getSubgraphqlUrl(options), + variables: { + endTimestamp, + startTimestamp, + vaultAddress: vaultAddress.toLowerCase(), + }, + modifyResult: (data: PeriodicDistributionsQueryPayload) => modifyPeriodicDistributions({ data }), + }) +} + + +export default getPeriodicDistributions diff --git a/src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.spec.ts b/src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.spec.ts new file mode 100644 index 00000000..de5dc7bb --- /dev/null +++ b/src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.spec.ts @@ -0,0 +1,58 @@ +import type { PeriodicDistributionsQueryPayload } from '../../../../graphql/subgraph/vault' + +import modifyPeriodicDistributions from './modifyPeriodicDistributions' + + +describe('modifyPeriodicDistributions', () => { + it('should modify PeriodicDistributions data', () => { + const mockData: PeriodicDistributionsQueryPayload = { + periodicDistributions: [ + { + apy: '0.5', + token: '0x9d65ff81a3c488d585bbfb0bfe3c7707c7917f54', + }, + { + apy: '0.5', + token: '0x48C3399719B582dD63eB5AADf12A40B4C3f52FA2', + }, + { + apy: '0.5', + token: '0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38', + }, + { + apy: '1.5', + token: '0x9d65ff81a3c488d585bbfb0bfe3c7707c7917f54', + }, + { + apy: '2.5', + token: '0x48C3399719B582dD63eB5AADf12A40B4C3f52FA2', + }, + { + apy: '3.5', + token: '0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38', + }, + ], + } + + const expectedOutput = [ + { + apy: '2', + token: '0x9d65ff81a3c488d585bbfb0bfe3c7707c7917f54', + }, + { + apy: '3', + token: '0x48C3399719B582dD63eB5AADf12A40B4C3f52FA2', + }, + { + apy: '4', + token: '0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38', + }, + ] + + const result = modifyPeriodicDistributions({ + data: mockData, + }) + + expect(result).toEqual(expectedOutput) + }) +}) diff --git a/src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.ts b/src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.ts new file mode 100644 index 00000000..82178c0c --- /dev/null +++ b/src/methods/vault/requests/getPeriodicDistributions/modifyPeriodicDistributions.ts @@ -0,0 +1,33 @@ +import type { + AggregatedPayload, + ModifiedPeriodicDistributions, + ModifyPeriodicDistributionsInput, +} from './types' + + +const modifyPeriodicDistributions = (input: ModifyPeriodicDistributionsInput): ModifiedPeriodicDistributions => { + const { data } = input + + const distributions = data?.periodicDistributions || [] + + const aggregatedData = distributions.reduce((acc: Record, { apy, token }) => { + const numericApy = parseFloat(apy) + + if (acc[token]) { + acc[token].apy += numericApy + } + else { + acc[token] = { token, apy: numericApy } + } + + return acc + }, {}) + + return Object.values(aggregatedData).map(item => ({ + token: item.token, + apy: item.apy.toString(), + })) +} + + +export default modifyPeriodicDistributions diff --git a/src/methods/vault/requests/getPeriodicDistributions/types.d.ts b/src/methods/vault/requests/getPeriodicDistributions/types.d.ts new file mode 100644 index 00000000..a60d5785 --- /dev/null +++ b/src/methods/vault/requests/getPeriodicDistributions/types.d.ts @@ -0,0 +1,14 @@ +import type { PeriodicDistributionsQueryPayload } from '../../../../graphql/subgraph/vault' + +export type ModifyPeriodicDistributionsInput = { + data: PeriodicDistributionsQueryPayload +} + +type PeriodicDistributionsPayload = Pick + +export type ModifiedPeriodicDistributions = Array + +export type AggregatedPayload = { + token: string + apy: number +} From 198a754518b6ca03a1ac580054ddcc206dd3f375 Mon Sep 17 00:00:00 2001 From: dfkadyr-stakewise Date: Mon, 10 Mar 2025 10:30:25 +0300 Subject: [PATCH 4/4] [base-apy] update getPeriodicDistributions to use number type for timestamps --- .../getPeriodicDistributions.md | 8 ++++---- .../vault/requests/getPeriodicDistributions/index.ts | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md b/src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md index ed40e1a2..3df6640a 100644 --- a/src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md +++ b/src/methods/vault/requests/getPeriodicDistributions/getPeriodicDistributions.md @@ -12,8 +12,8 @@ Getting the periodic distribution of additional incentives | Name | Type | Required | Description | |--------------|----------|----------|---------------------------| | vaultAddress | `string` | **Yes** | The address of the vault | -| endTimestamp | `string` | **Yes** | The timestamp when the distribution ends | -| startTimestamp | `string` | **Yes** | The timestamp when the distribution starts | +| endTimestamp | `number` | **Yes** | The timestamp when the distribution ends | +| startTimestamp | `number` | **Yes** | The timestamp when the distribution starts | #### Returns: @@ -34,7 +34,7 @@ type Output = Array<{ ```ts await sdk.vault.getPeriodicDistributions({ userAddress: '0x...', - endTimestamp: '1741346116', - startTimestamp: '1741346116', + endTimestamp: 1741346116, + startTimestamp: 1741346116, }) ``` diff --git a/src/methods/vault/requests/getPeriodicDistributions/index.ts b/src/methods/vault/requests/getPeriodicDistributions/index.ts index cb94e6b6..e3b71f7f 100644 --- a/src/methods/vault/requests/getPeriodicDistributions/index.ts +++ b/src/methods/vault/requests/getPeriodicDistributions/index.ts @@ -7,8 +7,8 @@ import modifyPeriodicDistributions from './modifyPeriodicDistributions' type GetPeriodicDistributionsInput = { vaultAddress: string - endTimestamp: string - startTimestamp: string + endTimestamp: number + startTimestamp: number options: StakeWise.Options } @@ -16,13 +16,13 @@ const getPeriodicDistributions = (values: GetPeriodicDistributionsInput) => { const { options, vaultAddress, startTimestamp, endTimestamp } = values validateArgs.address({ vaultAddress }) - validateArgs.string({ startTimestamp, endTimestamp }) + validateArgs.number({ startTimestamp, endTimestamp }) return graphql.subgraph.vault.fetchPeriodicDistributionsQuery({ url: apiUrls.getSubgraphqlUrl(options), variables: { - endTimestamp, - startTimestamp, + endTimestamp: String(endTimestamp), + startTimestamp: String(startTimestamp), vaultAddress: vaultAddress.toLowerCase(), }, modifyResult: (data: PeriodicDistributionsQueryPayload) => modifyPeriodicDistributions({ data }),