Skip to content

Commit

Permalink
move shielded params from core into shielded_token
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jan 31, 2024
1 parent f3ee4cb commit f9d2361
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 49 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ use namada::governance::pgf::parameters::PgfParameters;
use namada::ledger::eth_bridge::EthereumBridgeParams;
use namada::ledger::parameters::EpochDuration;
use namada::ledger::pos::{Dec, GenesisValidator, OwnedPosParams};
use namada::token;
use namada::types::address::{Address, EstablishedAddress};
use namada::types::chain::ProposalBytes;
use namada::types::key::*;
use namada::types::storage;
use namada::types::string_encoding::StringEncoded;
use namada::types::time::{DateTimeUtc, DurationSecs};
use namada::types::token::Denomination;
use namada::types::{storage, token};
use serde::{Deserialize, Serialize};

#[cfg(all(any(test, feature = "benches"), not(feature = "integration")))]
Expand Down Expand Up @@ -228,7 +229,7 @@ pub struct TokenAccount {
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
pub balances: HashMap<Address, token::Amount>,
/// Token parameters
pub masp_params: Option<token::MaspParams>,
pub masp_params: Option<token::ShieldedParams>,
/// Token inflation from the last epoch (read + write for every epoch)
pub last_inflation: token::Amount,
/// Token shielded ratio from the last epoch (read + write for every epoch)
Expand Down
5 changes: 3 additions & 2 deletions crates/apps/src/lib/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use borsh::{BorshDeserialize, BorshSerialize};
use namada::eth_bridge::storage::parameters::{
Contracts, Erc20WhitelistEntry, MinimumConfirmations,
};
use namada::token;
use namada::types::address::Address;
use namada::types::chain::ProposalBytes;
use namada::types::dec::Dec;
use namada::types::ethereum_structs;
use namada::types::token::{
Amount, DenominatedAmount, Denomination, NATIVE_MAX_DECIMAL_PLACES,
};
use namada::types::{ethereum_structs, token};
use serde::{Deserialize, Serialize};

use super::transactions::{self, Transactions};
Expand Down Expand Up @@ -209,7 +210,7 @@ pub struct Tokens {
)]
pub struct TokenConfig {
pub denom: Denomination,
pub masp_params: Option<token::MaspParams>,
pub masp_params: Option<token::ShieldedParams>,
}

#[derive(
Expand Down
38 changes: 0 additions & 38 deletions crates/core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,44 +964,6 @@ impl From<DenominatedAmount> for IbcAmount {
}
}

/// Token parameters for each kind of asset held on chain
#[derive(
Clone,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
BorshSerialize,
BorshDeserialize,
BorshSchema,
Deserialize,
Serialize,
)]
pub struct MaspParams {
/// Maximum reward rate
pub max_reward_rate: Dec,
/// Shielded Pool nominal derivative gain
pub kd_gain_nom: Dec,
/// Shielded Pool nominal proportional gain for the given token
pub kp_gain_nom: Dec,
/// Target amount for the given token that is locked in the shielded pool
/// TODO: should this be a Uint or DenominatedAmount???
pub locked_amount_target: u64,
}

impl Default for MaspParams {
fn default() -> Self {
Self {
max_reward_rate: Dec::from_str("0.1").unwrap(),
kp_gain_nom: Dec::from_str("0.25").unwrap(),
kd_gain_nom: Dec::from_str("0.25").unwrap(),
locked_amount_target: 10_000_u64,
}
}
}

/// A simple bilateral token transfer
#[derive(
Debug,
Expand Down
2 changes: 2 additions & 0 deletions crates/shielded_token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ namada_parameters = { path = "../parameters" }
namada_storage = { path = "../storage" }
namada_trans_token = { path = "../trans_token" }

borsh.workspace = true
masp_primitives.workspace = true
rayon = { workspace = true, optional = true }
serde.workspace = true
tracing.workspace = true

[dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions crates/shielded_token/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,13 @@ mod tests {
use namada_core::types::token::testing::arb_amount;
use namada_parameters::{EpochDuration, Parameters};
use namada_storage::testing::TestStorage;
use namada_trans_token::{write_denom, Denomination, MaspParams};
use namada_trans_token::{write_denom, Denomination};
use proptest::prelude::*;
use proptest::test_runner::Config;
use test_log::test;

use super::*;
use crate::ShieldedParams;

proptest! {
#![proptest_config(Config {
Expand Down Expand Up @@ -592,7 +593,7 @@ mod tests {
namada_parameters::init_storage(&params, &mut s).unwrap();

// Tokens
let token_params = MaspParams {
let token_params = ShieldedParams {
max_reward_rate: Dec::from_str("0.1").unwrap(),
kp_gain_nom: Dec::from_str("0.1").unwrap(),
kd_gain_nom: Dec::from_str("0.1").unwrap(),
Expand Down
43 changes: 43 additions & 0 deletions crates/shielded_token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,50 @@ mod storage;
pub mod storage_key;
pub mod utils;

use std::str::FromStr;

use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use namada_core::types::dec::Dec;
pub use namada_storage::conversion_state::{
ConversionState, WithConversionState,
};
use serde::{Deserialize, Serialize};
pub use storage::*;

/// Token parameters for each kind of asset held on chain
#[derive(
Clone,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
BorshSerialize,
BorshDeserialize,
BorshSchema,
Deserialize,
Serialize,
)]
pub struct ShieldedParams {
/// Maximum reward rate
pub max_reward_rate: Dec,
/// Shielded Pool nominal derivative gain
pub kd_gain_nom: Dec,
/// Shielded Pool nominal proportional gain for the given token
pub kp_gain_nom: Dec,
/// Target amount for the given token that is locked in the shielded pool
/// TODO: should this be a Uint or DenominatedAmount???
pub locked_amount_target: u64,
}

impl Default for ShieldedParams {
fn default() -> Self {
Self {
max_reward_rate: Dec::from_str("0.1").unwrap(),
kp_gain_nom: Dec::from_str("0.25").unwrap(),
kd_gain_nom: Dec::from_str("0.25").unwrap(),
locked_amount_target: 10_000_u64,
}
}
}
5 changes: 3 additions & 2 deletions crates/shielded_token/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ use namada_storage::{StorageRead, StorageWrite};
use storage::ResultExt;

use crate::storage_key::*;
use crate::ShieldedParams;

/// Initialize parameters for the token in storage during the genesis block.
pub fn write_params<S>(
params: &token::MaspParams,
params: &ShieldedParams,
storage: &mut S,
address: &Address,
denom: &token::Denomination,
) -> storage::Result<()>
where
S: StorageRead + StorageWrite,
{
let token::MaspParams {
let ShieldedParams {
max_reward_rate: max_rate,
kd_gain_nom,
kp_gain_nom,
Expand Down
4 changes: 2 additions & 2 deletions crates/tests/src/integration/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::str::FromStr;
use std::sync::{Arc, Mutex};

use color_eyre::eyre::{eyre, Result};
use namada::token;
use namada::types::dec::Dec;
use namada::types::token;
use namada_apps::cli::args;
use namada_apps::client::utils::PRE_GENESIS_DIR;
use namada_apps::config;
Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn initialize_genesis() -> Result<(MockNode, MockServicesController)> {
let mut templates = templates::All::read_toml_files(&template_dir)
.expect("Missing genesis files");
for (_, config) in templates.tokens.token.iter_mut() {
config.masp_params = Some(token::MaspParams {
config.masp_params = Some(token::ShieldedParams {
max_reward_rate: Dec::from_str("0.1").unwrap(),
kp_gain_nom: Dec::from_str("0.1").unwrap(),
kd_gain_nom: Dec::from_str("0.1").unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion crates/token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use namada_storage::{Result, StorageRead, StorageWrite};

/// Initialize parameters for the token in storage during the genesis block.
pub fn write_params<S>(
params: &Option<MaspParams>,
params: &Option<ShieldedParams>,
storage: &mut S,
address: &Address,
denom: &Denomination,
Expand Down
2 changes: 2 additions & 0 deletions wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions wasm_for_tests/wasm_source/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9d2361

Please sign in to comment.