Skip to content

Commit

Permalink
Script to import networks from chain registry
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon committed Mar 3, 2022
1 parent b68ba7f commit 1d9bcb8
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 44 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ Note that the `botAddress` is the address which will be granted by the delegator

You can now submit your `networks.json` update to the repository in a pull request which will be merged and deployed as soon as possible.

## Adding/updating a network

A script is included to generate the config needed to add a new chain from the [Chain Registry](https://github.com/cosmos/chain-registry). It will update the config file in-place, retaining the important information like operators etc. It can be used to update and add a chain, just check the changes with Git.

Make sure you match the directory name from Chain Registry.

```
docker-compose run app npm run registryConfig cosmoshub
```

## Running the UI

Run the UI using docker with one line:
Expand Down
57 changes: 46 additions & 11 deletions scripts/registryConfig.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import axios from 'axios'
import _ from 'lodash'
import fs from 'fs'

import RestClient from '../src/utils/RestClient.mjs'
import {findAsync} from '../src/utils/Helpers.mjs'

const registryConfig = (name) => {
const generateConfig = (chain, tokens) => {
const generateConfig = (chain, tokens, existingConfig) => {
const fees = chain.fees && chain.fees.fee_tokens && chain.fees.fee_tokens[0] || {}
let gasPrice
if(fees && fees.fixed_min_gas_price && fees.denom){
Expand All @@ -23,13 +28,13 @@ const registryConfig = (name) => {
"prettyName": chain.pretty_name,
"chainId": chain.chain_id,
"prefix": chain.bech32_prefix,
"denom": denom,
"restUrl": chain.apis.rest.map(el => el.address),
"rpcUrl": chain.apis.rpc.map(el => el.address.replace(/\/$/, '')),
"image": image,
"gasPrice": gasPrice,
"testAddress": null,
"operators": []
"denom": denom || existingConfig.denom,
"restUrl": _.uniq(chain.apis.rest.map(el => el.address), existingConfig.restUrl),
"rpcUrl": _.uniq(chain.apis.rpc.map(el => el.address.replace(/\/$/, '')), existingConfig.rpcUrl),
"image": existingConfig.image || image,
"gasPrice": existingConfig.gasPrice || gasPrice,
"testAddress": existingConfig.testAddress,
"operators": existingConfig.operators || []
}
}

Expand All @@ -43,16 +48,46 @@ const registryConfig = (name) => {
.then(res => res.data)
}

const testGrants = (restUrl) => {
return axios.get(restUrl + "/cosmos/authz/v1beta1/grants")
.then(res => res.data)
.then(data => data).catch(error => {
return error.response && error.response.status === 400 // expect bad request
})
}

const getNetworksData = () => {
let response = fs.readFileSync('src/networks.json');
return JSON.parse(response);
}

return {
generateConfig,
chainData,
tokenData,
generateConfig
testGrants,
getNetworksData
}
}

const chainName = process.argv[2]
const registry = registryConfig(chainName)
const networks = registry.getNetworksData().reduce((a, v) => ({ ...a, [v.name]: v}), {})
const existingConfig = networks[chainName]
const chain = await registry.chainData()
const tokens = await registry.tokenData()
const config = registry.generateConfig(chain, tokens)
console.log(JSON.stringify(config, null, '\t'))
const config = registry.generateConfig(chain, tokens, existingConfig)
let authzEnabled = false

if(config.restUrl.length){
const restClient = await RestClient(config.chainId, config.restUrl)
if(!restClient.restUrl) console.log('No API responses. Unable to check authz status')
authzEnabled = await registry.testGrants(restClient.restUrl)
if(restClient.restUrl && !authzEnabled) console.log('No authz support')
}
_.merge(config, {authzSupport: authzEnabled})
_.set(networks, chainName, config)
const newConfig = JSON.stringify(Object.values(networks), null, ' ')

fs.writeFileSync('src/networks.json', newConfig)
console.log('New config written, use git to rollback if needed')
86 changes: 53 additions & 33 deletions src/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/osmo.svg",
"gasPrice": "0uosmo",
"testAddress": "osmo1yxsmtnxdt6gxnaqrg0j0nudg7et2gqczed559y",
"operators": [{
"address": "osmovaloper1u5v0m74mql5nzfx2yh43s2tke4mvzghr6m2n5t",
"botAddress": "osmo1yxsmtnxdt6gxnaqrg0j0nudg7et2gqczed559y",
"runTime": "21:00",
"minimumReward": 1000
}, {
"address": "osmovaloper1md9f5524vtmrn64lyv2pdfn7cnkjkklf44vtjz",
"botAddress": "osmo1e44rluarkdw56dy2turnwjtvtg4wqvs06sx5ph",
"runTime": "21:00",
"minimumReward": 10000
}]
"operators": [
{
"address": "osmovaloper1u5v0m74mql5nzfx2yh43s2tke4mvzghr6m2n5t",
"botAddress": "osmo1yxsmtnxdt6gxnaqrg0j0nudg7et2gqczed559y",
"runTime": "21:00",
"minimumReward": 1000
},
{
"address": "osmovaloper1md9f5524vtmrn64lyv2pdfn7cnkjkklf44vtjz",
"botAddress": "osmo1e44rluarkdw56dy2turnwjtvtg4wqvs06sx5ph",
"runTime": "21:00",
"minimumReward": 10000
}
],
"authzSupport": true
},
{
"name": "juno",
Expand All @@ -36,7 +40,7 @@
"denom": "ujuno",
"restUrl": [
"https://lcd-juno.itastakers.com",
"https://lcd.juno-1.technofractal.com"
"https://lcd.juno-1.technofractal.com/"
],
"rpcUrl": [
"https://rpc-juno.itastakers.com",
Expand All @@ -45,12 +49,15 @@
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/juno.svg",
"gasPrice": "0.0025ujuno",
"testAddress": "juno1yxsmtnxdt6gxnaqrg0j0nudg7et2gqcz8yyl52",
"operators": [{
"address": "junovaloper193xl2tqh2tjkld2zv49ku5s44ee4qmgr65jcep",
"botAddress": "juno1e44rluarkdw56dy2turnwjtvtg4wqvs0yeklse",
"runTime": "21:00",
"minimumReward": 1000
}]
"operators": [
{
"address": "junovaloper193xl2tqh2tjkld2zv49ku5s44ee4qmgr65jcep",
"botAddress": "juno1e44rluarkdw56dy2turnwjtvtg4wqvs0yeklse",
"runTime": "21:00",
"minimumReward": 1000
}
],
"authzSupport": true
},
{
"name": "cosmoshub",
Expand All @@ -70,7 +77,8 @@
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/atom.svg",
"gasPrice": "0uatom",
"testAddress": "cosmos1yxsmtnxdt6gxnaqrg0j0nudg7et2gqcz3k8ynk",
"operators": []
"operators": [],
"authzSupport": true
},
{
"name": "akash",
Expand Down Expand Up @@ -100,25 +108,33 @@
],
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/akt.svg",
"testAddress": null,
"operators": []
"operators": [],
"authzSupport": false
},
{
"name": "chihuahua",
"prettyName": "Chihuahua",
"chainId": "chihuahua-1",
"prefix": "chihuahua",
"denom": "uhuahua",
"restUrl": "https://api.chihuahua.wtf",
"rpcUrl": "https://rpc.chihuahua.wtf",
"restUrl": [
"https://api.chihuahua.wtf/"
],
"rpcUrl": [
"https://rpc.chihuahua.wtf"
],
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/huahua.png",
"gasPrice": "0.025uhuahua",
"testAddress": "chihuahua1yxsmtnxdt6gxnaqrg0j0nudg7et2gqczjr22j5",
"operators": [{
"address": "chihuahuavaloper19vwcee000fhazmpt4ultvnnkhfh23ppwxll8zz",
"botAddress": "chihuahua1yxsmtnxdt6gxnaqrg0j0nudg7et2gqczjr22j5",
"runTime": "21:00",
"minimumReward": 1000
}]
"operators": [
{
"address": "chihuahuavaloper19vwcee000fhazmpt4ultvnnkhfh23ppwxll8zz",
"botAddress": "chihuahua1yxsmtnxdt6gxnaqrg0j0nudg7et2gqczjr22j5",
"runTime": "21:00",
"minimumReward": 1000
}
],
"authzSupport": false
},
{
"name": "gravitybridge",
Expand All @@ -138,7 +154,8 @@
],
"image": "https://raw.githubusercontent.com/Gravity-Bridge/Gravity-Docs/main/assets/Graviton-Blue.svg",
"testAddress": "gravity1yxsmtnxdt6gxnaqrg0j0nudg7et2gqcz4x4uk7",
"operators": []
"operators": [],
"authzSupport": true
},
{
"name": "regen",
Expand All @@ -157,7 +174,8 @@
],
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/regen.png",
"testAddress": "regen1yxsmtnxdt6gxnaqrg0j0nudg7et2gqczw5vc9j",
"operators": []
"operators": [],
"authzSupport": true
},
{
"name": "terra",
Expand All @@ -177,7 +195,8 @@
],
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/luna.svg",
"testAddress": "terra1rnszu7kumz5lmgdk3fv2pmzt3s8vhcddqep7d4",
"operators": []
"operators": [],
"authzSupport": true
},
{
"name": "sentinel",
Expand All @@ -194,6 +213,7 @@
],
"image": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/dvpn.png",
"testAddress": "sent1yxsmtnxdt6gxnaqrg0j0nudg7et2gqcz2d3ahe",
"operators": []
"operators": [],
"authzSupport": false
}
]
]
1 change: 1 addition & 0 deletions src/utils/RestClient.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const RestClient = async (chainId, restUrls) => {

return {
connected: !!restUrl,
restUrl,
getValidators,
getBalance,
getDelegations,
Expand Down

0 comments on commit 1d9bcb8

Please sign in to comment.