Skip to content

Commit

Permalink
Merge branch 'brent/pos-rewards' (#1992)
Browse files Browse the repository at this point in the history
* origin/brent/pos-rewards:
  add test for commissions and fix `bond_amounts_for_rewards`
  fix tests
  update `bond_amounts_for_rewards` and `bond_amount`
  misc lib code improvements
  fix rewards tallying: move from within withdraw -> unbond
  add and update tests
  changelog: add #1992
  updates to enable tx from CLI
  update to 0.25.0 base
  change default `kD` and `kP` params
  playground for testing how inflation changes
  WIP more tests
  benches: add a const for "tx_claim_rewards.wasm"
  test/PoS: add rewards related tests
  add a tx to claim PoS rewards
  PoS: apply inflation after processing slashes
  PoS: refactors to use helper functions
  PoS: allow to claim rewards
  PoS: update rewards products to handle commission correctly
  • Loading branch information
adrianbrink committed Nov 11, 2023
2 parents 7a1b743 + 72d16d8 commit 5c590e0
Show file tree
Hide file tree
Showing 25 changed files with 2,211 additions and 504 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1992-pos-rewards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Implements a claim-based rewards system for PoS inflation.
([\#1992](https://github.com/anoma/namada/pull/1992))
1 change: 1 addition & 0 deletions .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"e2e::ledger_tests::wrapper_disposable_signer": 28,
"e2e::ledger_tests::deactivate_and_reactivate_validator": 67,
"e2e::ledger_tests::change_validator_metadata": 31,
"e2e::ledger_tests::pos_rewards": 44,
"e2e::wallet_tests::wallet_address_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds_env_var": 1,
Expand Down
1 change: 1 addition & 0 deletions apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub const TX_UNJAIL_VALIDATOR_WASM: &str = "tx_unjail_validator.wasm";
pub const TX_DEACTIVATE_VALIDATOR_WASM: &str = "tx_deactivate_validator.wasm";
pub const TX_REACTIVATE_VALIDATOR_WASM: &str = "tx_reactivate_validator.wasm";
pub const TX_WITHDRAW_WASM: &str = "tx_withdraw.wasm";
pub const TX_CLAIM_REWARDS_WASM: &str = "tx_claim_rewards.wasm";
pub const TX_INIT_ACCOUNT_WASM: &str = "tx_init_account.wasm";
pub const TX_INIT_VALIDATOR_WASM: &str = "tx_init_validator.wasm";

Expand Down
64 changes: 64 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub mod cmds {
.subcommand(Unbond::def().display_order(2))
.subcommand(Withdraw::def().display_order(2))
.subcommand(Redelegate::def().display_order(2))
.subcommand(ClaimRewards::def().display_order(2))
.subcommand(TxCommissionRateChange::def().display_order(2))
.subcommand(TxMetadataChange::def().display_order(2))
// Ethereum bridge transactions
Expand Down Expand Up @@ -299,6 +300,7 @@ pub mod cmds {
let unbond = Self::parse_with_ctx(matches, Unbond);
let withdraw = Self::parse_with_ctx(matches, Withdraw);
let redelegate = Self::parse_with_ctx(matches, Redelegate);
let claim_rewards = Self::parse_with_ctx(matches, ClaimRewards);
let query_epoch = Self::parse_with_ctx(matches, QueryEpoch);
let query_account = Self::parse_with_ctx(matches, QueryAccount);
let query_transfers = Self::parse_with_ctx(matches, QueryTransfers);
Expand Down Expand Up @@ -351,6 +353,7 @@ pub mod cmds {
.or(unbond)
.or(withdraw)
.or(redelegate)
.or(claim_rewards)
.or(add_to_eth_bridge_pool)
.or(tx_update_steward_commission)
.or(tx_resign_steward)
Expand Down Expand Up @@ -431,6 +434,7 @@ pub mod cmds {
Bond(Bond),
Unbond(Unbond),
Withdraw(Withdraw),
ClaimRewards(ClaimRewards),
Redelegate(Redelegate),
AddToEthBridgePool(AddToEthBridgePool),
TxUpdateStewardCommission(TxUpdateStewardCommission),
Expand Down Expand Up @@ -1533,6 +1537,28 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct ClaimRewards(pub args::ClaimRewards<args::CliTypes>);

impl SubCmd for ClaimRewards {
const CMD: &'static str = "claim-rewards";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| ClaimRewards(args::ClaimRewards::parse(matches)))
}

fn def() -> App {
App::new(Self::CMD)
.about(
"Claim available rewards tokens from bonds that \
contributed in consensus.",
)
.add_args::<args::ClaimRewards<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct Redelegate(pub args::Redelegate<args::CliTypes>);

Expand Down Expand Up @@ -2808,6 +2834,7 @@ pub mod args {
"tx_update_steward_commission.wasm";
pub const TX_VOTE_PROPOSAL: &str = "tx_vote_proposal.wasm";
pub const TX_WITHDRAW_WASM: &str = "tx_withdraw.wasm";
pub const TX_CLAIM_REWARDS_WASM: &str = "tx_claim_rewards.wasm";
pub const TX_RESIGN_STEWARD: &str = "tx_resign_steward.wasm";

pub const VP_USER_WASM: &str = "vp_user.wasm";
Expand Down Expand Up @@ -4794,6 +4821,43 @@ pub mod args {
}
}

impl CliToSdk<ClaimRewards<SdkTypes>> for ClaimRewards<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> ClaimRewards<SdkTypes> {
let tx = self.tx.to_sdk(ctx);
let chain_ctx = ctx.borrow_chain_or_exit();
ClaimRewards::<SdkTypes> {
tx,
validator: chain_ctx.get(&self.validator),
source: self.source.map(|x| chain_ctx.get(&x)),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}

impl Args for ClaimRewards<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let tx = Tx::parse(matches);
let validator = VALIDATOR.parse(matches);
let source = SOURCE_OPT.parse(matches);
let tx_code_path = PathBuf::from(TX_CLAIM_REWARDS_WASM);
Self {
tx,
validator,
source,
tx_code_path,
}
}

fn def(app: App) -> App {
app.add_args::<Tx<CliTypes>>()
.arg(VALIDATOR.def().help("Validator address."))
.arg(SOURCE_OPT.def().help(
"Source address for claiming rewards for a bond. For \
self-bonds, the validator is also the source.",
))
}
}

impl CliToSdk<QueryConversions<SdkTypes>> for QueryConversions<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> QueryConversions<SdkTypes> {
QueryConversions::<SdkTypes> {
Expand Down
11 changes: 11 additions & 0 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ impl CliApi {
let namada = ctx.to_sdk(&client, io);
tx::submit_withdraw(&namada, args).await?;
}
Sub::ClaimRewards(ClaimRewards(mut args)) => {
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(
&mut args.tx.ledger_address,
)
});
client.wait_until_node_is_synced(io).await?;
let args = args.to_sdk(&mut ctx);
let namada = ctx.to_sdk(&client, io);
tx::submit_claim_rewards(&namada, args).await?;
}
Sub::Redelegate(Redelegate(mut args)) => {
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(
Expand Down
22 changes: 22 additions & 0 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,28 @@ where
Ok(())
}

pub async fn submit_claim_rewards<'a, N: Namada<'a>>(
namada: &N,
args: args::ClaimRewards,
) -> Result<(), error::Error>
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
tx::dump_tx(namada.io(), &args.tx, tx);
} else {
namada.sign(&mut tx, &args.tx, signing_data).await?;

namada.submit(tx, &args.tx).await?;
}

Ok(())
}

pub async fn submit_redelegate<'a, N: Namada<'a>>(
namada: &N,
args: args::Redelegate,
Expand Down
Loading

0 comments on commit 5c590e0

Please sign in to comment.