Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor + Add gov param updates to Phase 5 transition #10

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
827 changes: 527 additions & 300 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
resolver = "2"

members = [
"block_party",
"staking_party",
"shielding_party",
"shielding_reward_party",
"shielding_rewards_party",
"nam_party",
]

default-members = [
"block_party",
"staking_party",
"shielding_party",
"shielding_reward_party",
"shielding_rewards_party",
"nam_party",
]

[workspace.package]
Expand All @@ -22,9 +22,9 @@ license = "GPL-3.0"
version = "0.1.0"

[workspace.dependencies]
namada_tx_prelude = { git = "https://github.com/anoma/namada", tag = "v0.43.0" }
namada_proof_of_stake = { git = "https://github.com/anoma/namada", tag = "v0.43.0" }
namada_ibc = { git = "https://github.com/anoma/namada", tag = "v0.43.0" }
namada_tx_prelude = { git = "https://github.com/anoma/namada", tag = "v0.44.1" }
namada_proof_of_stake = { git = "https://github.com/anoma/namada", tag = "v0.44.1" }
namada_ibc = { git = "https://github.com/anoma/namada", tag = "v0.44.1" }
rlsf = "0.2.1"
getrandom = { version = "0.2", features = ["custom"] }
lazy_static = "1.4.0"
Expand All @@ -33,4 +33,4 @@ lazy_static = "1.4.0"
lto = true
panic = "abort"
opt-level = 'z'
strip = "debuginfo"
strip = "debuginfo"
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source:
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --chmod 755 docker/run-wasmopt.sh ./run-wasmopt.sh
COPY --keep-ts --chmod 755 docker/download-wasmopt.sh ./download-wasmopt.sh
COPY --keep-ts --dir block_party shielding_party staking_party shielding_reward_party ./
COPY --keep-ts --dir shielding_party staking_party shielding_rewards_party nam_party ./

# lint runs cargo clippy on the source code
lint:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ Namada mainnet launch is divided into [5 phases](https://namada.net/mainnet-laun

Staking rewards are enabled for delegators and validators staking NAM. Public Goods Funding is enabled to support public goods in the Namada ecosystem and beyond.

The reference code can be found in [block_party folder](./block_party/).
The reference code can be found in [staking_party folder](./staking_party/).

## Staking party -> Shielding party (Phase 2 -> 3)

Transparent and shielded transfers of governance-enabled IBC assets are enabled. Users can begin shielding assets in the unified shielded set. NAM transfers remain locked until phase 5 (NAM party).

The reference code can be found in [staking_party folder](./staking_party/).
The reference code can be found in [shielding_party folder](./shielding_party/).

## Shielding party -> Shielding Reward party (Phase 3 -> 4)

Shielding rewards for governance-enabled IBC assets are enabled. Users begin collecting rewards for shielding assets, which protects their data and helps strengthen Namada’s unified shielded set.

The reference code can be found in [shielding_party folder](./shielding_party/).
The reference code can be found in [shielding_rewards_party folder](./shielding_rewards_party/).

## Shielding Reward party -> NAM Party (Phase 4 -> 5)

When the Namada community is confident that the network is stable, NAM transfers are enabled. All key protocol functionality is now live. From here on, new features and support for new assets can continue to be added by the community via on-chain governance.

The reference code can be found in [shielding_reward_party folder](./shielding_reward_party/).
The reference code can be found in [nam_party folder](./nam_party/).

# How to build
To generate the wasm artifacts that can be attached to the governance proposal, run:
Expand Down
29 changes: 0 additions & 29 deletions block_party/src/lib.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"voting_start_epoch": 9,
"voting_end_epoch": 18,
"activation_epoch": 25,
"wasm_path": "artifacts/shielded_reward_party.wasm"
"wasm_path": "artifacts/nam_party.wasm"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"details": "Phasellus quis sem finibus, luctus neque in, vestibulum lectus.",
"requires": "-1",
"author": "tnam1qxfj3sf6a0meahdu9t6znp05g8zx4dkjtgyn9gfu",
"voting_start_epoch": 6,
"voting_end_epoch": 12,
"activation_epoch": 18,
"wasm_path": "artifacts/block_party.wasm"
"voting_start_epoch": 9,
"voting_end_epoch": 18,
"activation_epoch": 25,
"wasm_path": "artifacts/shielding_rewards_party.wasm"
}
6 changes: 3 additions & 3 deletions builder/parameters/staking-party.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"details": "Phasellus quis sem finibus, luctus neque in, vestibulum lectus.",
"requires": "-1",
"author": "tnam1qxfj3sf6a0meahdu9t6znp05g8zx4dkjtgyn9gfu",
"voting_start_epoch": 9,
"voting_end_epoch": 18,
"activation_epoch": 25,
"voting_start_epoch": 6,
"voting_end_epoch": 12,
"activation_epoch": 18,
"wasm_path": "artifacts/staking_party.wasm"
}
2 changes: 1 addition & 1 deletion shielding_reward_party/Cargo.toml → nam_party/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "shielded_reward_party"
name = "nam_party"
description = "WASM transaction to transition from phase 4 to phase 5 of Namada mainnet."
authors.workspace = true
edition.workspace = true
Expand Down
14 changes: 12 additions & 2 deletions shielding_reward_party/src/lib.rs → nam_party/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ pub const NAM_TARGET_LOCKED_AMOUNT: u64 = 1_000_000_000;
pub const KP_GAIN: &str = "120000";
pub const KD_GAIN: &str = "120000";

