Skip to content

Commit

Permalink
Add Comment Generation
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyParish69 committed Nov 23, 2024
1 parent 182dd36 commit dc26fef
Show file tree
Hide file tree
Showing 6 changed files with 709 additions and 380 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/generate_all_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ jobs:
- name: Run code to Generate Chainlist
working-directory: ./.github/workflows/utility
run: node generate_chainlist.mjs

- name: Run code to Update State
working-directory: ./.github/workflows/utility
run: node update_assetlist_state.mjs

- name: Run code to Generate Zone Assets Comments
working-directory: ./.github/workflows/utility
run: node generateComments.mjs

- name: Add Commit Push
uses: devops-infra/action-commit-push@master
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/utility/assetlist_functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import * as json_mgmt from './json_management.mjs';
//-- Gloabl Constants --

//- Input Files -
export const zoneConfigFileName = "osmosis.zone_config.json";
export const zoneAssetlistFileName = "osmosis.zone_assets.json";
export const zoneChainlistFileName = "osmosis.zone_chains.json";
export const zoneConfigFileName = "osmosis.zone_config.json";
export const zoneAssetlistFileName = "osmosis.zone_assets.json";
export const zoneAssetsFileName = "osmosis.zone_assets.json";
export const zoneChainlistFileName = "osmosis.zone_chains.json";

//- Generated Files -
export const assetlistFileName = "assetlist.json";
Expand All @@ -31,6 +32,7 @@ export const noDir = "";
export const generatedDirectoryName = "generated";
export const chainRegAssetlist = path.join(generatedDirectoryName, "chain_registry");
export const zoneConfigAssetlist = path.join(generatedDirectoryName, "frontend");
export const frontendAssetlistDir = path.join(generatedDirectoryName, "frontend");
export const zoneConfigChainlist = path.join(generatedDirectoryName, "frontend");
export const externalDir = path.join(generatedDirectoryName, "external");
export const zoneAssetDetail = path.join(generatedDirectoryName, "asset_detail");
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/utility/generateComments.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

/* Purpose:
* to manage the comments for each asset in Osmosis Zone Zone_Assets
* which looks like: "_comment": "Asset Name (variant info) $TICKER"
*
*
* Plan:
* Iterate through the zone_assets,
* for each asset, get the name and symbol,
* construct the comment (appending name and symbol together)
* save the comment to the zone_asset object
*
*
* */


//-- Imports --

import * as zone from "./assetlist_functions.mjs";
import * as chain_reg from "../../../chain-registry/.github/workflows/utility/chain_registry.mjs";
chain_reg.setup();
import * as path from 'path';



//-- Files and Directories --
//--


//-- Global Vars --
//--


//-- Functions --
function getZoneAssetsJson(chainName) {
let zoneAssetsJson;
try {
zoneAssetsJson = zone.readFromFile(chainName, zone.noDir, zone.zoneAssetsFileName);
} catch (error) {
if (error.code === 'ENOENT') {
console.warn(`File not found: ${error.message}`);
} else {
throw error;
}
}
return zoneAssetsJson;
}

function getAssetlistAsset(zoneAsset, assetlist) {
if (!zoneAsset.base_denom || !zoneAsset.chain_name) { return; }
return assetlist.find(asset =>
asset.sourceDenom === zoneAsset.base_denom
&&
asset.chainName === zoneAsset.chain_name
);
}

function getAssetComment(assetlistAsset) {
if (!assetlistAsset?.name || !assetlistAsset?.symbol) {
console.log(`Assetlist Asset missing name or symbol. ${assetlistAsset}`);
return;
}
return `${assetlistAsset.name} $${assetlistAsset.symbol}`;
}

function saveZoneAssets(chainName, zoneAssetsJson) {
zone.writeToFile(chainName, zone.noDir, zone.zoneAssetsFileName, zoneAssetsJson);
console.log(`Saved zone_assets for ${chainName}`);
}

function generateComments(chainName) {

const assetlist = zone.readFromFile(chainName, zone.frontendAssetlistDir, zone.assetlistFileName)?.assets;
if (!assetlist) { console.log("Assetlist not found"); return; }

let zoneAssetsJson = getZoneAssetsJson(chainName);
if (!zoneAssetsJson) { return; }
zoneAssetsJson.assets.forEach(zoneAsset => {
if (!zoneAsset.base_denom || !zoneAsset.chain_name) { return; }
const assetlistAsset = getAssetlistAsset(zoneAsset, assetlist);
zoneAsset._comment = getAssetComment(assetlistAsset);
});

saveZoneAssets(chainName, zoneAssetsJson);

}

