diff --git a/common/client-libs/validator-client/src/nymd/fee/mod.rs b/common/client-libs/validator-client/src/nymd/fee/mod.rs index aefb953900..84dad1b158 100644 --- a/common/client-libs/validator-client/src/nymd/fee/mod.rs +++ b/common/client-libs/validator-client/src/nymd/fee/mod.rs @@ -4,6 +4,7 @@ use crate::nymd::Coin; use cosmrs::tx; use serde::{Deserialize, Serialize}; +use std::fmt::{Display, Formatter}; pub mod gas_price; @@ -15,6 +16,12 @@ pub enum Fee { Auto(Option), } +impl Display for Fee { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + todo!() + } +} + impl Fee { pub fn try_get_manual_amount(&self) -> Option> { match self { diff --git a/common/types/src/currency.rs b/common/types/src/currency.rs index 4fa96fda9c..e10741a98f 100644 --- a/common/types/src/currency.rs +++ b/common/types/src/currency.rs @@ -34,6 +34,7 @@ pub type Denom = String; #[serde(rename_all = "UPPERCASE")] #[strum(serialize_all = "UPPERCASE")] // TODO: this shouldn't be an enum... +#[deprecated] pub enum CurrencyDenom { #[strum(ascii_case_insensitive)] Nym, @@ -72,6 +73,7 @@ impl TryFrom for CurrencyDenom { ts(export_to = "ts-packages/types/src/types/rust/CurrencyStringMajorAmount.ts") )] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[deprecated] pub struct MajorAmountString(String); // see https://github.com/Aleph-Alpha/ts-rs/issues/51 for exporting type aliases #[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))] @@ -80,6 +82,7 @@ pub struct MajorAmountString(String); // see https://github.com/Aleph-Alpha/ts-r ts(export_to = "ts-packages/types/src/types/rust/Currency.ts") )] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[deprecated] pub struct MajorCurrencyAmount { pub amount: MajorAmountString, pub denom: CurrencyDenom, diff --git a/common/types/src/gas.rs b/common/types/src/gas.rs index 22cf8ba6dc..9441008569 100644 --- a/common/types/src/gas.rs +++ b/common/types/src/gas.rs @@ -1,9 +1,6 @@ -use crate::currency::MajorCurrencyAmount; -use crate::error::TypesError; use cosmrs::tx::Gas as CosmrsGas; use serde::{Deserialize, Serialize}; use validator_client::nymd::cosmwasm_client::types::GasInfo as ValidatorClientGasInfo; -use validator_client::nymd::GasPrice; #[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))] #[cfg_attr( diff --git a/nym-wallet/src-tauri/src/operations/mixnet/bond.rs b/nym-wallet/src-tauri/src/operations/mixnet/bond.rs index e078d016e3..24401aa338 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/bond.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/bond.rs @@ -110,6 +110,7 @@ pub async fn update_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { + let guard = state.read().await; let fee_amount = guard.convert_tx_fee(fee.as_ref()); log::info!( ">>> Update mixnode: profit_margin_percent = {}, fee {:?}", diff --git a/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs b/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs index 1402b3f80f..d894c0b41f 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs @@ -96,7 +96,7 @@ struct DelegationWithHistory { pub async fn get_all_mix_delegations( state: tauri::State<'_, Arc>>, ) -> Result, BackendError> { - todo!("deal with this later :)") + todo!("deal with this later :)"); log::info!(">>> Get all mixnode delegations"); // @@ -341,7 +341,7 @@ pub async fn get_delegator_rewards( pub async fn get_delegation_summary( state: tauri::State<'_, Arc>>, ) -> Result { - todo!("also deal with later : )") + todo!("also deal with later : )"); log::info!(">>> Get delegation summary"); // let denom_minor = state.read().await.current_network().denom(); diff --git a/nym-wallet/src-tauri/src/operations/vesting/bond.rs b/nym-wallet/src-tauri/src/operations/vesting/bond.rs index 67df1a2e6d..f624c9d36a 100644 --- a/nym-wallet/src-tauri/src/operations/vesting/bond.rs +++ b/nym-wallet/src-tauri/src/operations/vesting/bond.rs @@ -3,7 +3,7 @@ use crate::nymd_client; use crate::state::State; use crate::{Gateway, MixNode}; -use nym_types::currency::MajorCurrencyAmount; +use nym_types::currency::DecCoin; use nym_types::transaction::TransactionExecuteResult; use std::sync::Arc; use tokio::sync::RwLock; @@ -12,28 +12,31 @@ use validator_client::nymd::{Fee, VestingSigningClient}; #[tauri::command] pub async fn vesting_bond_gateway( gateway: Gateway, - pledge: MajorCurrencyAmount, + pledge: DecCoin, owner_signature: String, fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); - let pledge_minor = pledge.clone().into(); + let guard = state.read().await; + let pledge_base = guard.attempt_convert_to_base_coin(pledge.clone())?; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); + log::info!( - ">>> Bond gateway with locked tokens: identity_key = {}, pledge = {}, pledge_minor = {}, fee = {:?}", - gateway.identity_key, - pledge, - pledge_minor, - fee, - ); - let res = nymd_client!(state) - .vesting_bond_gateway(gateway, &owner_signature, pledge_minor, fee) + ">>> Bond gateway with locked tokens: identity_key = {}, pledge_display = {}, pledge_base = {}, fee = {:?}", + gateway.identity_key, + pledge, + pledge_base, + fee, + ); + let res = guard + .current_client()? + .nymd + .vesting_bond_gateway(gateway, &owner_signature, pledge_base, fee) .await?; log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } @@ -42,7 +45,8 @@ pub async fn vesting_unbond_gateway( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); + let guard = state.read().await; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); log::info!( ">>> Unbond gateway bonded with locked tokens, fee = {:?}", fee @@ -51,8 +55,7 @@ pub async fn vesting_unbond_gateway( log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } @@ -60,27 +63,30 @@ pub async fn vesting_unbond_gateway( pub async fn vesting_bond_mixnode( mixnode: MixNode, owner_signature: String, - pledge: MajorCurrencyAmount, + pledge: DecCoin, fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); - let pledge_minor = pledge.clone().into(); + let guard = state.read().await; + let pledge_base = guard.attempt_convert_to_base_coin(pledge.clone())?; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); + log::info!( - ">>> Bond mixnode with locked tokens: identity_key = {}, pledge = {}, pledge_minor = {}, fee = {:?}", + ">>> Bond mixnode with locked tokens: identity_key = {}, pledge_display = {}, pledge_base = {}, fee = {:?}", mixnode.identity_key, pledge, - pledge_minor, + pledge_base, fee ); - let res = nymd_client!(state) - .vesting_bond_mixnode(mixnode, &owner_signature, pledge_minor, fee) + let res = guard + .current_client()? + .nymd + .vesting_bond_mixnode(mixnode, &owner_signature, pledge_base, fee) .await?; log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } @@ -89,42 +95,49 @@ pub async fn vesting_unbond_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); + let guard = state.read().await; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); log::info!( ">>> Unbond mixnode bonded with locked tokens, fee = {:?}", fee ); - let res = nymd_client!(state).vesting_unbond_mixnode(fee).await?; + let res = guard + .current_client()? + .nymd + .vesting_unbond_mixnode(fee) + .await?; log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } #[tauri::command] pub async fn withdraw_vested_coins( - amount: MajorCurrencyAmount, + amount: DecCoin, fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); - let amount_minor = amount.clone().into(); + let guard = state.read().await; + let amount_base = guard.attempt_convert_to_base_coin(amount.clone())?; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); + log::info!( - ">>> Withdraw vested liquid coins: amount = {}, amount_minor = {}, fee = {:?}", + ">>> Withdraw vested liquid coins: amount_base = {}, amount_base = {}, fee = {:?}", amount, - amount_minor, + amount_base, fee ); - let res = nymd_client!(state) - .withdraw_vested_coins(amount_minor, fee) + let res = guard + .current_client()? + .nymd + .withdraw_vested_coins(amount_base, fee) .await?; log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } @@ -134,19 +147,21 @@ pub async fn vesting_update_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); + let guard = state.read().await; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); log::info!( ">>> Update mixnode bonded with locked tokens: profit_margin_percent = {}, fee = {:?}", profit_margin_percent, fee, ); - let res = nymd_client!(state) + let res = guard + .current_client()? + .nymd .vesting_update_mixnode_config(profit_margin_percent, fee) .await?; log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } diff --git a/nym-wallet/src-tauri/src/operations/vesting/delegate.rs b/nym-wallet/src-tauri/src/operations/vesting/delegate.rs index bf6eca6838..3e83fa284e 100644 --- a/nym-wallet/src-tauri/src/operations/vesting/delegate.rs +++ b/nym-wallet/src-tauri/src/operations/vesting/delegate.rs @@ -1,15 +1,12 @@ -use std::sync::Arc; - -use tokio::sync::RwLock; - -use nym_types::currency::MajorCurrencyAmount; -use nym_types::delegation::{from_contract_delegation_events, DelegationEvent}; -use nym_types::transaction::TransactionExecuteResult; -use validator_client::nymd::{Fee, VestingSigningClient}; - use crate::error::BackendError; use crate::nymd_client; use crate::state::State; +use nym_types::currency::DecCoin; +use nym_types::delegation::{from_contract_delegation_events, DelegationEvent}; +use nym_types::transaction::TransactionExecuteResult; +use std::sync::Arc; +use tokio::sync::RwLock; +use validator_client::nymd::{Fee, VestingSigningClient}; #[tauri::command] pub async fn get_pending_vesting_delegation_events( @@ -40,27 +37,30 @@ pub async fn get_pending_vesting_delegation_events( #[tauri::command] pub async fn vesting_delegate_to_mixnode( identity: &str, - amount: MajorCurrencyAmount, + amount: DecCoin, fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); - let delegation = amount.clone().into(); + let guard = state.read().await; + let delegation = guard.attempt_convert_to_base_coin(amount.clone())?; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); + log::info!( - ">>> Delegate to mixnode with locked tokens: identity_key = {}, amount = {}, minor_amount = {}, fee = {:?}", + ">>> Delegate to mixnode with locked tokens: identity_key = {}, amount_display = {}, amount_base = {}, fee = {:?}", identity, amount, delegation, fee ); - let res = nymd_client!(state) + let res = guard + .current_client()? + .nymd .vesting_delegate_to_mixnode(identity, delegation, fee) .await?; log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } @@ -70,19 +70,21 @@ pub async fn vesting_undelegate_from_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom_minor = state.read().await.current_network().denom(); + let guard = state.read().await; + let fee_amount = guard.convert_tx_fee(fee.as_ref()); log::info!( ">>> Undelegate from mixnode delegated with locked tokens: identity_key = {}, fee = {:?}", identity, fee, ); - let res = nymd_client!(state) + let res = guard + .current_client()? + .nymd .vesting_undelegate_from_mixnode(identity, fee) .await?; log::info!("<<< tx hash = {}", res.transaction_hash); log::trace!("<<< {:?}", res); Ok(TransactionExecuteResult::from_execute_result( - res, - denom_minor.as_ref(), + res, fee_amount, )?) } diff --git a/nym-wallet/src-tauri/src/operations/vesting/queries.rs b/nym-wallet/src-tauri/src/operations/vesting/queries.rs index 72c85f69d7..0a21f0966c 100644 --- a/nym-wallet/src-tauri/src/operations/vesting/queries.rs +++ b/nym-wallet/src-tauri/src/operations/vesting/queries.rs @@ -1,23 +1,20 @@ -use std::sync::Arc; - -use cosmwasm_std::Timestamp; -use tokio::sync::RwLock; - -use nym_types::currency::MajorCurrencyAmount; -use nym_types::vesting::VestingAccountInfo; -use nym_types::vesting::{OriginalVestingResponse, PledgeData}; -use validator_client::nymd::VestingQueryClient; -use vesting_contract_common::Period; - use crate::error::BackendError; use crate::nymd_client; use crate::state::State; +use cosmwasm_std::Timestamp; +use nym_types::currency::DecCoin; +use nym_types::vesting::VestingAccountInfo; +use nym_types::vesting::{OriginalVestingResponse, PledgeData}; +use std::sync::Arc; +use tokio::sync::RwLock; +use validator_client::nymd::VestingQueryClient; +use vesting_contract_common::Period; #[tauri::command] pub async fn locked_coins( block_time: Option, state: tauri::State<'_, Arc>>, -) -> Result { +) -> Result { log::info!(">>> Query locked coins"); let res = nymd_client!(state) .locked_coins( @@ -34,7 +31,7 @@ pub async fn locked_coins( pub async fn spendable_coins( block_time: Option, state: tauri::State<'_, Arc>>, -) -> Result { +) -> Result { log::info!(">>> Query spendable coins"); let res = nymd_client!(state) .spendable_coins( @@ -52,7 +49,7 @@ pub async fn vested_coins( vesting_account_address: &str, block_time: Option, state: tauri::State<'_, Arc>>, -) -> Result { +) -> Result { log::info!(">>> Query vested coins"); let res = nymd_client!(state) .vested_coins( @@ -70,7 +67,7 @@ pub async fn vesting_coins( vesting_account_address: &str, block_time: Option, state: tauri::State<'_, Arc>>, -) -> Result { +) -> Result { log::info!(">>> Query vesting coins"); let res = nymd_client!(state) .vesting_coins( @@ -130,7 +127,7 @@ pub async fn delegated_free( vesting_account_address: &str, block_time: Option, state: tauri::State<'_, Arc>>, -) -> Result { +) -> Result { log::info!(">>> Query delegated free"); let res = nymd_client!(state) .delegated_free( @@ -149,7 +146,7 @@ pub async fn delegated_vesting( block_time: Option, vesting_account_address: &str, state: tauri::State<'_, Arc>>, -) -> Result { +) -> Result { log::info!(">>> Query delegated vesting"); let res = nymd_client!(state) .delegated_vesting(