Skip to content

Commit

Permalink
release (#448)
Browse files Browse the repository at this point in the history
* Fabo/fix gas (#250)

* fix gas estimate

* linted

* fixed test

* do not keep data sources (#251)

* track failing transactions in Sentry (#249)

* correctly set the tx schema for a failing tx (#248)

* Fabo/remove per block caching as not working (#247)

* remove per block caching as not working

* fix memoized results

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>

* delete perblockcachedatasource (#253)

* Ana/fix balances in actionmodal (#255)

* fix action modal available balance

* include regen

* use dictionary for denomlookup

* use correct events for received txs (#257)

* enable account creation for some networks (#252)

* network update time metric added (#256)

* network update time metric added

* added missing dep

Co-authored-by: Fabian <frznhope@gmail.com>

* Fix proposal deposit (#261)

* Remove denom handling from getDeposit()

* Revert undesired change

* delete package-lock.json

* localtestnet config change (#265)

* Ana/handle "address not from this network" error (#263)

* add check address function for all queries

* apply suggestions

* Ana/add fiatvalue to balances query (e-Money) (#262)

* preparation

* more preparation

* add fiatvalue field to balances query

* fix get account info

* apply suggestions

* apply one last suggestion

* suggestions+

Co-authored-by: Fabian <frznhope@gmail.com>

* Ana/emoney fix expected returns with inflation and totalbacked (#243)

* fix expected returns with inflation and supply

* minor fixes. dictionary

* query exchange rates from emoney api

* fix infinite expected returns

* convert api url to const

* add eur value to totalbackedvalue. totalngm gains

* add important comment

* finish calculation

* lint

* catch errors with sentry

Co-authored-by: Fabian <frznhope@gmail.com>

* readd coin conversion (#268)

* delete amount field (#274)

* Fabo/increase gas again (#271)

* icrease gas again

* fixed test

* Fabo/load all txs (even if more then first page in response) (#270)

* load all txs (even if more then first page in response)

* improved handling of txs

* missing renaming

* fixed paginated load

* add pagination fix also to cosmosV0-source

Co-authored-by: iambeone <iambeone@gmail.com>
Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>

* fixing issue with multiple senders in one event (#273)

* fixing issue with multiple senders in one event

* Update lib/source/cosmosV2-source.js

Co-authored-by: Fabian <frznhope@gmail.com>

* Fabo/allow signing for terra + emoney (#267)

* allow signing for terra

* readd coin conversion

* enable actions for terra

* fix correct terra testnet url

* comments and guards

* enabled more txs for emoney and fixed broadcasting

* added a catch for wrongly formatted broadcast urls

* recover default field. change some network titles (#277)

* Fabo/add network data to API (#278)

* non desctructive introduction of better address prefix wording

* added address creator to API

* adjusted test

* added ledger app to networks config

* add icon property to schema (#281)

* add icon property to schema

* fix network schema validation

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>

* filter out validator specific txs (#279)

* Ana/balances coinreducer good fix (#269)

* balances coinreducer good fix

* refactored fiat value logic

Co-authored-by: Fabian <frznhope@gmail.com>

* Create network_integration.md

* Update network_integration.md

* Update network_integration.md

* Fabo/avoid 500 errors (#288)

* avoid using the latest query

* cleanup

* Ana/filter validator tx cross network and add txvalue reducer (#285)

* filter validators cross network

* add value reducer. necessary for multi claim txs

* add validator txs filter also for cosmosv0 source

* filter and make array only claim rewards msg value

* filter txs by whitelist

* change length in multi claim reward reducer

* add withdrawvalidators

* replace dictionary for set

* refactor transaction snippet. avoid repetition

* Ana/emoney upgrade (mergeable) (#282)

* update emoney api_url

* fix denom. add default fiat currency

* fix rpc endpoint

* fix value (my bad) (#293)

* fix value (my bad)

* trigger another ci flow

* erase space

* set correct new chain id (#294)

* restart API

* restart API

* fix pr alert (#297)

* Fabo/298 tendermint reconnect (#300)

* reconnect on tendermint disconnect

* cleanup

* comments

* Update cosmos-node-subscription.js

* Fabo/299 trigger a chain hangup error (#301)

* trigger a chain hangup error

* increase chain hangup time

* Apply suggestions from code review

* Fabo/store validator addresses (#296)

* add validator addresses to db

* linted

* ignore in local dev

* revert

* fixed fetch

* comment

* refactored db into constructor

* cleanup

* add clearTimeout to avoid reconnection hell (#306)

* add clearTimeout to avoid reconnection hell

* removed console.log

* Aleksei/luniedb replaced (#303)

* add validator addresses to db

* linted

* ignore in local dev

* revert

* fixed fetch

* comment

* refactored db into constructor

* cleanup

* replaced luniedb

* linted

Co-authored-by: Fabian <frznhope@gmail.com>

* disable reconnection logic

* clear polling interval for tendermint connection

* simple api fixes (#310)

* Fabo/remove tendermint (#311)

* remove tendermint

*  fixed empty blockHeight issue

* small refactoring

* catch on fetches to get logging

* delay block updates

* add retry logic

* refactored getBlockByHeight

* remove pm2 dep

* validator profiles were returned as array (#312)

* remove pr github action (#316)

* fixing caching issue and more (#315)

* fixing caching issue and more

* clear chain hangup timeout

* timeout fixed

* Update lib/block-listeners/cosmos-node-subscription.js

Co-authored-by: Jordan Bibla <jbibla@gmail.com>

* added terra_mainnet to networks (#309)

* added terra_mainnet to networks

* errors fix reverted

* Ana/add multidenom rewards. necessary for emoney (#308)

* add multidenom rewards. necessary for emoney

* add rewards to overview. improve code location

* lint

* add filter rewards for multidenom

* important fix

* another important fix

* fix cannot read propery constructor of undefined (#318)

* change terra mainnet title

* pushing something to trigger new build and to restart the node

* trying out nylira's node

* WIP: Ana/More Terra fixes (#323)

* fixing my mess

* move all rewards logic to terra

* clearly signal single denom rewards

* Revert "WIP: Ana/More Terra fixes (#323)" (#325)

This reverts commit 408186a.

* catch inside block polling function (#327)

* Fabo/disable writing validator addresses for now (#329)

* disable writing validator addresses for now

* linted

* flushing http cache (#332)

* Transaction abstraction schema (#333)

* tx abstraction proposal using union

* Use Coin type

* Cleanup, TransactionV2

* Cleanup, not multisend tx

* Unsupported tx (like multisend) don't have details

* Fabo/switch to docker swarm mode (#330)

* swtich to docker swarm mode

* typo

* Update .github/workflows/development.yml

* Ana/more terra fixes (***THE COMEBACK***) (#324)

* fixing my mess

* move all rewards logic to terra

* clearly signal single denom rewards

* error structure has changed. need to look into it

* also return denom for single denom rewards

* manage errors properly

* delete comments

* Update lib/reducers/terraV3-reducers.js

* loop through transaction messages

* doing crazy stuff

* rewrite the crazy bit

Co-authored-by: Fabian <frznhope@gmail.com>

* cosmosv0 was missing the retry logic (#334)

* add back validator to db logic (#335)

* path_prefix added to network data (#338)

* path_prefix added to network data

* path_prefix replaced to slug

* tests fixed

* remove regen (#337)

Co-authored-by: Jordan Bibla <jbibla@gmail.com>

* Fabo+Mario/transaction abstraction (#336)

* draft for transaction abstraction

* use lunie message types

* Add supported tx types

* WIP

* Draft new reducers

* Fix msg types

* Need to resolve type for TransactionDetails union

* debug resolver

* lint

* Fix

* Cleanup

* fix some union issues

* Almost done

* Small fixes

* Add userTransactionAddedV2

* Add userTransactionAddedV2 to resolvers

Co-authored-by: Mario Pino <info@quequiereshacer.es>

* emoney fixes for fiatvalue (#345)

* emoney fixes for fiatvalue

* refactor with coinreducer

* speaking functions are your friends

* refactor ugly nested code

* lint

* add denoms lookups for terra and emoney (#346)

* Ana/add only tokens gas prices 2nd attempt (#344)

* add terra and emoney gas price. terra reducer

* delete fiatvalue from get balances in cosmos

* add emoney reducer

* hyper important emoney fixes

* fix for emoney denoms

* change gas price to micro units

* add emoney denoms to denomlookup

* transform to microunit also for terra tokens

* return null for emoney gas prices

* add harcoded gas prices

* correct emoney hardcoded values

* hardcoded terra gas prices. not working

* update hardcoded values to working ones

* delete unrelated changes to gas prices

* apply suggestions except coinreducer

* they call me mr coinreducer

* change amount for price. add gas price reducer

* change naming in gas price reducer

* add error message

Co-authored-by: Fabian <frznhope@gmail.com>

* fix rewards denoms (#351)

* updating image on deploy (#352)

* fix my mess once more (#353)

* Ana/add gas prices to other networks (#350)

* add gasprices to cosmos

* format gas prices to three decimals

* Apply suggestions from code review

* Update lib/reducers/cosmosV0-reducers.js

Co-authored-by: Fabian <frznhope@gmail.com>
Co-authored-by: Jordan Bibla <jbibla@gmail.com>

* added a tx success push, fallback (#354)

* fix cosmos gas price (#355)

* fix terra for new tmbalance (#358)

* Fabo/new emoney rewards (#357)

* intent to fix the emoney rewards

* intent to fix emoney rewards

* simplified code

* comments

* hack to fix reduce function

* eligable -> eligible

* correct reducer fix

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>
Co-authored-by: Jordan Bibla <jbibla@gmail.com>

* Aleksei/prevent constant db calls (#304)

* add validator addresses to db

* linted

* ignore in local dev

* revert

* fixed fetch

* comment

* refactored db into constructor

* cleanup

* prevent constant db interaction

* stored object structure changed

* remove nesting in validators

* filter validators list

Co-authored-by: Fabian <frznhope@gmail.com>

* limit txs pages load by two pages per request (#314)

* limit txs pages load by two pages per request

* delete block from loadpaginatedtxs

* small fixes

* Update lib/source/cosmosV2-source.js

* linted

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>
Co-authored-by: Fabian <frznhope@gmail.com>

* linted

* linted

* Fabo/Use figment nodes (#362)

* use api keys

* add env variables for nodes

* hard code api keys (#365)

* fix ngm fiatvalue (#361)

* hardcoded urls fix (#366)

* WIP: Improve TransactionV2 implementation (#349)

* Add from field to SendTx type

* add amount to claim rewards transactions

* convert to units in string coin reducer

* fix typo

* add multidenom string coinreducer for claim amount

* Add UnknownTx to schema

* Add BlockV2 type which returns TransactionV2 txs

* Add blockV2 query that returns TransactionV2 txs

* kill handling claim rewards amount

* Update lib/reducers/cosmosV0-reducers.js

Co-Authored-By: Fabian <frznhope@gmail.com>

* Update lib/reducers/cosmosV0-reducers.js

Co-Authored-By: Fabian <frznhope@gmail.com>

* Cleanup

* lint

* Support claim rewards from multiple validators

* Fix, cleanup

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>
Co-authored-by: Fabian <frznhope@gmail.com>

* Aleksei/fix db insert (#367)

* fixed insert function to allow empty schema

* Aleksei/statistics in the api (#364)

* collecting statistics in the API

* small fixes

* fixes

* changing address to key in clearOverviewedAddresses

Co-authored-by: Aleksey Rudometov <iambeone@gmail.com>

* add pageNumber to schema (#370)

* add pageNumber to schema

* file wasn't saved

* trigger ci

* added pagination to tx v2 api (#372)

* Together with 3584: Ana/change fiatvalue to object (#360)

* change fiatvalue to object

* handle when selected currency is eur

* include ngm fiatvalue fix

* Ana/amount in claim rewards in transactions v2 (#373)

* bring amount in claim rewards back to life

* change to regex

* simplify

* make the regex understandable

* Ana/add powered to networks (#377)

* add powered by

* more logical powered

* add provider address for avatar

* fix powere validation

* Fabo/add network-type for selecting addrss and signing (#378)

* add network-type for selecting addrss and signing

* adjust according to new network_type param

* add network type to network schema

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>

* fix staking denom (#379)

* fix terra balances and overview (#380)

* Fabo/allow to query experimental networks (#382)

* all to query experimental networks

* fix old small typo

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>

* First steps to integrate Polkadot (#376)

* Add polkadot-testnet in networks.js

* Install polkadot-api, polkadot-node-sub. draft

* lint

* lint

* lint

* add polkadotV0 source

* add address creator

* Update data/networks.js

Co-Authored-By: Jordan Bibla <jbibla@gmail.com>

* Update data/networks.js

Co-Authored-By: Jordan Bibla <jbibla@gmail.com>

* blocks, events

* Cleanup

* polling instead subscription

* husky

* updateDBValidatorProfiles

* no wait for block data fetching, kind of stable

* Add reducers file

* block subscription works!

* Cleanup, fix memory leak

* lint, node

* comment

* Handle polkadot chain reorgs

* Cleanup

* Optimization, cleanup

* Optimization

* fixes, validators query working, cleanup

* comment

* lint

* fix block time

* handle polkadot chain hangups

* cleanup

* validator reducer

* lint

* wip

* calculate and include a bunch of validator fields

* add bech32_prefix address_prefix to networks.js

* add 1 space so we dont break tests

* remove chain reorg handling, more stable

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>
Co-authored-by: Fabian <frznhope@gmail.com>
Co-authored-by: Jordan Bibla <jbibla@gmail.com>

* transactions loading time reduced (#383)

* transactions loading time reduced

* increased page number

* add loki to docker-compose (#385)

* add network type (#386)

* removed livepeer from running in API (#390)

* set polkadot to disabled (#392)

* Ana/add totalstake-fiatvalue to Overview (#384)

* add totalstake fiat value to overview

* fix amount in totalstake fiatvalue

* make new code more readable

* Update lib/reducers/cosmosV0-reducers.js

* refactor unit conversion

Co-authored-by: Mario Pino <info@quequiereshacer.es>

* disable polkadot (#395)

Co-authored-by: Fabian <frznhope@gmail.com>

* Fabo/terra returns (#389)

* better error logging

* add result selector to query

* split emoney getAllValidators from Terra

* add expected returns querying to terra

* filter out empty returns

* remove not used code

* missing return

* limit decimals

* fix not found in terra testnet

* temporary hacks

* Revert "temporary hacks"

This reverts commit 88d0918af70489422d6d5d84909df1186a23fa1c.

* Revert "fix not found in terra testnet"

This reverts commit 19a4eca6eb4a9eb2050b368b270d4a39847e016a.

* add terra testnet api

* switch to show all decimals

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>

* fix all fiat values to 2 decimals (#399)

* Ana/correct terra denoms (#398)

* correct terra denoms

* variable renaming

Co-authored-by: Fabian <frznhope@gmail.com>

* Ana/add fiatvalue in rewards (#396)

* add fiatvalue to rewards

* add fiatcurrency to rewards query

* handle unsupported fiat currencies

* apply suggestions

* delete never used delegations parameter (#404)

* fix terra getrewards and gas prices (#409)

* reactivate kusama (#411)

* Ana/fix repeated claim rewards transactions in transaction abstraction (#400)

* fix terra repeated claim rewards transactions

* much better fix

* add claim rewards messages aggregator

* try to apply suggestion

* also not working

* working 🎉

* change name and add comment

* improved implementation by aggregating the claim messags correctly

Co-authored-by: Fabian Weber <frznhope@gmail.com>

* disable polkadot once more for release (#412)

* readd memory limit (#413)

* Use polling instead subscription in Kusama (#406)

* uncomment polkadot

* bug fixes

* pollForNewBlock

* mod getBlockHeight

* add again commented api disconnect to not forget

* enqueueAndPublishBlockAdded

* re-subscribe on error

* stringify error

* stringify errors

* api.isReady

* Add delay to newBlockHandler

* Ana/add balances to kusama (#405)

* rudimentary balance

* add some comment

* Ana/switch polkadot to rest calls (#408)

* add rewards and overview functions. not working

* poll instead of subscribe to blocks

* switch over to http provider

* fix lint errors

* use httpprovider

* getting last block hash

* get blockhash and header. but no height

* back to normal. use mario node subscription

* successfully get block height polling with http

* get block hash from http. use polling

* uncomment all other networks

* pass the store to source classes

* create the api only once

* comment api.disconnect()

* added polling fix and quick querying

* fixed block height query

* clean up

* comment

* cleanup and optimization

Co-authored-by: Fabian Weber <frznhope@gmail.com>
Co-authored-by: mariopino <info@quequiereshacer.es>

* remove unused dependency

Co-authored-by: Bitcoinera <anagjordano@gmail.com>
Co-authored-by: Ana G <40721795+Bitcoinera@users.noreply.github.com>
Co-authored-by: Fabian Weber <frznhope@gmail.com>

* deactivate polkadot

* trigger deploy

* trigger CI

* swtich to newer caddy version

* activate polkadot again

* deactivate again

* Proposal to enable Kusama network (#424)

* working state

* cleanup

* getBlockHeight()

* update polkadot-api (#423)

* fixing node_exporter call in Caddyfile (#418)

* fixing send amount in statistics (#419)

* fixing send amount in statistics

* denom fixed

* fix validator as selected fiat bug (#415)

* Ana/correct terra denoms in activity (#425)

* correct fix terra denoms in activity

* delete correct terra denom as not needed

* Ana/fix amount null in claim rewards (#416)

* fix amount null in claim rewards

* small refactor

* apply suggestion

* add release script to api (#426)

* Add self stake to validators query (#433)

* add self stake

* Update lib/reducers/polkadotV0-reducers.js

Co-Authored-By: Ana G. <40721795+Bitcoinera@users.noreply.github.com>

* lint

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>
Co-authored-by: Bitcoinera <anagjordano@gmail.com>

* fix emoney balances denoms (#436)

* [Polkadot] Add delegations query (#435)

* first step, simplified query is working

* lint

* Get validator info from val dictionary

* cleanup, fix comission

* fix

* faster solution

* remove types we dont need in store

* @ALEKSEI suggestions

* fix

* fix

* simplify as @imbeone suggested

* simplify, thanks @Bitcoinera!

* re adding array check

* delegationReducer

* fix

* Ana/update polkadot balances (#441)

* update polkadot balances

* structs are strange

* change comment

* disable kusama

* disable kusama

* Ana/427 polkadot single validator query (#440)

* save validators with operatoraddress as key

* add check to wait to fetch validators

* Update lib/resolvers.js

Co-Authored-By: Fabian <frznhope@gmail.com>

* Update lib/resolvers.js

Co-Authored-By: Fabian <frznhope@gmail.com>

* lint

* fix delegations

Co-authored-by: Fabian <frznhope@gmail.com>

* Add denom decimal places to networks.js (#434)

* lint

* add decimals places, refactor POLKADOT_CONVERSION

* add to schema

* add to tests

* refactor with @faboweb suggestions

* fix

* fix

* fix

* cleanup

* apply suggestions

* fix balances

* add factor properly to network

Co-authored-by: Bitcoinera <anagjordano@gmail.com>

* fix totalstake fiatvalue only returning euro (#442)

* Fix commission for validators in Polkadot network (#447)

* fix commission

* comment

* Fix expectedReturns for validators in Polkadot network (#446)

* fix expectedReturns

* change -- for null in getrewards and returns

Co-authored-by: Bitcoinera <anagjordano@gmail.com>

* Ana/emoney validators load optimization (#430)

* just for testing. hang up on validatorssets latest

* fix emoney validators load

* resolve conflict

* remove experimental line

* linted

Co-authored-by: Ana G. <40721795+Bitcoinera@users.noreply.github.com>
Co-authored-by: iambeone <iambeone@gmail.com>
Co-authored-by: Mario Pino <info@quequiereshacer.es>
Co-authored-by: Jordan Bibla <jbibla@gmail.com>
Co-authored-by: Bitcoinera <anagjordano@gmail.com>
  • Loading branch information
6 people authored Mar 12, 2020
1 parent 34fab04 commit ce87f1e
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 37 deletions.
8 changes: 8 additions & 0 deletions data/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ module.exports = [
action_proposal: false,
default: false,
stakingDenom: 'KSM',
// https://wiki.polkadot.network/docs/en/learn-DOT
coinLookup: [
{
chainDenom: 'Planck',
viewDenom: 'KSM',
chainToViewConversionFactor: 1e-12
}
],
enabled: false,
icon: 'https://app.lunie.io/img/networks/polkadot-testnet.png',
slug: 'kusama'
Expand Down
4 changes: 2 additions & 2 deletions lib/block-listeners/polkadot-node-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class PolkadotNodeSubscription {
this.store.update({
height: blockHeight,
block,
validators: this.sessionValidators
validators: this.getValidatorMap(this.sessionValidators)
})

// For each transaction listed in a block we extract the relevant addresses. This is published to the network.
Expand All @@ -160,7 +160,7 @@ class PolkadotNodeSubscription {
}
}

async getValidatorMap(validators) {
getValidatorMap(validators) {
const validatorMap = _.keyBy(validators, 'operatorAddress')
return validatorMap
}
Expand Down
6 changes: 5 additions & 1 deletion lib/reducers/cosmosV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ async function overviewReducer(
rewards,
stakingDenom,
fiatValueAPI,
fiatCurrency,
reducers
) {
stakingDenom = denomLookup(stakingDenom)
Expand Down Expand Up @@ -427,6 +428,7 @@ async function overviewReducer(
totalStakeFiatValue: fiatValueAPI
? totalStakeFiatValueReducer(
fiatValueAPI,
fiatCurrency,
totalStake,
stakingDenom,
reducers
Expand All @@ -437,6 +439,7 @@ async function overviewReducer(

async function totalStakeFiatValueReducer(
fiatValueAPI,
fiatCurrency,
totalStake,
stakingDenom
) {
Expand All @@ -445,7 +448,8 @@ async function totalStakeFiatValueReducer(
toMicroUnitBalance({
amount: totalStake,
denom: stakingDenom
})
}),
fiatCurrency
)
}

Expand Down
30 changes: 21 additions & 9 deletions lib/reducers/polkadotV0-reducers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const BigNumber = require('bignumber.js')

const POLKADOT_CONVERSION = 1000000000000

function blockReducer(
networkId,
blockHeight,
Expand Down Expand Up @@ -44,33 +42,47 @@ function validatorReducer(network, validator) {
uptimePercentage: undefined,
tokens: validator.tokens,
commissionUpdateTime: undefined,
commission: validator.validatorPrefs.commission / 100000000,
commission: (validator.validatorPrefs.commission / 1000000000).toFixed(9), // Returns commission in 0-1 range (1 = 100%)
maxCommission: undefined,
maxChangeCommission: undefined,
status: `ACTIVE`, // We are fetching current session active validators only (not intentions)
statusDetailed: ``, // TODO: Include validator heartbeat messages
delegatorShares: undefined,
selfStake:
(
BigNumber(validator.exposure.own).toNumber() / POLKADOT_CONVERSION
).toFixed(9) || 0
BigNumber(validator.exposure.own).toNumber() *
network.coinLookup[0].chainToViewConversionFactor
).toFixed(9) || 0,
nominations: validator.nominations
}
}

function balanceReducer(balance) {
function balanceReducer(network, balance) {
// hack. We convert the balance into an Array to make it an Iterable
return [
{
amount: BigNumber(balance)
.div(POLKADOT_CONVERSION)
.times(network.coinLookup[0].chainToViewConversionFactor)
.toFixed(4),
denom: `KSM` // hardcoded for now. Looking how to do a more complete query
denom: network.coinLookup[0].viewDenom
}
]
}

function delegationReducer(network, delegation, validator) {
return {
validatorAddress: validator.operatorAddress,
delegatorAddress: delegation.who,
validator,
amount: BigNumber(delegation.value)
.times(network.coinLookup[0].chainToViewConversionFactor)
.toFixed(9)
}
}

module.exports = {
blockReducer,
validatorReducer,
balanceReducer
balanceReducer,
delegationReducer
}
24 changes: 16 additions & 8 deletions lib/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,25 @@ async function validator(_, { networkId, operatorAddress }, { dataSources }) {
networkId
).getValidatorInfoByAddress(operatorAddress)

const validator = localStore(dataSources, networkId).validators[
operatorAddress
]
// here first we check if validators in localStore are an empty object
// this is because sometimes it takes time to fetch them on startup
if (Object.keys(localStore(dataSources, networkId).validators).length > 0) {
const validator = localStore(dataSources, networkId).validators[
operatorAddress
]

if (!validator) {
throw new UserInputError(
`The validator ${operatorAddress} was was found within the network ${networkId}`
if (!validator) {
throw new UserInputError(
`The validator ${operatorAddress} was not found within the network ${networkId}`
)
}

return enrichValidator(validatorInfo, validator)
} else {
throw new Error(
`Validators have not been loaded yet for the network ${networkId}`
)
}

return enrichValidator(validatorInfo, validator)
}

function delegation(
Expand Down
7 changes: 7 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ const typeDefs = gql`
type: String
}
type coinLookup {
chainDenom: String!
viewDenom: String!
chainToViewConversionFactor: Int!
}
type Network {
id: String
title: String
Expand Down Expand Up @@ -138,6 +144,7 @@ const typeDefs = gql`
action_proposal: Boolean
default: Boolean
stakingDenom: String
coinLookup: [coinLookup]
enabled: Boolean
icon: String
slug: String
Expand Down
1 change: 1 addition & 0 deletions lib/source/cosmosV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ class CosmosV0API extends RESTDataSource {
rewards,
stakingDenom,
fiatValueAPI,
fiatCurrency,
this.reducers
)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/source/emoneyV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class EMoneyV0API extends TerraV3API {
return 0
}

async getAllValidators() {
return CosmosV0API.prototype.getAllValidators.call(this)
async getAllValidators(height) {
return CosmosV0API.prototype.getAllValidators.call(this, height)
}

async getExpectedReturns(validator) {
Expand Down
50 changes: 35 additions & 15 deletions lib/source/polkadotV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ class polkadotAPI {
if (validator.exposure) {
const validatorStake = new BigNumber(validator.exposure.total)
validator.votingPower = validatorStake.div(networkTotalStake).toNumber()
validator.tokens = validatorStake / 1e12 // IMPROVE IT! Add denom decimal places to network.js
validator.tokens =
validatorStake *
this.network.coinLookup[0].chainToViewConversionFactor
validator.nominations = JSON.parse(
JSON.stringify(validator.exposure.others)
) // Added for faster delegations search
} else {
validator.votingPower = 0
}
Expand All @@ -159,35 +164,50 @@ class polkadotAPI {
)
}

// TODO: implement!
async getExpectedReturns() {
return 0
}

async getSelfStake(validator) {
return validator.selfStake
}

async getBalancesFromAddress(address) {
const api = await this.getAPI()
// the documentation points at api.query.system.account as the preferred query. Looking into it
const balance = await api.query.balances.freeBalance(address)
return this.reducers.balanceReducer(JSON.stringify(balance))
const account = await api.query.system.account(address)
const freeBalance = account.data.free
return this.reducers.balanceReducer(this.network, freeBalance.toString())
}

async getRewards(delegatorAddress) {
const api = await this.getAPI()
const rewards = api.derive.staking.stakerRewards(delegatorAddress)
// currently not working. It always returns []
console.log('REWARDS', rewards)
return rewards
async getExpectedReturns() {
return null
}

async getRewards() {
return null
}

async getOverview(delegatorAddress) {
const api = await this.getAPI()
const accountBalances = await api.query.staking.bonded(delegatorAddress) // or stashId?
console.log('ACCOUNT', JSON.stringify(accountBalances))
}

async getDelegationsForDelegatorAddress(
delegatorAddress,
validatorsDictionary
) {
const validatorsArray = Object.keys(validatorsDictionary).map(
key => validatorsDictionary[key]
)
let delegations = []
validatorsArray.forEach(validator => {
validator.nominations.forEach(nomination => {
if (delegatorAddress === nomination.who) {
delegations.push(
this.reducers.delegationReducer(this.network, nomination, validator)
)
}
})
})
return delegations
}
}

module.exports = polkadotAPI
9 changes: 9 additions & 0 deletions tests/network-configs.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const Joi = require('@hapi/joi')
const { allNetworks } = require('../lib/networks')

const coinLookup = Joi.object().keys({
chainDenom: Joi.string(),
viewDenom: Joi.string(),
chainToViewConversionFactor: Joi.number()
})

const schema = Joi.object({
id: Joi.string().lowercase(),
title: Joi.string(),
Expand Down Expand Up @@ -32,6 +38,9 @@ const schema = Joi.object({
action_proposal: Joi.boolean(),
default: Joi.boolean(),
stakingDenom: Joi.string().uppercase(),
coinLookup: Joi.array()
.items(coinLookup)
.optional(),
enabled: Joi.boolean(),
experimental: Joi.boolean().optional(),
icon: Joi.string().optional(),
Expand Down

0 comments on commit ce87f1e

Please sign in to comment.