From ea1fe46bfc483e2ad38e157b86270ea4a26e2d71 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Tue, 22 Oct 2024 18:34:50 +0400 Subject: [PATCH 1/4] Fix upenumbra priority score and adjust scores of assets --- input/chains/penumbra-1.json | 16 ++++++++-------- registry/chains/penumbra-1.json | 19 ++++++++++--------- tools/compiler/src/processor.rs | 8 ++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/input/chains/penumbra-1.json b/input/chains/penumbra-1.json index 0fdba06..985528c 100644 --- a/input/chains/penumbra-1.json +++ b/input/chains/penumbra-1.json @@ -105,14 +105,14 @@ "priorityScoresByBase": { "upenumbra": 999999999999, "transfer/channel-2/uusdc": 100000000000, - "transfer/channel-4/factory/osmo1em6xs47hd82806f5cxgyufguxrrc7l0aqx7nzzptjuqgswczk8csavdxek/alloyed/allUSDT": 10000000000, - "transfer/channel-4/factory/osmo1k6c8jln7ejuqwtqmay3yvzrg3kueaczl96pk067ldg8u835w0yhsw27twm/alloyed/allETH": 10000000000, - "transfer/channel-4/factory/osmo1n3n75av8awcnw4jl62n3l48e6e4sxqmaf97w5ua6ddu4s475q5qq9udvx4/alloyed/allSOL": 10000000000, - "transfer/channel-4/factory/osmo1z6r6qdknhgsc0zeracktgpcxf43j6sekq07nw8sxduc9lg0qjjlqfu25e3/alloyed/allBTC": 10000000000, - "transfer/channel-4/factory/osmo1z0qrq605sjgcqpylfl4aa6s90x738j7m58wyatt0tdzflg2ha26q67k743/wbtc": 10000000000, - "transfer/channel-4/factory/osmo18zdw5yvs6gfp95rp74qqwug9yduw2fyr8kplk2xgs726s9axc5usa2vpgw/alloyed/allLINK": 1000000000, - "transfer/channel-4/factory/osmo1r53fx9fvcdzncrs7zkn4gw5vfelx5gk8k5wc6wqha2jpkh992rusr5tk02/alloyed/allDOT": 1000000000, - "transfer/channel-4/factory/osmo14mafhhp337yjj2aujplawz0tks6jd2lel4hkwz4agyzhvvztzaqsqzjq8x/alloyed/allTRX": 100000000, + "transfer/channel-4/factory/osmo1em6xs47hd82806f5cxgyufguxrrc7l0aqx7nzzptjuqgswczk8csavdxek/alloyed/allUSDT": 100000000000, + "transfer/channel-4/factory/osmo1z6r6qdknhgsc0zeracktgpcxf43j6sekq07nw8sxduc9lg0qjjlqfu25e3/alloyed/allBTC": 70000000000, + "transfer/channel-4/factory/osmo1z0qrq605sjgcqpylfl4aa6s90x738j7m58wyatt0tdzflg2ha26q67k743/wbtc": 70000000000, + "transfer/channel-4/factory/osmo1k6c8jln7ejuqwtqmay3yvzrg3kueaczl96pk067ldg8u835w0yhsw27twm/alloyed/allETH": 60000000000, + "transfer/channel-4/factory/osmo1n3n75av8awcnw4jl62n3l48e6e4sxqmaf97w5ua6ddu4s475q5qq9udvx4/alloyed/allSOL": 50000000000, + "transfer/channel-4/factory/osmo18zdw5yvs6gfp95rp74qqwug9yduw2fyr8kplk2xgs726s9axc5usa2vpgw/alloyed/allLINK": 4000000000, + "transfer/channel-4/factory/osmo1r53fx9fvcdzncrs7zkn4gw5vfelx5gk8k5wc6wqha2jpkh992rusr5tk02/alloyed/allDOT": 3000000000, + "transfer/channel-4/factory/osmo14mafhhp337yjj2aujplawz0tks6jd2lel4hkwz4agyzhvvztzaqsqzjq8x/alloyed/allTRX": 200000000, "transfer/channel-4/factory/osmo1p7x454ex08s4f9ztmm7wfv7lvtgdkfztj2u7v7fezfcauy85q35qmqrdpk/alloyed/allARB": 100000000, "transfer/channel-4/factory/osmo1nufyzqlm8qhu2w7lm0l4rrax0ec8rsk69mga4tel8eare7c7ljaqpk2lyg/alloyed/allOP": 100000000, "transfer/channel-4/factory/osmo12lnwf54yd30p6amzaged2atln8k0l32n7ncxf04ctg7u7ymnsy7qkqgsw4/alloyed/allTON": 100000000, diff --git a/registry/chains/penumbra-1.json b/registry/chains/penumbra-1.json index ebc6c9d..8451779 100644 --- a/registry/chains/penumbra-1.json +++ b/registry/chains/penumbra-1.json @@ -238,7 +238,7 @@ } } ], - "priorityScore": "100000000" + "priorityScore": "200000000" }, "5B0jxWP9LX+U4uD7aU9OVsIk0U385uD2q+a2eEerHg0=": { "description": "Cosmos Airdrop Chat", @@ -744,7 +744,8 @@ { "svg": "https://raw.githubusercontent.com/prax-wallet/registry/main/images/um.svg" } - ] + ], + "priorityScore": "999999999999" }, "LdexCcIS7h5jbSjieMV+MoC2IB1XmuKxzNNeRgq4QAQ=": { "description": "An alloy of SOL asset variants on Osmosis.", @@ -787,7 +788,7 @@ "theme": {} } ], - "priorityScore": "10000000000" + "priorityScore": "50000000000" }, "MMDbC4jQ7GUP6yEU+Yo2xkW85LyRKJASJN4MPHAPmhE=": { "description": "Levana Well-funded Perps is a protocol for perpetual swaps, which are leveraged trading contracts.", @@ -1108,7 +1109,7 @@ "svg": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/allBTC.svg" } ], - "priorityScore": "10000000000" + "priorityScore": "70000000000" }, "Rvh55FJrd8q3kT8xYIl5ApTOc9ErxyL8m1NS5RArHxE=": { "description": "An alloy of OP asset variants on Osmosis.", @@ -1188,7 +1189,7 @@ } } ], - "priorityScore": "1000000000" + "priorityScore": "3000000000" }, "SChNnza9qDQMNGqwSoQMzB2x2M5nmEBtST1EoSy29gM=": { "description": "An alloy of UNI asset variants on Osmosis.", @@ -1290,7 +1291,7 @@ } } ], - "priorityScore": "10000000000" + "priorityScore": "70000000000" }, "UxSzPuz9XKLpnAttHgzK/j0t1YHJUtgU+2T99R+FxBE=": { "description": "Celestia is a modular blockchain network focused on data availability, allowing developers to deploy their own customizable blockchains with ease.", @@ -1677,7 +1678,7 @@ } } ], - "priorityScore": "1000000000" + "priorityScore": "4000000000" }, "hOnMqQbpe5Abe7vvfHYda77fg3Zit88fatqDfPO1bgQ=": { "description": "An alloy of SHIB asset variants on Osmosis.", @@ -2130,7 +2131,7 @@ "svg": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/allUSDT.svg" } ], - "priorityScore": "10000000000" + "priorityScore": "100000000000" }, "vSCVmtndzw2C2RYuB2vcKWfkPVZRCP9GNN8MwB6QUAU=": { "description": "Cosmus Cartol always get rich", @@ -2254,7 +2255,7 @@ "svg": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/allETH.svg" } ], - "priorityScore": "10000000000" + "priorityScore": "60000000000" }, "xNdg/Pc2CvrtawUX41EBLTlgj83RTenRJaBFXxsSTwk=": { "description": "ION is the second native token of Osmosis.", diff --git a/tools/compiler/src/processor.rs b/tools/compiler/src/processor.rs index 1cdd58a..2f47c06 100644 --- a/tools/compiler/src/processor.rs +++ b/tools/compiler/src/processor.rs @@ -152,6 +152,14 @@ fn process_chain_config(chain_config: ChainConfig) -> AppResult { all_metadata.extend(generate_metadata_from_validators(&chain_config.validators)?); all_metadata.extend(chain_config.native_assets.clone()); + for metadata in &mut all_metadata { + if let Some(score) = chain_config.priority_scores_by_base.get(&metadata.base_denom().denom) { + let mut pb_metadata: pb::Metadata = metadata.clone().into(); + pb_metadata.priority_score = *score; + *metadata = Metadata::try_from(pb_metadata)?; + } + } + // For each ibc connection, grab all metadata of native assets from the cosmos registry for ibc_input in &chain_config.ibc_connections { let assetlist_path = Path::new(LOCAL_COSMOS_REGISTRY_DIR) From baea63297eb5c5fc9b5ecb8899ebb0e143b5fef3 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Tue, 22 Oct 2024 18:43:45 +0400 Subject: [PATCH 2/4] Refactored to use single place for adding priority scores --- tools/compiler/src/processor.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tools/compiler/src/processor.rs b/tools/compiler/src/processor.rs index 2f47c06..8bd585a 100644 --- a/tools/compiler/src/processor.rs +++ b/tools/compiler/src/processor.rs @@ -1,6 +1,5 @@ use anyhow::anyhow; use std::collections::BTreeMap; -use std::collections::HashMap; use std::fs; use std::path::Path; use tracing::instrument; @@ -103,7 +102,6 @@ pub fn generate_registry() -> AppResult<()> { pub fn transport_metadata_along_channel( ibc_data: &IbcInput, source_asset: Metadata, - priority_scores_by_base: &HashMap, ) -> AppResult { // The `Metadata` structure doesn't allow modifying the internals, so drop to raw proto data let mut pb_metadata: pb::Metadata = source_asset.into(); @@ -126,11 +124,6 @@ pub fn transport_metadata_along_channel( // Without this, decoding will fail because the asset ID won't match. pb_metadata.penumbra_asset_id = None; - // Add priority score if available - if let Some(score) = priority_scores_by_base.get(&pb_metadata.base) { - pb_metadata.priority_score = *score; - } - tracing::trace!(?pb_metadata, "new"); Ok(Metadata::try_from(pb_metadata)?) } @@ -152,14 +145,6 @@ fn process_chain_config(chain_config: ChainConfig) -> AppResult { all_metadata.extend(generate_metadata_from_validators(&chain_config.validators)?); all_metadata.extend(chain_config.native_assets.clone()); - for metadata in &mut all_metadata { - if let Some(score) = chain_config.priority_scores_by_base.get(&metadata.base_denom().denom) { - let mut pb_metadata: pb::Metadata = metadata.clone().into(); - pb_metadata.priority_score = *score; - *metadata = Metadata::try_from(pb_metadata)?; - } - } - // For each ibc connection, grab all metadata of native assets from the cosmos registry for ibc_input in &chain_config.ibc_connections { let assetlist_path = Path::new(LOCAL_COSMOS_REGISTRY_DIR) @@ -182,12 +167,20 @@ fn process_chain_config(chain_config: ChainConfig) -> AppResult { let transferred_asset = transport_metadata_along_channel( ibc_input, source_asset_metadata, - &chain_config.priority_scores_by_base, )?; all_metadata.push(transferred_asset); } } + // add priority score if available + for metadata in &mut all_metadata { + if let Some(score) = chain_config.priority_scores_by_base.get(&metadata.base_denom().denom) { + let mut pb_metadata: pb::Metadata = metadata.clone().into(); + pb_metadata.priority_score = *score; + *metadata = Metadata::try_from(pb_metadata)?; + } + } + Ok(Registry { chain_id: chain_config.chain_id, ibc_connections: chain_config From 6d6777fc3964bb2f52f44f12b58fe15d2edda530 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Tue, 22 Oct 2024 18:46:13 +0400 Subject: [PATCH 3/4] Formatted code --- tools/compiler/src/processor.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/compiler/src/processor.rs b/tools/compiler/src/processor.rs index 8bd585a..6cdfcf0 100644 --- a/tools/compiler/src/processor.rs +++ b/tools/compiler/src/processor.rs @@ -164,17 +164,18 @@ fn process_chain_config(chain_config: ChainConfig) -> AppResult { let asset_json = serde_json::to_string(&source_asset)?; let source_asset_metadata = serde_json::from_str(&asset_json)?; - let transferred_asset = transport_metadata_along_channel( - ibc_input, - source_asset_metadata, - )?; + let transferred_asset = + transport_metadata_along_channel(ibc_input, source_asset_metadata)?; all_metadata.push(transferred_asset); } } // add priority score if available for metadata in &mut all_metadata { - if let Some(score) = chain_config.priority_scores_by_base.get(&metadata.base_denom().denom) { + if let Some(score) = chain_config + .priority_scores_by_base + .get(&metadata.base_denom().denom) + { let mut pb_metadata: pb::Metadata = metadata.clone().into(); pb_metadata.priority_score = *score; *metadata = Metadata::try_from(pb_metadata)?; From d9b8995cac57ab7d8cabed1a93ba00637252787c Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Tue, 22 Oct 2024 18:47:47 +0400 Subject: [PATCH 4/4] Remove priority_scores_by_base from transport_metadata_along_channel test --- tools/compiler/tests/test_processor.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tools/compiler/tests/test_processor.rs b/tools/compiler/tests/test_processor.rs index 2f315f6..1375ec3 100644 --- a/tools/compiler/tests/test_processor.rs +++ b/tools/compiler/tests/test_processor.rs @@ -52,14 +52,6 @@ fn test_transport_metadata_along_channel() { "#; let input_metadata = serde_json::from_str(input_json).unwrap(); - let priority_scores_by_base = r#" - { - "transfer/channel-123/ugm": 7 - } - "#; - - let priority_scores_by_base_json = serde_json::from_str(priority_scores_by_base).unwrap(); - let output_json = r#" { "denomUnits": [ @@ -76,14 +68,11 @@ fn test_transport_metadata_along_channel() { "symbol": "GM", "penumbraAssetId": { "inner": "YGObCaxvA7dR5tg6FeoNDxIGbwl9HK5eYr7jFho/GwQ=" - }, - "priorityScore": "7" + } } "#; let output_metadata = serde_json::from_str(output_json).unwrap(); - let result = - transport_metadata_along_channel(&ibc_data, input_metadata, &priority_scores_by_base_json) - .unwrap(); + let result = transport_metadata_along_channel(&ibc_data, input_metadata).unwrap(); assert_eq!(result, output_metadata); }