function main() {
zone.chainNames.forEach(chainName => generateComments(chainName));
}

main();
3 changes: 2 additions & 1 deletion .github/workflows/utility/update_assetlist_state.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ const generateState = (chainName, assetlist) => {
};


function getAssetlistFromFile(chainNAme) {
function getAssetlistFromFile(chainName) {

// Read the generate assetlist
const assetlist = zone.readFromFile(chainName, zone.zoneConfigAssetlist, zone.assetlistFileName);
//console.log(`Generated Assetlist is: ${assetlist}`);
return assetlist;

}

Expand Down
61 changes: 40 additions & 21 deletions osmo-test-5/osmosis.zone_assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
{
"chain_name": "osmosistestnet",
"base_denom": "uosmo",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Osmosis Testnet $OSMO"
},
{
"chain_name": "osmosistestnet",
"base_denom": "uion",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Ion $ION"
},
{
"chain_name": "cosmoshubtestnet",
"base_denom": "uatom",
"path": "transfer/channel-4156/uatom",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "[DEPRECATED] Cosmos Hub Public Testnet, will be sunset 2024-12-01 $ATOM"
},
{
"chain_name": "axelartestnet",
Expand All @@ -25,7 +28,8 @@
"osmosis_verified": true,
"override_properties": {
"symbol": "aUSDC.axl"
}
},
"_comment": "USD Coin (Axelar Testnet) $aUSDC.axl"
},
{
"chain_name": "axelartestnet",
Expand All @@ -34,19 +38,22 @@
"osmosis_verified": true,
"override_properties": {
"symbol": "ETH"
}
},
"_comment": "Ether (Axelar Testnet) $ETH"
},
{
"chain_name": "junotestnet",
"base_denom": "ujunox",
"path": "transfer/channel-5498/ujunox",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Juno Testnet $JUNOX"
},
{
"chain_name": "marstestnet",
"base_denom": "umars",
"path": "transfer/channel-5499/umars",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Mars Hub Testnet $MARS"
},
{
"chain_name": "nobletestnet",
Expand All @@ -55,77 +62,89 @@
"override_properties": {
"coingecko_id": "usd-coin"
},
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "USD Coin $USDC"
},
{
"chain_name": "akashtestnet",
"base_denom": "uakt",
"path": "transfer/channel-4171/uakt",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Sandbox $AKT"
},
{
"chain_name": "kyvetestnet",
"base_denom": "tkyve",
"path": "transfer/channel-10/tkyve",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "KYVE Kaon $KYVE"
},
{
"chain_name": "quicksilvertestnet",
"base_denom": "uqck",
"path": "transfer/channel-13/uqck",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Quicksilver Testnet $QCK"
},
{
"chain_name": "chain4energytestnet",
"base_denom": "uc4e",
"path": "transfer/channel-7735/uc4e",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Chain4Energy Testnet $C4E"
},
{
"chain_name": "persistencetestnet2",
"base_denom": "uxprt",
"path": "transfer/channel-1037/uxprt",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Persistence Testnet $XPRT"
},
{
"chain_name": "xiontestnet",
"base_denom": "uxion",
"path": "transfer/channel-6668/uxion",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Xion Testnet $XION"
},
{
"chain_name": "sagatestnet",
"base_denom": "utsaga",
"path": "transfer/channel-4946/utsaga",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Saga Testnet $TSAGA"
},
{
"chain_name": "impacthubtestnet",
"base_denom": "uixo",
"path": "transfer/channel-1637/uixo",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "ixo $IXO"
},
{
"chain_name": "archwaytestnet",
"base_denom": "aconst",
"path": "transfer/channel-7779/aconst",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Archway Testnet $CONST"
},
{
"chain_name": "symphonytestnet",
"base_denom": "note",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "Symphony Testnet $MLD"
},
{
"chain_name": "kimanetworktestnet",
"base_denom": "uKIMA",
"osmosis_verified": true
"osmosis_verified": true,
"_comment": "KIMA $KIMA"
},
{
"chain_name": "nomictestnet",
"base_denom": "usat",
"osmosis_verified": true,
"_comment": "$nBTC",
"_comment": "Nomic Bitcoin $nBTC",
"override_properties": {
"ibc": {
"type": "ibc",
Expand All @@ -142,4 +161,4 @@
}
}
]
}
}
Loading

0 comments on commit dc26fef

Please sign in to comment.