Skip to content

Commit

Permalink
Augment ibc connections with name+images (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 authored Apr 17, 2024
1 parent fa61d0e commit 42a07c7
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 39 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
16 changes: 14 additions & 2 deletions input/penumbra-testnet-deimos-6.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 6 additions & 0 deletions npm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @penumbra-labs/registry

## 3.0.0

### Major Changes

- Augmented and adapted ibc connections

## 2.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions npm/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ type Jsonified<T> = string;

export interface Registry {
chainId: string;
ibcConfig: IbcConfig[];
ibcConnections: Chain[];
rpcs: Rpc[];
assetById: Record<Jsonified<AssetId>, Metadata>;
}

export interface IbcConfig {
export interface Chain {
addressPrefix: string;
chainId: string;
ibcChannel: string;
images: Image[];
displayName: string;
}

export interface Rpc {
Expand Down
23 changes: 17 additions & 6 deletions registry/penumbra-testnet-deimos-6.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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"
}
]
}
Expand Down Expand Up @@ -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="
Expand Down
8 changes: 6 additions & 2 deletions tools/compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::error::AppResult;
pub struct ChainConfig {
pub chain_id: String,
pub rpcs: Vec<Rpc>,
pub ibc_connections: Vec<IbcConnection>,
pub ibc_connections: Vec<IbcInput>,
pub native_assets: Vec<Metadata>,
}

Expand All @@ -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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub svg: Option<String>,
}

#[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<Image>,
}

pub const LOCAL_REGISTRY_DIR: &str = "../../registry";
Expand Down
20 changes: 12 additions & 8 deletions tools/compiler/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Image>,
}

impl From<IbcConnection> for IbcConfig {
fn from(config: IbcConnection) -> Self {
IbcConfig {
impl From<IbcInput> 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,
}
}
}
Expand All @@ -37,7 +41,7 @@ impl From<IbcConnection> for IbcConfig {
#[serde(rename_all = "camelCase")]
pub struct Registry {
pub chain_id: String,
pub ibc_config: Vec<IbcConfig>,
pub ibc_connections: Vec<Chain>,
pub rpcs: Vec<Rpc>,
pub asset_by_id: BTreeMap<String, Metadata>, // Using a BTreeMap to have sorted (deterministic) output
}
Expand Down Expand Up @@ -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<Metadata> {
// The `Metadata` structure doesn't allow modifying the internals, so drop to raw proto data
Expand Down Expand Up @@ -131,7 +135,7 @@ async fn process_chain_config(chain_config: ChainConfig) -> AppResult<Registry>
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)
Expand Down
8 changes: 4 additions & 4 deletions tools/compiler/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<(IbcConnection, AssetList)>> {
) -> AppResult<Vec<(IbcInput, AssetList)>> {
let client = Client::new();
let mut futures = Vec::new();

Expand All @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions tools/compiler/tests/test_processor.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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#"
Expand Down

0 comments on commit 42a07c7

Please sign in to comment.