diff --git a/data/networks.js b/data/networks.js index 8c280387c7..d802998f4b 100644 --- a/data/networks.js +++ b/data/networks.js @@ -121,7 +121,7 @@ module.exports = [ id: 'terra-testnet', title: 'Terra Testnet', chain_id: 'soju-0013', - api_url: 'https://terra-testnet.lunie.io', + api_url: 'https://soju-fcd.terra.dev', rpc_url: 'wss://terra-testnet.lunie.io/websocket', bech32_prefix: 'terra', address_prefix: 'terra', @@ -186,7 +186,7 @@ module.exports = [ enabled: true, icon: 'https://app.lunie.io/img/networks/emoney-testnet.png', slug: 'emoney-testnet' - }, + } // { // id: 'polkadot-testnet', // title: 'Kusama', diff --git a/lib/block-listeners/cosmos-node-subscription.js b/lib/block-listeners/cosmos-node-subscription.js index a344c32708..9d706d90f6 100644 --- a/lib/block-listeners/cosmos-node-subscription.js +++ b/lib/block-listeners/cosmos-node-subscription.js @@ -108,7 +108,7 @@ class CosmosNodeSubscription { }) }) } catch (error) { - console.error('newBlockHandler failed') + console.error('newBlockHandler failed', error) Sentry.captureException(error) } this.cosmosAPI.memoizedResults.clear() diff --git a/lib/source/cosmosV2-source.js b/lib/source/cosmosV2-source.js index b5ccf26c2f..1979bdaa5e 100644 --- a/lib/source/cosmosV2-source.js +++ b/lib/source/cosmosV2-source.js @@ -6,9 +6,9 @@ class CosmosV2API extends CosmosV0API { this.reducers = require('../reducers/cosmosV2-reducers') } - async query(url) { + async query(url, resultSelector = 'result') { const response = await this.getRetry(url) - return response.result + return response[resultSelector] } async getValidatorSigningInfos() { diff --git a/lib/source/emoneyV0-source.js b/lib/source/emoneyV0-source.js index 8963c4815a..9d06a8e659 100644 --- a/lib/source/emoneyV0-source.js +++ b/lib/source/emoneyV0-source.js @@ -1,4 +1,5 @@ const TerraV3API = require('./terraV3-source') +const CosmosV0API = require('./cosmosV0-source') const BigNumber = require('bignumber.js') const fetch = require('node-fetch') const apiURL = `https://api.exchangeratesapi.io/latest?` @@ -55,6 +56,14 @@ class EMoneyV0API extends TerraV3API { return await mapTotalBackedValues() } + getAnnualProvision() { + return 0 + } + + async getAllValidators() { + return CosmosV0API.prototype.getAllValidators.call(this) + } + async getExpectedReturns(validator) { const inflations = await this.getTokensInflations() const totalBackedValues = await this.getTotalBackedValues() diff --git a/lib/source/terraV3-source.js b/lib/source/terraV3-source.js index d46d3ceeaa..68e6123c81 100644 --- a/lib/source/terraV3-source.js +++ b/lib/source/terraV3-source.js @@ -3,9 +3,6 @@ const BigNumber = require('bignumber.js') const { keyBy } = require('lodash') const { pubkeyToAddress } = require('../tools') -// Terra is provisioning this amount manually https://medium.com/terra-money/project-santa-community-initiative-b8ab6c4d79be -const annualProvision = '21700000000000' // 21.7 million in uluna - const gasPrices = [ { denom: 'ukrw', @@ -36,14 +33,20 @@ class TerraV3API extends CosmosV2API { } async getAllValidators(height) { - let [validators, validatorSet, signedBlocksWindow] = await Promise.all([ + let [ + validators, + validatorSet, + signedBlocksWindow, + expectedReturns + ] = await Promise.all([ Promise.all([ this.query(`staking/validators?status=unbonding`), this.query(`staking/validators?status=bonded`), this.query(`staking/validators?status=unbonded`) ]).then(validatorGroups => [].concat(...validatorGroups)), this.getAllValidatorSets(height), - this.getSignedBlockWindow() + this.getSignedBlockWindow(), + this.query(`v1/staking`, 'validators') ]) // create a dictionary to reduce array lookups @@ -59,6 +62,8 @@ class TerraV3API extends CosmosV2API { 'address' ) + const expectedReturnsMap = keyBy(expectedReturns, 'operatorAddress') + validators.forEach(validator => { const consensusAddress = pubkeyToAddress( validator.consensus_pubkey, @@ -72,23 +77,25 @@ class TerraV3API extends CosmosV2API { validator.signing_info = signingInfos[consensusAddress] }) - return validators.map(validator => - this.reducers.validatorReducer( + return validators.map(validator => { + const lunieValidator = this.reducers.validatorReducer( this.networkId, signedBlocksWindow, - validator, - annualProvision + validator ) - ) + + lunieValidator.expectedReturns = expectedReturnsMap[ + lunieValidator.operatorAddress + ] + ? expectedReturnsMap[lunieValidator.operatorAddress].stakingReturn + : 0 + + return lunieValidator + }) } async getExpectedReturns(validator) { - const expectedReturns = this.reducers.expectedRewardsPerToken( - validator, - validator.commission, - annualProvision - ) - return expectedReturns + return Number(validator.expectedReturns).toFixed(4) } // Terra will be the root source for functions specific to Tendermint multidenom networks