Skip to content

Commit

Permalink
Merge branch 'update-staking-rewards-api' into release-v0.5.15
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon committed Oct 9, 2023
2 parents a58c10d + c72e7bb commit 186ebb4
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions services/servicesMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,24 @@ function ServicesMonitor() {
try {
const opts = {
headers: {
'Authorization': `${stakingRewardsKey}`
'X-API-KEY': `${stakingRewardsKey}`
},
...gotOpts
}
const assets = await got.get('https://api-beta.stakingrewards.com/v1/list/assets', opts).json()
const providers = await got.get('https://api-beta.stakingrewards.com/v1/list/providers', opts).json()
const assetResponse = await got.post('https://api.stakingrewards.com/public/query', { ...opts, json:
{
query: `
{
assets (where: { tags: { tagKeys: ["cosmos-ecosystem"]} }, limit: 500) {
name
slug
symbol
}
}
`
}
}).json()
const assets = assetResponse.data.assets

await Promise.all([...chains].map((chain) => {
const request = async () => {
Expand All @@ -158,19 +170,37 @@ function ServicesMonitor() {
await client.json.set('chains:' + chain.path, '$', {}, { NX: true });
await client.json.set('chains:' + chain.path, '$.services', {}, { NX: true });
await client.json.set('chains:' + chain.path, '$.services.staking_rewards', asset);
const assetProviders = await got.get(`https://api-beta.stakingrewards.com/v1/assets/providers/${asset.slug}`, opts).json()
const providerResponse = await got.post('https://api.stakingrewards.com/public/query', { ...opts, json:
{
query: `
{
rewardOptions(where: {inputAsset: {slugs: ["${asset.slug}"]}, providers: {isVerified: true}, typeKeys: ["pos"]}, limit: 500, order: {metricKey_desc: "staked_tokens"}) {
providers(limit: 1) {
name
isVerified
slug
}
validators(limit: 100) {
address
}
}
}
`
}
}).json()
const providers = providerResponse.data.rewardOptions
const validators = await client.json.get('validators:' + chain.path, '$') || {}
const calls = Object.entries(validators.validators).map(([address, validator]) => {
return async () => {
const assetProvider = assetProviders.providers.find(provider => {
return provider.staking.find(el => el.address === address)
const assetProvider = providers.find(provider => {
return provider.validators.find(el => el.address === address)
})
if (assetProvider) {
const provider = providers.find(el => el.name === assetProvider.name)
const provider = assetProvider.providers[0]
await client.json.set('validators:' + chain.path, `$.validators.${address}.services`, {}, { NX: true });
await client.json.set('validators:' + chain.path, `$.validators.${address}.services.staking_rewards`, {
name: assetProvider.name,
verified: assetProvider.isVerified,
name: provider.name,
verified: provider.isVerified,
slug: provider.slug
});
}
Expand Down

0 comments on commit 186ebb4

Please sign in to comment.