From 42a07c7b9a2a7e83071591d7f93660192592b412 Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Wed, 17 Apr 2024 18:28:54 +0200 Subject: [PATCH] Augment ibc connections with name+images (#16) --- README.md | 18 ++++++------------ input/penumbra-testnet-deimos-6.json | 16 ++++++++++++++-- npm/CHANGELOG.md | 6 ++++++ npm/package.json | 2 +- npm/src/client.ts | 6 ++++-- registry/penumbra-testnet-deimos-6.json | 23 +++++++++++++++++------ tools/compiler/src/parser.rs | 8 ++++++-- tools/compiler/src/processor.rs | 20 ++++++++++++-------- tools/compiler/src/querier.rs | 8 ++++---- tools/compiler/tests/test_processor.rs | 6 ++++-- 10 files changed, 74 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index d552b78..1cd4614 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This repo contains a registry of metadata for assets on Penumbra. Penumbra records value in its shielded pool tagged by _asset ID_, and client software must map asset IDs to a `Metadata` object describing its base denom, -display units, symbol, asset icons, etc. Because this information is presented +display units, symbol, asset icons, etc. Because this information is presented to users to help them understand their actions, it is relatively security-critical. As in other parts of the Cosmos ecosystem, the expectation for the Penumbra ecosystem is that client software is responsible for choosing @@ -21,8 +21,8 @@ Cosmos chain registry. ### Why not use the Cosmos Chain Registry? We do, but indirectly. The Cosmos chain registry contains data about assets on -Cosmos chains. Penumbra clients require data about assets on Penumbra, -including Penumbra-specific data such as the Penumbra asset ID. The Prax +Cosmos chains. Penumbra clients require data about assets on Penumbra, +including Penumbra-specific data such as the Penumbra asset ID. The Prax registry is a registry of Cosmos assets _on Penumbra_. We also intend to submit metadata about Penumbra assets upstream to the CCR for @@ -45,22 +45,16 @@ The generator expects a specific directory structure: - An `input` directory at the root of the project, containing configuration JSON files for each chain you want to process. -- The `input` directory should contain subdirectories named after each chain's ID, each of which should - contain `ibc-assets.json` and `native-assets.json`. Example: ``` input/ -├── osmosis-test-5/ -│ ├── ibc-assets.json -│ └── native-assets.json -└── mars-1/ - ├── ibc-assets.json - └── native-assets.json +├── penumbra-testnet-deimos-6.json +└── mars-1.json ``` -Each subdirectory should be named with the chain ID. +Each file should be named with the chain ID. ### Output Directory diff --git a/input/penumbra-testnet-deimos-6.json b/input/penumbra-testnet-deimos-6.json index 8e3f840..4695ee1 100644 --- a/input/penumbra-testnet-deimos-6.json +++ b/input/penumbra-testnet-deimos-6.json @@ -13,16 +13,28 @@ ], "ibcConnections": [ { + "displayName": "Osmosis", "chainId": "osmo-test-5", "ibcChannel": "channel-0", "addressPrefix": "osmo", - "cosmosRegistryDir": "testnets/osmosistestnet" + "cosmosRegistryDir": "testnets/osmosistestnet", + "images": [ + { + "svg": "https://raw.githubusercontent.com/cosmos/chain-registry/f1348793beb994c6cc0256ed7ebdb48c7aa70003/osmosis/images/osmo.svg" + } + ] }, { + "displayName": "Noble", "chainId": "grand-1", "ibcChannel": "channel-3", "addressPrefix": "noble", - "cosmosRegistryDir": "testnets/nobletestnet" + "cosmosRegistryDir": "testnets/nobletestnet", + "images": [ + { + "svg": "https://raw.githubusercontent.com/cosmos/chain-registry/2ca39d0e4eaf3431cca13991948e099801f02e46/noble/images/stake.svg" + } + ] } ], "nativeAssets": [ diff --git a/npm/CHANGELOG.md b/npm/CHANGELOG.md index fd87dda..e55a8ad 100644 --- a/npm/CHANGELOG.md +++ b/npm/CHANGELOG.md @@ -1,5 +1,11 @@ # @penumbra-labs/registry +## 3.0.0 + +### Major Changes + +- Augmented and adapted ibc connections + ## 2.0.0 ### Major Changes diff --git a/npm/package.json b/npm/package.json index 4495356..4d7d165 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@penumbra-labs/registry", - "version": "2.0.0", + "version": "3.0.0", "description": "Chain and asset registry for Penumbra", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/npm/src/client.ts b/npm/src/client.ts index 3b006df..9d3f4b3 100644 --- a/npm/src/client.ts +++ b/npm/src/client.ts @@ -10,15 +10,17 @@ type Jsonified = string; export interface Registry { chainId: string; - ibcConfig: IbcConfig[]; + ibcConnections: Chain[]; rpcs: Rpc[]; assetById: Record, Metadata>; } -export interface IbcConfig { +export interface Chain { addressPrefix: string; chainId: string; ibcChannel: string; + images: Image[]; + displayName: string; } export interface Rpc { diff --git a/registry/penumbra-testnet-deimos-6.json b/registry/penumbra-testnet-deimos-6.json index 388b8d6..e39a8a2 100644 --- a/registry/penumbra-testnet-deimos-6.json +++ b/registry/penumbra-testnet-deimos-6.json @@ -1,15 +1,27 @@ { "chainId": "penumbra-testnet-deimos-6", - "ibcConfig": [ + "ibcConnections": [ { "addressPrefix": "osmo", "chainId": "osmo-test-5", - "ibcChannel": "channel-0" + "ibcChannel": "channel-0", + "displayName": "Osmosis", + "images": [ + { + "svg": "https://raw.githubusercontent.com/cosmos/chain-registry/f1348793beb994c6cc0256ed7ebdb48c7aa70003/osmosis/images/osmo.svg" + } + ] }, { "addressPrefix": "noble", "chainId": "grand-1", - "ibcChannel": "channel-3" + "ibcChannel": "channel-3", + "displayName": "Noble", + "images": [ + { + "svg": "https://raw.githubusercontent.com/cosmos/chain-registry/2ca39d0e4eaf3431cca13991948e099801f02e46/noble/images/stake.svg" + } + ] } ], "rpcs": [ @@ -18,8 +30,7 @@ "url": "https://grpc.testnet.penumbra.zone", "images": [ { - "png": "https://raw.githubusercontent.com/prax-wallet/registry/main/images/penumbra-favicon.png", - "svg": null + "png": "https://raw.githubusercontent.com/prax-wallet/registry/main/images/penumbra-favicon.png" } ] } @@ -235,7 +246,7 @@ ], "base": "transfer/channel-0/uosmo", "display": "transfer/channel-0/osmo", - "name": "Osmosis", + "name": "Osmosis Testnet", "symbol": "OSMO", "penumbraAssetId": { "inner": "jIowYEpoMr+LQYqjDVEnQO6hyzb9raVxbO1GLyDxlhI=" diff --git a/tools/compiler/src/parser.rs b/tools/compiler/src/parser.rs index f9db731..2519f08 100644 --- a/tools/compiler/src/parser.rs +++ b/tools/compiler/src/parser.rs @@ -11,7 +11,7 @@ use crate::error::AppResult; pub struct ChainConfig { pub chain_id: String, pub rpcs: Vec, - pub ibc_connections: Vec, + pub ibc_connections: Vec, pub native_assets: Vec, } @@ -24,17 +24,21 @@ pub struct Rpc { #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Image { + #[serde(skip_serializing_if = "Option::is_none")] pub png: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub svg: Option, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct IbcConnection { +pub struct IbcInput { pub chain_id: String, pub ibc_channel: String, pub address_prefix: String, pub cosmos_registry_dir: String, + pub display_name: String, + pub images: Vec, } pub const LOCAL_REGISTRY_DIR: &str = "../../registry"; diff --git a/tools/compiler/src/processor.rs b/tools/compiler/src/processor.rs index fe35a9a..04ca261 100644 --- a/tools/compiler/src/processor.rs +++ b/tools/compiler/src/processor.rs @@ -11,24 +11,28 @@ use tokio::task; use crate::error::AppResult; use crate::github::assetlist_schema::AssetTypeAsset; use crate::parser::{ - get_chain_configs, ChainConfig, IbcConnection, Rpc, LOCAL_INPUT_DIR, LOCAL_REGISTRY_DIR, + get_chain_configs, ChainConfig, IbcInput, Image, Rpc, LOCAL_INPUT_DIR, LOCAL_REGISTRY_DIR, }; use crate::querier::query_github_assets; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct IbcConfig { +pub struct Chain { pub address_prefix: String, pub chain_id: String, pub ibc_channel: String, + pub display_name: String, + pub images: Vec, } -impl From for IbcConfig { - fn from(config: IbcConnection) -> Self { - IbcConfig { +impl From for Chain { + fn from(config: IbcInput) -> Self { + Chain { address_prefix: config.address_prefix, chain_id: config.chain_id, ibc_channel: config.ibc_channel, + display_name: config.display_name, + images: config.images, } } } @@ -37,7 +41,7 @@ impl From for IbcConfig { #[serde(rename_all = "camelCase")] pub struct Registry { pub chain_id: String, - pub ibc_config: Vec, + pub ibc_connections: Vec, pub rpcs: Vec, pub asset_by_id: BTreeMap, // Using a BTreeMap to have sorted (deterministic) output } @@ -68,7 +72,7 @@ pub async fn generate_registry() -> AppResult<()> { /// Given `ibc_data` describing a channel and `source_asset` on the source chain, /// compute the metadata for the asset when it is transported along the channel onto a Penumbra chain. pub fn transport_metadata_along_channel( - ibc_data: &IbcConnection, + ibc_data: &IbcInput, source_asset: Metadata, ) -> AppResult { // The `Metadata` structure doesn't allow modifying the internals, so drop to raw proto data @@ -131,7 +135,7 @@ async fn process_chain_config(chain_config: ChainConfig) -> AppResult Ok(Registry { chain_id: chain_config.chain_id, rpcs: chain_config.rpcs, - ibc_config: chain_config + ibc_connections: chain_config .ibc_connections .into_iter() .map(Into::into) diff --git a/tools/compiler/src/querier.rs b/tools/compiler/src/querier.rs index 5d3b89e..3e800d7 100644 --- a/tools/compiler/src/querier.rs +++ b/tools/compiler/src/querier.rs @@ -2,14 +2,14 @@ use reqwest::Client; use crate::error::AppResult; use crate::github::types::{AssetList, GitHubContent}; -use crate::parser::{ChainConfig, IbcConnection}; +use crate::parser::{ChainConfig, IbcInput}; const GITHUB_API_BASE_URL: &str = "https://api.github.com/repos/cosmos/chain-registry/contents"; /// Queries asset metadata from the cosmos asset registry pub async fn query_github_assets( chain_config: &ChainConfig, -) -> AppResult> { +) -> AppResult> { let client = Client::new(); let mut futures = Vec::new(); @@ -29,8 +29,8 @@ pub async fn query_github_assets( async fn fetch_asset_list( client: &Client, url: String, - ibc_asset: &IbcConnection, -) -> AppResult<(IbcConnection, AssetList)> { + ibc_asset: &IbcInput, +) -> AppResult<(IbcInput, AssetList)> { let res = client .get(&url) .header(reqwest::header::USER_AGENT, "request") diff --git a/tools/compiler/tests/test_processor.rs b/tools/compiler/tests/test_processor.rs index fe5a058..1d467c1 100644 --- a/tools/compiler/tests/test_processor.rs +++ b/tools/compiler/tests/test_processor.rs @@ -1,4 +1,4 @@ -use penumbra_registry::parser::IbcConnection; +use penumbra_registry::parser::IbcInput; use penumbra_registry::processor::{base64_id, transport_metadata_along_channel}; #[test] @@ -20,11 +20,13 @@ fn base64_id_extracts_correctly() { #[test] fn test_transport_metadata_along_channel() { - let ibc_data = IbcConnection { + let ibc_data = IbcInput { ibc_channel: "channel-123".to_string(), chain_id: "love-999".to_string(), address_prefix: "love".to_string(), cosmos_registry_dir: "love-124".to_string(), + display_name: "Strangelove".to_string(), + images: vec![], }; let input_json = r#"