Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions services/servicesMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const COINGECKO_THROTTLE = process.env.COINGECKO_THROTTLE ?? 5000
function ServicesMonitor() {
const agent = createAgent();
const chainQueue = new PQueue({ concurrency: 20 });
const serviceQueue = new PQueue({ concurrency: 10 });
const stakingRewardsQueue = new PQueue({ concurrency: 1 });
const coingeckoQueue = new PQueue({ concurrency: 1 });
const gotOpts = {
timeout: { request: 60000 },
Expand Down Expand Up @@ -45,9 +45,9 @@ function ServicesMonitor() {
const url = apis.bestAddress('rest')
if(url){
const delegations = await getDelegationInfo(url, validator, chain)
await client.json.set('validators:' + chain.path, `$.validators.${address}.delegations`, delegations)
await client.json.set('validators:' + chain.path, `$.validators["${address}"].delegations`, delegations)
const slashes = chain.config.monitor.slashes ? (await getSlashes(url, height, validator.operator_address)) : null
await client.json.set('validators:' + chain.path, `$.validators.${address}.slashes`, slashes)
await client.json.set('validators:' + chain.path, `$.validators["${address}"].slashes`, slashes)

// throttle as these requests are heavy
await new Promise(r => setTimeout(r, VALIDATOR_THROTTLE));
Expand Down Expand Up @@ -164,11 +164,17 @@ function ServicesMonitor() {
await Promise.all([...chains].map((chain) => {
const request = async () => {
try {
const asset = assets.find(el => chain.symbol && el.symbol === chain.symbol.toUpperCase())
let asset
if(!['nomic'].includes(chain.path)){
asset = assets.find(el => chain.symbol && el.symbol === chain.symbol.toUpperCase())
}
const validators = await client.json.get('validators:' + chain.path, '$')
if (asset) {
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);
if(!validators?.validators) return

const providerResponse = await got.post('https://api.stakingrewards.com/public/query', { ...opts, json:
{
query: `
Expand All @@ -188,18 +194,15 @@ function ServicesMonitor() {
}
}).json()
const providers = providerResponse.data.rewardOptions
const validators = await client.json.get('validators:' + chain.path, '$')
if(!validators?.validators) return

const calls = Object.entries(validators.validators).map(([address, validator]) => {
return async () => {
const assetProvider = providers.find(provider => {
return provider.validators.find(el => el.address === address)
return provider.validators?.find(el => el.address === address)
})
if (assetProvider?.providers) {
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`, {
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: provider.name,
verified: provider.isVerified,
slug: provider.slug
Expand All @@ -211,10 +214,19 @@ function ServicesMonitor() {
debugLog(chain.path, 'Staking Rewards update complete')
} else {
debugLog(chain.path, 'Staking Rewards asset not found')
await client.json.del('chains:' + chain.path, '$.services.staking_rewards');
if(!validators?.validators) return

const calls = Object.entries(validators.validators).map(([address, validator]) => {
return async () => {
await client.json.del('validators:' + chain.path, `$.validators["${address}"].services.staking_rewards`);
}
})
await executeSync(calls, 20)
}
} catch (e) { timeStamp(chain.path, 'Staking Rewards check failed', e.message) }
};
return serviceQueue.add(request, { identifier: chain.path });
return stakingRewardsQueue.add(request, { identifier: chain.path });
}));
debugLog('Staking Rewards update complete')
} catch (e) { timeStamp('Staking Rewards check failed', e.message) }
Expand Down
4 changes: 2 additions & 2 deletions validators/validatorImageMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ function ValidatorImageMonitor() {
try {
const mintscan_image = `https://raw.githubusercontent.com/cosmostation/chainlist/main/chain/${chain.mintscanPath()}/moniker/${address}.png`
await got.get(mintscan_image, gotOpts)
await client.json.set('validators:' + chain.path, '$.validators.' + address + '.mintscan_image', mintscan_image);
await client.json.set('validators:' + chain.path, `$.validators["${address}"].mintscan_image`, mintscan_image);
} catch { }
if (validator.description?.identity) {
try {
const response = await got.get("https://keybase.io/_/api/1.0/user/lookup.json?fields=pictures&key_suffix=" + validator.description.identity, gotOpts)
if (response && response.body) {
const data = JSON.parse(response.body)
if (data.them && data.them[0] && data.them[0].pictures) {
await client.json.set('validators:' + chain.path, '$.validators.' + address + '.keybase_image', data.them[0].pictures.primary?.url);
await client.json.set('validators:' + chain.path, `$.validators["${address}"].keybase_image`, data.them[0].pictures.primary?.url);
}
}
} catch (e) {
Expand Down