pub const MIN_PROPOSAL_GRACE_EPOCHS: u64 = 8;
pub const MIN_PROPOSAL_VOTING_PERIOD: u64 = 28;

#[transaction]
fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
let nam_address = ctx.get_native_token()?;

// Enable NAM transfers
// 1. Enable NAM transfers
let native_token_transferable_key = parameters_storage::get_native_token_transferable_key();
ctx.write(&native_token_transferable_key, true)?;

// Enable NAM MASP rewards
// 2. Enable MASP rewards for NAM
let shielded_token_last_inflation_key =
token::storage_key::masp_last_inflation_key(&nam_address);
let shielded_token_last_locked_amount_key =
Expand Down Expand Up @@ -50,5 +53,12 @@ fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
ctx.write(&shielded_token_kp_gain_key, Dec::from_str(KP_GAIN).unwrap())?;
ctx.write(&shielded_token_kd_gain_key, Dec::from_str(KD_GAIN).unwrap())?;

// 3. Update governance parameters
let min_proposal_grace_epochs_key = gov_storage::keys::get_min_proposal_grace_epochs_key();
ctx.write(&min_proposal_grace_epochs_key, MIN_PROPOSAL_GRACE_EPOCHS)?;

let min_proposal_voting_period_key = gov_storage::keys::get_min_proposal_voting_period_key();
ctx.write(&min_proposal_voting_period_key, MIN_PROPOSAL_VOTING_PERIOD)?;

Ok(())
}
2 changes: 1 addition & 1 deletion shielding_party/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shielding_party"
description = "WASM transaction to transition from phase 3 to phase 4 of Namada mainnet."
description = "WASM transaction to transition from phase 2 to phase 3 of Namada mainnet."
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
123 changes: 14 additions & 109 deletions shielding_party/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,126 +1,31 @@
use dec::Dec;
use namada_tx_prelude::*;
use std::str::FromStr;

pub type Denomination = u8;
pub type ChannelId = &'static str;
pub type BaseToken = &'static str;

pub type TokenMaxReward = &'static str;
pub type TokenTargetLockedAmount = u64;
pub type KpGain = &'static str;
pub type KdGain = &'static str;
pub type MintTokenLimit = token::Amount;
pub type ThroughtputTokenLimit = token::Amount;

const IBC_TOKENS: [(
Denomination,
ChannelId,
BaseToken,
TokenMaxReward,
TokenTargetLockedAmount,
KpGain,
KdGain,
); 2] = [
(
0,
"channel-0",
"tnam1qrdm8ymq2svrrafzuqahm547xm4kfuw3aue93uzs",
"0.01",
1_000_000_000,
"120000",
"120000",
),
(
0,
"channel-1",
"tnam1qqx4luqsngxdmpf5nk8shkn7wwlmz6g7dckp8kgm",
"0.015",
1_500_000_000,
"150000",
"110000",
),
];
const IBC_TOKENS: [(ChannelId, BaseToken, MintTokenLimit, ThroughtputTokenLimit); 1] = [(
"channel-0",
"uosmo",
MintTokenLimit::from_u64(10000000000),
ThroughtputTokenLimit::from_u64(10000000000),
)];

