From 5c9b5533d64b36ce4aaf2f5c862c8e10b78411b7 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 4 Feb 2025 17:42:03 -0500 Subject: [PATCH] cosmos: add serde arbitrary precision for i128 --- crates/by-chain/icepick-cosmos/Cargo.toml | 2 +- .../icepick-cosmos/src/coin_denoms.rs | 73 ++++++++++++++++--- crates/by-chain/icepick-cosmos/src/lib.rs | 1 + crates/icepick/Cargo.toml | 2 +- 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/crates/by-chain/icepick-cosmos/Cargo.toml b/crates/by-chain/icepick-cosmos/Cargo.toml index 2516262..fe14b09 100644 --- a/crates/by-chain/icepick-cosmos/Cargo.toml +++ b/crates/by-chain/icepick-cosmos/Cargo.toml @@ -8,7 +8,7 @@ bon = "3.3.2" cosmrs = { version = "0.21.0", features = ["rpc", "tokio"] } icepick-module = { version = "0.1.0", path = "../../icepick-module" } serde.workspace = true -serde_json.workspace = true +serde_json = { workspace = true, features = ["arbitrary_precision"] } thiserror = "2.0.9" tokio = { version = "1.43.0", features = ["rt"] } diff --git a/crates/by-chain/icepick-cosmos/src/coin_denoms.rs b/crates/by-chain/icepick-cosmos/src/coin_denoms.rs index 31a64dd..1a8a4c2 100644 --- a/crates/by-chain/icepick-cosmos/src/coin_denoms.rs +++ b/crates/by-chain/icepick-cosmos/src/coin_denoms.rs @@ -50,6 +50,17 @@ impl Bech32Config { consensus_node_public_prefix: consensus_node_public_prefix.to_string(), } } + + fn with_similar_prefix(prefix: &'static str) -> Self { + Self { + account_address_prefix: format!("{prefix}"), + account_address_public_prefix: format!("{prefix}pub"), + validator_operator_prefix: format!("{prefix}valoper"), + validator_operator_public_prefix: format!("{prefix}valoperpub"), + consensus_node_prefix: format!("{prefix}valcons"), + consensus_node_public_prefix: format!("{prefix}valconspub"), + } + } } #[derive(Clone, Debug, Serialize, Deserialize, Builder)] @@ -152,7 +163,46 @@ impl Blockchain { } } -pub fn default_chains() -> Vec { +fn seda_chains() -> Vec { + let mut chains = vec![]; + + let aseda = Currency::builder() + .coin_denom("seda") + .coin_minimal_denom("aseda") + .coin_decimals(18) + .coin_gecko_id("ID") + .build(); + + let aseda_gas = GasPriceStep::builder() + .low(5000000000.) + .average(10000000000.) + .high(15000000000.) + .build(); + + chains.push( + Blockchain::builder() + .chain_id("seda-1-devnet") + // NOTE: Officially, this is just "devnet", but otherwise this would conflict. + // We'll override it in our config. + .chain_name("seda-devnet") + .rpc_url("https://rpc.devnet.seda.xyz") + .rest_url("https://lcd.devnet.seda.xyz") + .explorer_url_format("https://devnet.explorer.seda.xyz/txs/%s") + .bip44_config(Bip44Config::builder().coin_type(118).build()) + .bech32_config(Bech32Config::with_similar_prefix("seda")) + .currencies(&[aseda.clone()]) + .fee_currencies(&[CurrencyWithGas::builder() + .currency(aseda.clone()) + .gas_price_step(aseda_gas.clone()).build()]) + .gas_price_step(aseda_gas) + .stake_currency(aseda) + .build(), + ); + + chains +} + +fn kyve_chains() -> Vec { let mut chains = vec![]; let tkyve = Currency::builder() @@ -175,16 +225,7 @@ pub fn default_chains() -> Vec { .rest_url("https://api.korellia.kyve.network") .explorer_url_format("https://explorer.kyve.network/korellia/tx/%s") .bip44_config(Bip44Config::builder().coin_type(118).build()) - .bech32_config( - Bech32Config::builder() - .account_address_prefix("kyve") - .account_address_public_prefix("kyvepub") - .validator_operator_prefix("kyvevaloper") - .validator_operator_public_prefix("kyvevaloperpub") - .consensus_node_prefix("kyvevalcons") - .consensus_node_public_prefix("kyvevalconspub") - .build(), - ) + .bech32_config(Bech32Config::with_similar_prefix("kyve")) .currencies(&[tkyve.clone()]) .fee_currencies(&[CurrencyWithGas::builder() .currency(tkyve.clone()) @@ -194,5 +235,15 @@ pub fn default_chains() -> Vec { .stake_currency(tkyve.clone()) .build(), ); + + chains +} + +pub fn default_chains() -> Vec { + let mut chains = vec![]; + + chains.extend(kyve_chains()); + chains.extend(seda_chains()); + chains } diff --git a/crates/by-chain/icepick-cosmos/src/lib.rs b/crates/by-chain/icepick-cosmos/src/lib.rs index 482f54a..a9438bf 100644 --- a/crates/by-chain/icepick-cosmos/src/lib.rs +++ b/crates/by-chain/icepick-cosmos/src/lib.rs @@ -682,6 +682,7 @@ impl Module for Cosmos { } }); let cosmrs::proto::cosmos::base::v1beta1::Coin { denom, amount } = coin; + Ok(serde_json::json!({ "blob": { "balance": { diff --git a/crates/icepick/Cargo.toml b/crates/icepick/Cargo.toml index 79551d3..e0213b8 100644 --- a/crates/icepick/Cargo.toml +++ b/crates/icepick/Cargo.toml @@ -13,7 +13,7 @@ keyforkd-client = { version = "0.2.1", registry = "distrust" } keyforkd-models = { version = "0.2.0", registry = "distrust" } miniquorum = { version = "0.1.0", path = "../miniquorum", default-features = false } serde = { workspace = true, features = ["derive"] } -serde_json.workspace = true +serde_json = { workspace = true, features = ["arbitrary_precision"] } serde_yaml = "0.9.34" thiserror = "2.0.3" toml = "0.8.19"