Skip to content

Commit

Permalink
Ana/add emoney mainnet (#511)
Browse files Browse the repository at this point in the history
* first preparations

* Update data/networks.js

Co-Authored-By: Fabian <[email protected]>

* Update data/networks.js

Co-Authored-By: Fabian <[email protected]>

* add correct chainid

* add validators poller for release

* check emoney mainnet validators recursively

Co-authored-by: Fabian <[email protected]>
  • Loading branch information
Bitcoinera and faboweb authored Mar 25, 2020
1 parent 4aafab8 commit eb704dc
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 9 deletions.
17 changes: 17 additions & 0 deletions data/network-capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ const getNetworkCapabilities = {
action_vote: false,
action_proposal: false
},
"emoney-mainnet": {
feature_session: true,
feature_explore: true,
feature_portfolio: true,
feature_validators: true,
feature_proposals: false,
feature_activity: true,
feature_explorer: true,
action_send: true,
action_claim_rewards: true,
action_delegate: true,
action_redelegate: true,
action_undelegate: true,
action_deposit: false,
action_vote: false,
action_proposal: false
},
"emoney-testnet": {
feature_session: true,
feature_explore: true,
Expand Down
21 changes: 21 additions & 0 deletions data/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ module.exports = [
icon: 'https://app.lunie.io/img/networks/terra-testnet.png',
slug: 'terra-testnet'
},
{
id: 'emoney-mainnet',
title: 'e-Money',
chain_id: 'emoney-1',
api_url: 'https://emoney.validator.network/light',
rpc_url: 'wss://emoney.validator.network/websocket',
bech32_prefix: 'emoney',
address_prefix: 'emoney',
address_creator: 'cosmos',
ledger_app: 'cosmos',
network_type: 'cosmos',
source_class_name: 'source/emoneyV0-source',
block_listener_class_name: 'block-listeners/cosmos-node-subscription',
testnet: true,
...getNetworkCapabilities[`emoney-mainnet`],
default: false,
stakingDenom: 'NGM',
enabled: true,
icon: 'https://app.lunie.io/img/networks/emoney-mainnet.png',
slug: 'emoney'
},
{
id: 'emoney-testnet',
title: 'e-Money Testnet',
Expand Down
10 changes: 10 additions & 0 deletions lib/block-listeners/cosmos-node-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
const Sentry = require('@sentry/node')
const database = require('../database')
const config = require('../../config.js')
const { pollForValidators } = require('./emoney-release-validators-poller')

const POLLING_INTERVAL = 1000
const EXPECTED_MAX_BLOCK_WINDOW = 120000
Expand All @@ -31,6 +32,15 @@ class CosmosNodeSubscription {
}

async pollForNewBlock() {
if (this.network.id === `emoney-mainnet`) {
const validators = await pollForValidators(this.network)
if (!validators || validators.length <= 0) {
setTimeout(async () => {
this.pollForNewBlock()
}, POLLING_INTERVAL)
return
}
}
const cosmosAPI = new this.CosmosApiClass(this.network, this.store)
await this.checkForNewBlock(cosmosAPI)

Expand Down
8 changes: 8 additions & 0 deletions lib/block-listeners/emoney-release-validators-poller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
async function pollForValidators(eMoneyNetwork) {
const { result } = await global.fetch(
`${eMoneyNetwork.api_url}/staking/validators`
)
return result
}

module.exports = { pollForValidators }
5 changes: 4 additions & 1 deletion lib/reducers/cosmosV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ function denomLookup(denom) {
eeur: 'eEUR',
echf: 'eCHF',
ejpy: 'eJPY',
eusd: 'eUSD'
eusd: 'eUSD',
edkk: 'eDKK',
enok: 'eNOK',
esek: 'eSEK'
}
return lookup[denom] ? lookup[denom] : denom.toUpperCase()
}
Expand Down
30 changes: 22 additions & 8 deletions lib/source/emoneyV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const fetch = require('node-fetch')
const Sentry = require('@sentry/node')

const fiatExchangeRateApi = `https://api.exchangeratesapi.io/latest?`
const EMoneyAPIUrl = `https://beta-api.e-money.com/v1/`
const EMoneyAPIUrlMainnet = `https://api.e-money.com/v1/`
const EMoneyAPIUrlTestnet = `https://beta-api.e-money.com/v1/`
const gasPrices = [
{
denom: 'echf',
Expand All @@ -27,12 +28,25 @@ const gasPrices = [
price: '0.800'
}
]
const supportedFiatCurrencies = new Set(['EUR', 'USD', 'GBP', 'CHF', 'JPY'])
const supportedFiatCurrencies = new Set([
'EUR',
'USD',
'GBP',
'CHF',
'JPY',
'DKK',
'NOK',
'SEK'
])

class EMoneyV0API extends TerraV3API {
setReducers() {
this.reducers = require('../reducers/emoneyV0-reducers')
this.gasPrices = gasPrices
this.apiURL =
this.networkId === 'emoney-mainnet'
? EMoneyAPIUrlMainnet
: EMoneyAPIUrlTestnet
}

// additional block handling by network
Expand Down Expand Up @@ -62,9 +76,9 @@ class EMoneyV0API extends TerraV3API {
await Promise.all([
this.getTokensInflations(),
this.getTotalBackedValues()
]).then(async ([inflatations, totalBackedValues]) => {
]).then(async ([inflations, totalBackedValues]) => {
store.totalNetworkAnnualRewards = await this.reducers.getTotalNetworkAnnualRewards(
inflatations,
inflations,
totalBackedValues
)
})
Expand All @@ -83,7 +97,7 @@ class EMoneyV0API extends TerraV3API {
// Here we query for the current inflation rates for all the backed tokens
async getTokensInflations() {
const inflations = await this.get(`inflation/current`)
return inflations.result.assets.filter(asset => asset.denom !== `x3chf`)
return inflations.result.assets
}

// Here we query for the current total supply for all the backed tokens
Expand Down Expand Up @@ -141,7 +155,7 @@ class EMoneyV0API extends TerraV3API {
// firt check if the selectedFiatCurrency is a supported currency
if (!supportedFiatCurrencies.has(selectedFiatCurrency)) {
throw new Error(
'We currently only support "EUR", "USD", "GBP", "CHF" and "JPY" as fiat currencies. Remember they should be written in uppercases'
'We currently only support "EUR", "USD", "GBP", "DKK", "NOK", "SEK", "CHF" and "JPY" as fiat currencies. Remember they should be written in uppercases'
)
}

Expand All @@ -164,11 +178,11 @@ class EMoneyV0API extends TerraV3API {
}

async fetchEmoneyTokenExchangeRates() {
const rates = await fetch(`${EMoneyAPIUrl}rates.json`)
const rates = await fetch(`${this.apiURL}rates.json`)
.then(r => r.json())
.catch(err => {
Sentry.withScope(function(scope) {
scope.setExtra('fetch', `${EMoneyAPIUrl}rates.json`)
scope.setExtra('fetch', `${this.apiURL}rates.json`)
Sentry.captureException(err)
})
})
Expand Down

0 comments on commit eb704dc

Please sign in to comment.