#[transaction]
fn apply_tx(ctx: &mut Ctx, _tx_data: BatchedTx) -> TxResult {
// Read the current MASP token map
let token_map_key = token::storage_key::masp_token_map_key();
let mut token_map = ctx
.read::<masp::TokenMap>(&token_map_key)?
.unwrap_or_default();

let nam_address = ctx.get_native_token()?;

// Add native token to token map
token_map.insert("nam".to_string(), nam_address.clone());

let shielded_native_token_last_inflation_key =
token::storage_key::masp_last_inflation_key(&nam_address);
let shielded_native_token_last_locked_amount_key =
token::storage_key::masp_last_locked_amount_key(&nam_address);
let shielded_native_token_max_rewards_key =
token::storage_key::masp_max_reward_rate_key(&nam_address);
let shielded_native_token_target_locked_amount_key =
token::storage_key::masp_locked_amount_target_key(&nam_address);
let shielded_native_token_kp_gain_key = token::storage_key::masp_kp_gain_key(&nam_address);
let shielded_native_token_kd_gain_key = token::storage_key::masp_kd_gain_key(&nam_address);

// Setup native token shielded set rewards to 0
ctx.write(
&shielded_native_token_last_inflation_key,
token::Amount::zero(),
)?;
ctx.write(
&shielded_native_token_last_locked_amount_key,
token::Amount::zero(),
)?;
ctx.write(&shielded_native_token_max_rewards_key, Dec::zero())?;
ctx.write(
&shielded_native_token_target_locked_amount_key,
token::Amount::from_uint(0, 6).unwrap(),
)?;
ctx.write(&shielded_native_token_kp_gain_key, Dec::zero())?;
ctx.write(&shielded_native_token_kd_gain_key, Dec::zero())?;

// Enable shielded set rewards for ibc tokens
for (denomination, channel_id, base_token, max_reward, target_locked_amount, kp, kd) in
IBC_TOKENS
{
// Enable IBC deposit/withdraws limits
for (channel_id, base_token, mint_limit, throughput_limit) in IBC_TOKENS {
let ibc_denom = format!("transfer/{channel_id}/{base_token}");
let token_address = ibc::ibc_token(&ibc_denom);

let shielded_token_last_inflation_key =
token::storage_key::masp_last_inflation_key(&token_address);
let shielded_token_last_locked_amount_key =
token::storage_key::masp_last_locked_amount_key(&token_address);
let shielded_token_max_rewards_key =
token::storage_key::masp_max_reward_rate_key(&token_address);
let shielded_token_target_locked_amount_key =
token::storage_key::masp_locked_amount_target_key(&token_address);
let shielded_token_kp_gain_key = token::storage_key::masp_kp_gain_key(&token_address);
let shielded_token_kd_gain_key = token::storage_key::masp_kd_gain_key(&token_address);

// Add the ibc token to the masp token map
token_map.insert(ibc_denom, token_address);
let mint_limit_token_key = ibc::mint_limit_key(&token_address);
ctx.write(&mint_limit_token_key, mint_limit)?;

// Write the MASP inflation keys
ctx.write(&shielded_token_last_inflation_key, token::Amount::zero())?;
ctx.write(
&shielded_token_last_locked_amount_key,
token::Amount::zero(),
)?;
ctx.write(
&shielded_token_max_rewards_key,
Dec::from_str(max_reward).unwrap(),
)?;
ctx.write(
&shielded_token_target_locked_amount_key,
token::Amount::from_uint(target_locked_amount, denomination).unwrap(),
)?;
ctx.write(&shielded_token_kp_gain_key, Dec::from_str(kp).unwrap())?;
ctx.write(&shielded_token_kd_gain_key, Dec::from_str(kd).unwrap())?;
let throughput_limit_token_key = ibc::throughput_limit_key(&token_address);
ctx.write(&throughput_limit_token_key, throughput_limit)?;
}

ctx.write(&token_map_key, token_map)?;

Ok(())
}
5 changes: 2 additions & 3 deletions block_party/Cargo.toml → shielding_rewards_party/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "block_party"
description = "WASM transaction to transition from phase 1 to phase 2 of Namada mainnet."
name = "shielding_rewards_party"
description = "WASM transaction to transition from phase 3 to phase 4 of Namada mainnet."
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -10,7 +10,6 @@ version.workspace = true

[dependencies]
namada_tx_prelude.workspace = true
namada_proof_of_stake.workspace = true
rlsf.workspace = true
getrandom.workspace = true

Expand Down
Loading