-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new methods getFiatRates & getUserExchangeRewards (#179)
* add new methods getFiatRates & getUserExchangeRewards * remove unused * update text in docs * remove usdToDaiRate * remove unused methods, update docs * update docs * improve date in milliseconds
- Loading branch information
Showing
19 changed files
with
275 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query FiatRates { | ||
networks { | ||
assetsUsdRate | ||
usdToEurRate | ||
usdToGbpRate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export { fetchStatsQuery } from './statsQuery.graphql' | ||
export type { StatsQueryPayload, StatsQueryVariables } from './statsQuery.graphql' | ||
|
||
export { fetchFiatRatesQuery } from './fiatRatesQuery.graphql' | ||
export type { FiatRatesQueryPayload, FiatRatesQueryVariables } from './fiatRatesQuery.graphql' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
query UserRewards($user: Bytes!, $vaultAddress: String!, $dateFrom: Timestamp!, $dateTo: Timestamp!) { | ||
exchangeRate: exchangeRateStats_collection( | ||
interval: day | ||
where: { timestamp_gte: $dateFrom, timestamp_lte: $dateTo } | ||
) { | ||
timestamp | ||
assetsUsdRate | ||
usdToEurRate | ||
usdToGbpRate | ||
} | ||
allocator: allocatorStats_collection( | ||
interval: day | ||
where: { timestamp_gte: $dateFrom, timestamp_lte: $dateTo, allocator_: { address: $user, vault: $vaultAddress } } | ||
) { | ||
timestamp | ||
earnedAssets | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import graphql from '../../graphql' | ||
import { apiUrls, configs, Network } from '../../utils' | ||
|
||
|
||
type GetFiatRatesInput = { | ||
options: StakeWise.Options | ||
} | ||
|
||
const getMainnetGbpRate = () => { | ||
return graphql.subgraph.stats.fetchFiatRatesQuery({ | ||
url: configs[Network.Mainnet].api.subgraph, | ||
modifyResult: (data): number => { | ||
const usdInGbp = Number(data.networks[0].usdToGbpRate) | ||
|
||
return usdInGbp | ||
}, | ||
}) | ||
} | ||
|
||
const getFiatRates = (values: GetFiatRatesInput) => { | ||
const { options } = values | ||
|
||
return graphql.subgraph.stats.fetchFiatRatesQuery({ | ||
url: apiUrls.getSubgraphqlUrl(options), | ||
modifyResult: async (data) => { | ||
const usd = Number(data.networks[0].assetsUsdRate) | ||
const usdInEur = Number(data.networks[0].usdToEurRate) | ||
|
||
const isGnosis = [ Network.Gnosis, Network.Chiado ].includes(options.network) | ||
const usdInGbp = isGnosis ? await getMainnetGbpRate() : Number(data.networks[0].usdToGbpRate) | ||
|
||
return { | ||
assetsUsdRate: usd, | ||
usdToEurRate: usdInEur, | ||
usdToGbpRate: usdInGbp, | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
|
||
export default getFiatRates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.