Skip to content

Commit

Permalink
Add staking token and numeraires (#17)
Browse files Browse the repository at this point in the history
* Add staking token and numeraires

* changeset

* changelog
  • Loading branch information
Valentine1898 authored Apr 18, 2024
1 parent 42a07c7 commit d60dca0
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 13 deletions.
3 changes: 2 additions & 1 deletion input/penumbra-testnet-deimos-6.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,6 @@
}
]
}
]
],
"canonicalNumeraires": ["wtest_usd", "transfer/channel-3/uusdc"]
}
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

## 4.0.0

### Major Changes

- Added stakingAssetId and numeraires

## 3.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": "3.0.0",
"version": "4.0.0",
"description": "Chain and asset registry for Penumbra",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
4 changes: 3 additions & 1 deletion npm/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export interface Registry {
chainId: string;
ibcConnections: Chain[];
rpcs: Rpc[];
assetById: Record<Jsonified<AssetId>, Metadata>;
assetById: Record<Jsonified<AssetId>, Jsonified<Metadata>>;
stakingAssetId: Jsonified<AssetId>;
numeraires: Jsonified<AssetId>[];
}

export interface Chain {
Expand Down
7 changes: 6 additions & 1 deletion registry/penumbra-testnet-deimos-6.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,10 @@
}
]
}
}
},
"stakingAssetId": "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=",
"numeraires": [
"reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg=",
"CKBQapu+DkQpsKyTfKESLTV19/NPWR5sNZtvQsd3Hw8="
]
}
1 change: 1 addition & 0 deletions tools/compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct ChainConfig {
pub rpcs: Vec<Rpc>,
pub ibc_connections: Vec<IbcInput>,
pub native_assets: Vec<Metadata>,
pub canonical_numeraires: Vec<String>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down
22 changes: 18 additions & 4 deletions tools/compiler/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,8 @@ pub struct Registry {
pub ibc_connections: Vec<Chain>,
pub rpcs: Vec<Rpc>,
pub asset_by_id: BTreeMap<String, Metadata>, // Using a BTreeMap to have sorted (deterministic) output
pub staking_asset_id: String,
pub numeraires: Vec<String>,
}

pub async fn generate_registry() -> AppResult<()> {
Expand Down Expand Up @@ -100,8 +103,8 @@ pub fn transport_metadata_along_channel(
Ok(Metadata::try_from(pb_metadata)?)
}

pub fn base64_id(m: &Metadata) -> AppResult<String> {
let id_json = serde_json::to_value(m.id())?;
pub fn base64_id(id: &Id) -> AppResult<String> {
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
Expand Down Expand Up @@ -141,11 +144,22 @@ async fn process_chain_config(chain_config: ChainConfig) -> AppResult<Registry>
.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::<AppResult<_>>()?,
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(),
})
}
11 changes: 8 additions & 3 deletions tools/compiler/tests/test_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions tools/compiler/tests/test_processor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use penumbra_asset::asset::Metadata;
use penumbra_registry::parser::IbcInput;
use penumbra_registry::processor::{base64_id, transport_metadata_along_channel};

Expand All @@ -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="
);
}
Expand Down

0 comments on commit d60dca0

Please sign in to comment.