forked from osmosis-labs/assetlists
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Chainlist Generator (osmosis-labs#494)
* create chainlist script * expland mainnet chainlist * Add testnet chainlist generation * minor fix
- Loading branch information
1 parent
92db82c
commit 3454b56
Showing
10 changed files
with
6,602 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
on: [workflow_dispatch] | ||
name: Generate Chainlist | ||
jobs: | ||
generate_assetlist: | ||
name: Generate Chainlist | ||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
submodules: true | ||
|
||
- name: Git Sumbodule Update | ||
run: | | ||
git submodule update --init --recursive | ||
git submodule update --recursive --remote | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 19.6.0 | ||
|
||
- name: Run code to Generate Chainlist | ||
working-directory: ./.github/workflows/utility | ||
run: node generate_chainlist.mjs | ||
|
||
- name: Add Commit Push | ||
uses: devops-infra/action-commit-push@master | ||
with: | ||
github_token: "${{ secrets.GITHUB_TOKEN }}" | ||
add_timestamp: false | ||
commit_prefix: "[AUTO]" | ||
commit_message: "chainlist.json Update" | ||
force: false | ||
target_branch: update/chainlist | ||
|
||
- name: Create A PR | ||
uses: devops-infra/action-pull-request@v0.4.2 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
source_branch: update/chainlist | ||
target_branch: main | ||
title: chainlist.json Update | ||
body: "**Automated pull request**" | ||
old_string: "**THIS IS AN AUTOMATED UPDATE OF CHAINLIST.JSON**" | ||
new_string: "** Automatic pull request**" | ||
get_diff: true | ||
ignore_users: "dependabot" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Purpose: | ||
// to generate the chainlist json using the zone_chains json and chain registry data | ||
|
||
|
||
// -- THE PLAN -- | ||
// | ||
// read zone list from osmosis.zone_chains.json | ||
// add chains to zone array | ||
// for each chain in zone array, identify the chain_name (this is primary key) | ||
// get various chain properties | ||
// for bech32, is no bech32 config, get bech32 prefix, and then generate the rest of the bech32 config | ||
// write chainlist array to file osmosis-1.chainlist.json | ||
|
||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as chain_reg from './chain_registry.mjs'; | ||
|
||
|
||
const assetlistsRoot = "../../.."; | ||
const chainNameToChainIdMap = new Map([ | ||
["osmosis", "osmosis-1"], | ||
["osmosistestnet", "osmo-test-4"], | ||
["osmosistestnet5", "osmo-test-5"] | ||
]); | ||
let chains = []; | ||
|
||
const assetlistFileName = "assetlist.json"; | ||
const zoneAssetlistFileName = "osmosis.zone.json"; | ||
const zoneChainlistFileName = "osmosis.zone_chains.json"; | ||
|
||
|
||
function getZoneChainlist(chainName) { | ||
try { | ||
return JSON.parse(fs.readFileSync(path.join( | ||
assetlistsRoot, | ||
chainNameToChainIdMap.get(chainName), | ||
zoneChainlistFileName | ||
))); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
function writeToFile(assetlist, chainName) { | ||
try { | ||
fs.writeFile(path.join( | ||
assetlistsRoot, | ||
chainNameToChainIdMap.get(chainName), | ||
chainNameToChainIdMap.get(chainName) +'.chainlist.json' | ||
), JSON.stringify(assetlist,null,2), (err) => { | ||
if (err) throw err; | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
function generateChains(zone_chains) { | ||
|
||
zone_chains.forEach((zone_chain) => { | ||
|
||
// -- Chain Object -- | ||
let chain = {}; | ||
chain.chain_name = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "chain_name"); | ||
chain.status = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "status"); | ||
chain.network_type = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "network_type"); | ||
chain.pretty_name = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "pretty_name"); | ||
chain.chain_id = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "chain_id"); | ||
|
||
|
||
// -- Get bech32_config -- | ||
chain.bech32_prefix = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "bech32_prefix"); | ||
let bech32_config = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "bech32_config"); | ||
if (!bech32_config) { | ||
bech32_config = {}; | ||
} | ||
chain_reg.bech32ConfigSuffixMap.forEach((value, key) => { | ||
if (bech32_config[key]) { return; } | ||
bech32_config[key] = chain.bech32_prefix.concat(value); | ||
}); | ||
chain.bech32_config = bech32_config; | ||
|
||
|
||
// -- Get SLIP44 -- | ||
chain.slip44 = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "slip44"); | ||
chain.alternative_slip44s = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "alternative_slip44s"); | ||
|
||
|
||
// -- Get Fees -- | ||
chain.fees = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "fees"); | ||
|
||
|
||
// -- Get Staking -- | ||
chain.staking = chain_reg.getFileProperty(zone_chain.chain_name, "chain", "staking"); | ||
|
||
|
||
// -- Get APIs -- | ||
chain.apis = {}; | ||
chain.apis.rpc = []; | ||
chain.apis.rpc[0] = {}; | ||
chain.apis.rpc[0].address = zone_chain.rpc; | ||
chain.apis.rest = []; | ||
chain.apis.rest[0] = {}; | ||
chain.apis.rest[0].address = zone_chain.rest; | ||
|
||
|
||
// -- Get Explorer Tx URL -- | ||
chain.explorers = []; | ||
chain.explorers[0] = {}; | ||
chain.explorers[0].tx_page = zone_chain.explorer_tx_url; | ||
|
||
|
||
// -- Get Keplr Suggest Chain Features -- | ||
chain.features = zone_chain.keplr_features; | ||
|
||
|
||
// -- Get Outage Alerts -- | ||
chain.outage = zone_chain.outage; | ||
|
||
|
||
// -- Push Chain Object -- | ||
chains.push(chain); | ||
|
||
}); | ||
|
||
} | ||
|
||
function generateChainlist(chainName) { | ||
|
||
chains = []; | ||
let zoneChainlist = getZoneChainlist(chainName); | ||
|
||
generateChains(zoneChainlist.chains); | ||
let chainlist = { | ||
zone: chainName, | ||
chains: chains | ||
} | ||
//console.log(chainlist); | ||
|
||
writeToFile(chainlist, chainName); | ||
|
||
} | ||
|
||
function main() { | ||
|
||
generateChainlist("osmosis"); | ||
generateChainlist("osmosistestnet"); | ||
generateChainlist("osmosistestnet5"); | ||
|
||
} | ||
|
||
main(); |
Oops, something went wrong.