From 74f4756879b3cf0d3e3e4700bbf7ec5f047dffc4 Mon Sep 17 00:00:00 2001 From: dfkadyr Date: Tue, 16 Jan 2024 17:44:36 +0300 Subject: [PATCH 1/5] [export]: add export logic --- README.md | 5 +++-- .../backend/vault/userRewardsQuery.graphql | 7 +++++-- .../vault/requests/getUserRewards/index.ts | 8 +++++++- .../getUserRewards/modifyUserRewards.spec.ts | 18 ++++++++++++++++++ .../getUserRewards/modifyUserRewards.ts | 8 ++++++-- .../vault/requests/getUserRewards/types.ts | 4 ++++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6ef9b2d4..8c52b3a4 100644 --- a/README.md +++ b/README.md @@ -251,11 +251,12 @@ Daily rewards for the user who has made a deposit in the vault. With the help of #### Arguments: -| Name | Type | Type | Description | +| Name | Type | Type | Description | |------|----------|-------------|---------| -| dateFrom | `number` | **Require** | Time to start | | vaultAddress | `string` | **Require** | - | | userAddress | `string` | **Require** | - | +| dateFrom | `number` | **Require** | Time to start | +| dateTo | `number` | Time to end | #### Returns: diff --git a/src/graphql/backend/vault/userRewardsQuery.graphql b/src/graphql/backend/vault/userRewardsQuery.graphql index c8dff0f0..e55c7db4 100644 --- a/src/graphql/backend/vault/userRewardsQuery.graphql +++ b/src/graphql/backend/vault/userRewardsQuery.graphql @@ -1,7 +1,10 @@ -query UserRewards($user: String!, $vaultAddress: String!, $dateFrom: DateAsTimestamp!) { - userRewards(user: $user, vaultAddress: $vaultAddress, dateFrom: $dateFrom) { +query UserRewards($user: String!, $vaultAddress: String!, $dateFrom: DateAsTimestamp!, $dateTo: DateAsTimestamp) { + userRewards(user: $user, vaultAddress: $vaultAddress, dateFrom: $dateFrom, dateTo: $dateTo) { date sumRewards dailyRewards + dailyRewardsEur + dailyRewardsGbp + dailyRewardsUsd } } diff --git a/src/methods/vault/requests/getUserRewards/index.ts b/src/methods/vault/requests/getUserRewards/index.ts index f6023b39..25aa8878 100644 --- a/src/methods/vault/requests/getUserRewards/index.ts +++ b/src/methods/vault/requests/getUserRewards/index.ts @@ -10,20 +10,26 @@ type GetUserRewardsInput = { userAddress: UserRewardsQueryVariables['user'] vaultAddress: UserRewardsQueryVariables['vaultAddress'] dateFrom: number + dateTo?: number } const getUserRewards = async (input: GetUserRewardsInput) => { - const { options, vaultAddress, userAddress, dateFrom } = input + const { options, vaultAddress, userAddress, dateFrom, dateTo } = input validateArgs.address({ vaultAddress, userAddress }) validateArgs.number({ dateFrom }) + if (dateTo) { + validateArgs.number({ dateTo }) + } + const data = await graphql.backend.vault.fetchUserRewardsQuery({ url: apiUrls.getBackendUrl(options), variables: { vaultAddress: vaultAddress.toLowerCase(), user: userAddress.toLowerCase(), dateFrom: String(dateFrom), + dateTo: dateTo ? String(dateTo) : null, } as UserRewardsQueryVariables, modifyResult: modifyUserRewards, }) diff --git a/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts b/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts index a13413ea..4423c885 100644 --- a/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts +++ b/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts @@ -9,11 +9,17 @@ describe('modifyUserReward and modifyUserRewards functions', () => { date: '1694908800', sumRewards: '344379922475148628745', dailyRewards: '344379922475148628745', + dailyRewardsEur: "0.10", + dailyRewardsGbp: "0.09", + dailyRewardsUsd: "0.11", }, { date: '1694995200', sumRewards: '344382187878289278175', dailyRewards: '0', + dailyRewardsEur: "0.10", + dailyRewardsGbp: "0.09", + dailyRewardsUsd: "0.11", }, ], } @@ -24,8 +30,12 @@ describe('modifyUserReward and modifyUserRewards functions', () => { const result = modifyUserReward(userReward) expect(result).toEqual({ + date: 1694908800, sumRewards: 344.37992247514865, dailyRewards: 344.37992247514865, + dailyRewardsEur: 0.10, + dailyRewardsGbp: 0.09, + dailyRewardsUsd: 0.11, }) }) @@ -33,12 +43,20 @@ describe('modifyUserReward and modifyUserRewards functions', () => { const expectedResult = { days: { 1694908800: { + date: 1694908800, sumRewards: 344.37992247514865, dailyRewards: 344.37992247514865, + dailyRewardsEur: 0.10, + dailyRewardsGbp: 0.09, + dailyRewardsUsd: 0.11, }, 1694995200: { + date: 1694995200, sumRewards: 344.3821878782893, dailyRewards: 0, + dailyRewardsEur: 0.10, + dailyRewardsGbp: 0.09, + dailyRewardsUsd: 0.11, }, }, } diff --git a/src/methods/vault/requests/getUserRewards/modifyUserRewards.ts b/src/methods/vault/requests/getUserRewards/modifyUserRewards.ts index 47fbd63a..209118c6 100644 --- a/src/methods/vault/requests/getUserRewards/modifyUserRewards.ts +++ b/src/methods/vault/requests/getUserRewards/modifyUserRewards.ts @@ -4,19 +4,23 @@ import { ModifyUserReward } from './types' import type { UserRewardsQueryPayload } from '../../../../graphql/backend/vault' -export const modifyUserReward = (reward: Omit) => { +export const modifyUserReward = (reward: UserRewardsQueryPayload['userRewards'][number]) => { const sumRewards = String(reward.sumRewards) || '0' const dailyRewards = String(reward.dailyRewards) || '0' return { + date: Number(reward.date), sumRewards: Number(formatEther(sumRewards)), dailyRewards: Number(formatEther(dailyRewards)), + dailyRewardsEur: Number(reward.dailyRewardsEur) || 0, + dailyRewardsGbp: Number(reward.dailyRewardsGbp) || 0, + dailyRewardsUsd: Number(reward.dailyRewardsUsd) || 0, } } const modifyUserRewards = (input: UserRewardsQueryPayload): ModifyUserReward => { const days = input.userRewards.reduce((acc, { date, ...rest }) => { - acc[Number(date)] = modifyUserReward(rest) + acc[Number(date)] = modifyUserReward({ date, ...rest }) return acc }, {} as ModifyUserReward['days']) diff --git a/src/methods/vault/requests/getUserRewards/types.ts b/src/methods/vault/requests/getUserRewards/types.ts index b0dff29b..b11cd4d8 100644 --- a/src/methods/vault/requests/getUserRewards/types.ts +++ b/src/methods/vault/requests/getUserRewards/types.ts @@ -1,6 +1,10 @@ type UserReward = { + date: number sumRewards: number dailyRewards: number + dailyRewardsEur: number + dailyRewardsGbp: number + dailyRewardsUsd: number } export type ModifyUserReward = { From 28196281b0c84683015db67850ec228f8441744d Mon Sep 17 00:00:00 2001 From: dfkadyr Date: Wed, 17 Jan 2024 17:50:12 +0300 Subject: [PATCH 2/5] [vault-test]: improves, add new fillGaps --- README.md | 15 ++++++++++----- .../backend/vault/userRewardsQuery.graphql | 4 ++-- .../vault/requests/getUserRewards/index.ts | 18 ++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8c52b3a4..dc3ddac6 100644 --- a/README.md +++ b/README.md @@ -252,22 +252,27 @@ Daily rewards for the user who has made a deposit in the vault. With the help of #### Arguments: | Name | Type | Type | Description | -|------|----------|-------------|---------| +|------|----------|-------------|---| | vaultAddress | `string` | **Require** | - | | userAddress | `string` | **Require** | - | | dateFrom | `number` | **Require** | Time to start | -| dateTo | `number` | Time to end | +| dateTo | `number` | **Optional** | Time to end | +| fillGaps | `boolean` | **Optional** | To fill in all the days, or not | #### Returns: ```ts type UserReward = { - sumRewards: number - dailyRewards: number + date: number + sumRewards: string + dailyRewards: string + dailyRewardsEur: string + dailyRewardsGbp: string + dailyRewardsUsd: string } type Output = { - days: Record + days: Record | [] } ``` diff --git a/src/graphql/backend/vault/userRewardsQuery.graphql b/src/graphql/backend/vault/userRewardsQuery.graphql index e55c7db4..dc89e39f 100644 --- a/src/graphql/backend/vault/userRewardsQuery.graphql +++ b/src/graphql/backend/vault/userRewardsQuery.graphql @@ -1,5 +1,5 @@ -query UserRewards($user: String!, $vaultAddress: String!, $dateFrom: DateAsTimestamp!, $dateTo: DateAsTimestamp) { - userRewards(user: $user, vaultAddress: $vaultAddress, dateFrom: $dateFrom, dateTo: $dateTo) { +query UserRewards($user: String!, $vaultAddress: String!, $dateFrom: DateAsTimestamp!, $dateTo: DateAsTimestamp, $fillGaps: Boolean = true) { + userRewards(user: $user, vaultAddress: $vaultAddress, dateFrom: $dateFrom, dateTo: $dateTo, fillGaps: $fillGaps) { date sumRewards dailyRewards diff --git a/src/methods/vault/requests/getUserRewards/index.ts b/src/methods/vault/requests/getUserRewards/index.ts index 25aa8878..06216d75 100644 --- a/src/methods/vault/requests/getUserRewards/index.ts +++ b/src/methods/vault/requests/getUserRewards/index.ts @@ -9,27 +9,29 @@ type GetUserRewardsInput = { options: StakeWise.Options userAddress: UserRewardsQueryVariables['user'] vaultAddress: UserRewardsQueryVariables['vaultAddress'] - dateFrom: number - dateTo?: number + dateFrom: string + dateTo?: string + fillGaps?: boolean } const getUserRewards = async (input: GetUserRewardsInput) => { - const { options, vaultAddress, userAddress, dateFrom, dateTo } = input + const { options, vaultAddress, userAddress, dateFrom, dateTo, fillGaps } = input validateArgs.address({ vaultAddress, userAddress }) - validateArgs.number({ dateFrom }) + validateArgs.string({ dateFrom }) if (dateTo) { - validateArgs.number({ dateTo }) + validateArgs.string({ dateTo }) } const data = await graphql.backend.vault.fetchUserRewardsQuery({ url: apiUrls.getBackendUrl(options), variables: { - vaultAddress: vaultAddress.toLowerCase(), + dateTo, + dateFrom, + fillGaps, user: userAddress.toLowerCase(), - dateFrom: String(dateFrom), - dateTo: dateTo ? String(dateTo) : null, + vaultAddress: vaultAddress.toLowerCase(), } as UserRewardsQueryVariables, modifyResult: modifyUserRewards, }) From 81c174f777f522f6a79c00dc9caad62780ff5b6a Mon Sep 17 00:00:00 2001 From: dfkadyr Date: Wed, 17 Jan 2024 17:55:33 +0300 Subject: [PATCH 3/5] [vault-test]: improves PR --- .../getUserRewards/modifyUserRewards.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts b/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts index 4423c885..7531a966 100644 --- a/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts +++ b/src/methods/vault/requests/getUserRewards/modifyUserRewards.spec.ts @@ -9,17 +9,17 @@ describe('modifyUserReward and modifyUserRewards functions', () => { date: '1694908800', sumRewards: '344379922475148628745', dailyRewards: '344379922475148628745', - dailyRewardsEur: "0.10", - dailyRewardsGbp: "0.09", - dailyRewardsUsd: "0.11", + dailyRewardsEur: '0.10', + dailyRewardsGbp: '0.09', + dailyRewardsUsd: '0.11', }, { date: '1694995200', sumRewards: '344382187878289278175', dailyRewards: '0', - dailyRewardsEur: "0.10", - dailyRewardsGbp: "0.09", - dailyRewardsUsd: "0.11", + dailyRewardsEur: '0.10', + dailyRewardsGbp: '0.09', + dailyRewardsUsd: '0.11', }, ], } From c3e018f465232c1dfef1579ad441df687d874d1e Mon Sep 17 00:00:00 2001 From: dfkadyr Date: Thu, 18 Jan 2024 11:43:24 +0300 Subject: [PATCH 4/5] [vault-test]: improves PR --- README.md | 4 ++-- src/methods/vault/requests/getUserRewards/index.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index dc3ddac6..c8a40d5e 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ Daily rewards for the user who has made a deposit in the vault. With the help of | userAddress | `string` | **Require** | - | | dateFrom | `number` | **Require** | Time to start | | dateTo | `number` | **Optional** | Time to end | -| fillGaps | `boolean` | **Optional** | To fill in all the days, or not | +| fillGaps | `boolean` | **Optional** | Fill in the empty days with zeros | #### Returns: @@ -272,7 +272,7 @@ type UserReward = { } type Output = { - days: Record | [] + days: Record } ``` diff --git a/src/methods/vault/requests/getUserRewards/index.ts b/src/methods/vault/requests/getUserRewards/index.ts index 06216d75..bd93ae94 100644 --- a/src/methods/vault/requests/getUserRewards/index.ts +++ b/src/methods/vault/requests/getUserRewards/index.ts @@ -9,8 +9,8 @@ type GetUserRewardsInput = { options: StakeWise.Options userAddress: UserRewardsQueryVariables['user'] vaultAddress: UserRewardsQueryVariables['vaultAddress'] - dateFrom: string - dateTo?: string + dateFrom: number + dateTo?: number fillGaps?: boolean } @@ -18,19 +18,19 @@ const getUserRewards = async (input: GetUserRewardsInput) => { const { options, vaultAddress, userAddress, dateFrom, dateTo, fillGaps } = input validateArgs.address({ vaultAddress, userAddress }) - validateArgs.string({ dateFrom }) + validateArgs.number({ dateFrom }) if (dateTo) { - validateArgs.string({ dateTo }) + validateArgs.number({ dateTo }) } const data = await graphql.backend.vault.fetchUserRewardsQuery({ url: apiUrls.getBackendUrl(options), variables: { - dateTo, - dateFrom, fillGaps, + dateFrom: String(dateFrom), user: userAddress.toLowerCase(), + dateTo: dateTo ? String(dateTo) : undefined, vaultAddress: vaultAddress.toLowerCase(), } as UserRewardsQueryVariables, modifyResult: modifyUserRewards, From 0917f09801a88ec6a5f4b77bd2e55573246cd9ba Mon Sep 17 00:00:00 2001 From: dfkadyr Date: Fri, 19 Jan 2024 18:30:57 +0300 Subject: [PATCH 5/5] [export]: improve mobile version, add new Transferred type --- src/utils/enums.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/enums.ts b/src/utils/enums.ts index dbd385f7..0e9c2eac 100644 --- a/src/utils/enums.ts +++ b/src/utils/enums.ts @@ -9,6 +9,7 @@ export enum AllocatorActionType { Redeemed = 'Redeemed', Migrated = 'Migrated', Deposited = 'Deposited', + Transferred = 'Transferred', VaultCreated = 'VaultCreated', OsTokenMinted = 'OsTokenMinted', OsTokenBurned = 'OsTokenBurned',