diff --git a/input/penumbra-testnet-deimos-6.json b/input/penumbra-testnet-deimos-6.json index 4695ee1..fefb419 100644 --- a/input/penumbra-testnet-deimos-6.json +++ b/input/penumbra-testnet-deimos-6.json @@ -211,5 +211,6 @@ } ] } - ] + ], + "canonicalNumeraires": ["wtest_usd", "transfer/channel-3/uusdc"] } \ No newline at end of file diff --git a/npm/CHANGELOG.md b/npm/CHANGELOG.md index e55a8ad..60bb3ee 100644 --- a/npm/CHANGELOG.md +++ b/npm/CHANGELOG.md @@ -1,5 +1,11 @@ # @penumbra-labs/registry +## 4.0.0 + +### Major Changes + +- Added stakingAssetId and numeraires + ## 3.0.0 ### Major Changes diff --git a/npm/package.json b/npm/package.json index 4d7d165..782765d 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@penumbra-labs/registry", - "version": "3.0.0", + "version": "4.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 9d3f4b3..862ffb9 100644 --- a/npm/src/client.ts +++ b/npm/src/client.ts @@ -12,7 +12,9 @@ export interface Registry { chainId: string; ibcConnections: Chain[]; rpcs: Rpc[]; - assetById: Record, Metadata>; + assetById: Record, Jsonified>; + stakingAssetId: Jsonified; + numeraires: Jsonified[]; } export interface Chain { diff --git a/registry/penumbra-testnet-deimos-6.json b/registry/penumbra-testnet-deimos-6.json index e39a8a2..7a2553e 100644 --- a/registry/penumbra-testnet-deimos-6.json +++ b/registry/penumbra-testnet-deimos-6.json @@ -369,5 +369,10 @@ } ] } - } + }, + "stakingAssetId": "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=", + "numeraires": [ + "reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg=", + "CKBQapu+DkQpsKyTfKESLTV19/NPWR5sNZtvQsd3Hw8=" + ] } \ No newline at end of file diff --git a/tools/compiler/src/parser.rs b/tools/compiler/src/parser.rs index 2519f08..713ee54 100644 --- a/tools/compiler/src/parser.rs +++ b/tools/compiler/src/parser.rs @@ -13,6 +13,7 @@ pub struct ChainConfig { pub rpcs: Vec, pub ibc_connections: Vec, pub native_assets: Vec, + pub canonical_numeraires: Vec, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/tools/compiler/src/processor.rs b/tools/compiler/src/processor.rs index 04ca261..57e06cf 100644 --- a/tools/compiler/src/processor.rs +++ b/tools/compiler/src/processor.rs @@ -3,7 +3,8 @@ use std::collections::BTreeMap; use std::fs; use std::path::Path; -use penumbra_asset::asset::Metadata; +use penumbra_asset::asset::{Id, Metadata}; +use penumbra_asset::STAKING_TOKEN_ASSET_ID; use penumbra_proto::penumbra::core::asset::v1 as pb; use serde::{Deserialize, Serialize}; use tokio::task; @@ -44,6 +45,8 @@ pub struct Registry { pub ibc_connections: Vec, pub rpcs: Vec, pub asset_by_id: BTreeMap, // Using a BTreeMap to have sorted (deterministic) output + pub staking_asset_id: String, + pub numeraires: Vec, } pub async fn generate_registry() -> AppResult<()> { @@ -100,8 +103,8 @@ pub fn transport_metadata_along_channel( Ok(Metadata::try_from(pb_metadata)?) } -pub fn base64_id(m: &Metadata) -> AppResult { - let id_json = serde_json::to_value(m.id())?; +pub fn base64_id(id: &Id) -> AppResult { + let id_json = serde_json::to_value(id)?; let base64_str = id_json .get("inner") .and_then(|s| s.as_str()) // This extracts the string without the double quotes @@ -141,11 +144,22 @@ async fn process_chain_config(chain_config: ChainConfig) -> AppResult .map(Into::into) .collect(), asset_by_id: all_metadata + .clone() .into_iter() .map(|m| { - let id = base64_id(&m)?; + let id = base64_id(&m.id())?; Ok((id, m)) }) .collect::>()?, + staking_asset_id: base64_id(&STAKING_TOKEN_ASSET_ID)?, + numeraires: all_metadata + .into_iter() + .filter(|metadata| { + chain_config + .canonical_numeraires + .contains(&metadata.base_denom().denom) + }) + .filter_map(|m| base64_id(&m.id()).ok()) + .collect(), }) } diff --git a/tools/compiler/tests/test_parser.rs b/tools/compiler/tests/test_parser.rs index f49579c..0d0b646 100644 --- a/tools/compiler/tests/test_parser.rs +++ b/tools/compiler/tests/test_parser.rs @@ -19,7 +19,8 @@ fn test_get_chain_configs_reads_configs_correctly() { "chainId": "test-chain-1", "rpcs": [], "ibcConnections": [], - "nativeAssets": [] + "nativeAssets": [], + "canonicalNumeraires": [] }) .to_string(); create_test_config_file(temp_input_dir.path(), "test-chain-1.json", &config_content); @@ -42,7 +43,9 @@ fn test_get_chain_configs_reads_multiple_configs_correctly() { "chainId": "test-chain-1", "rpcs": [], "ibcConnections": [], - "nativeAssets": [] + "nativeAssets": [], + "canonicalNumeraires": [] + }) .to_string(); create_test_config_file( @@ -55,7 +58,9 @@ fn test_get_chain_configs_reads_multiple_configs_correctly() { "chainId": "test-chain-2", "rpcs": [], "ibcConnections": [], - "nativeAssets": [] + "nativeAssets": [], + "canonicalNumeraires": [] + }) .to_string(); create_test_config_file( diff --git a/tools/compiler/tests/test_processor.rs b/tools/compiler/tests/test_processor.rs index 1d467c1..ab31380 100644 --- a/tools/compiler/tests/test_processor.rs +++ b/tools/compiler/tests/test_processor.rs @@ -1,3 +1,4 @@ +use penumbra_asset::asset::Metadata; use penumbra_registry::parser::IbcInput; use penumbra_registry::processor::{base64_id, transport_metadata_along_channel}; @@ -10,10 +11,10 @@ fn base64_id_extracts_correctly() { "inner": "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=" } }"#; - let metadata = serde_json::from_str(asset_json).unwrap(); + let metadata: Metadata = serde_json::from_str(asset_json).unwrap(); assert_eq!( - base64_id(&metadata).unwrap(), + base64_id(&metadata.id()).unwrap(), "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=" ); }