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

[pos] Add epoch argument to vp::pos::rewards #4196

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/4196-rewards-at-past-epoch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Allow querying PoS rewards at a specified epoch
([\#4196](https://github.com/anoma/namada/pull/4196))
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'namada_sdk'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=namada_sdk"
],
"filter": {
"name": "namada_sdk",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
Expand Down
13 changes: 12 additions & 1 deletion crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,7 @@ pub mod cmds {
fn def() -> App {
App::new(Self::CMD)
.about(wrap!(
"Query the latest rewards available to claim for a given \
"Query the rewards available to claim for a given \
delegation (or self-bond)."
))
.add_args::<args::QueryRewards<args::CliTypes>>()
Expand Down Expand Up @@ -7309,6 +7309,7 @@ pub mod args {
query: self.query.to_sdk(ctx)?,
validator: ctx.borrow_chain_or_exit().get(&self.validator),
source: self.source.map(|x| ctx.borrow_chain_or_exit().get(&x)),
epoch: self.epoch,
})
}
}
Expand All @@ -7318,10 +7319,12 @@ pub mod args {
let query = Query::parse(matches);
let source = SOURCE_OPT.parse(matches);
let validator = VALIDATOR.parse(matches);
let epoch = EPOCH.parse(matches);
Self {
query,
source,
validator,
epoch,
}
}

Expand All @@ -7336,6 +7339,14 @@ pub mod args {
"Validator address for the rewards query."
)),
)
.arg(EPOCH.def().help(wrap!(
"The epoch at which to query (corresponding to the last \
committed block, if not specified). \
\
Note: when querying by epoch, this returns the accumulated \
rewards that were available to claim at the start of the \
epoch."
tzemanovic marked this conversation as resolved.
Show resolved Hide resolved
)))
}
}

Expand Down
17 changes: 13 additions & 4 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,11 @@ pub async fn query_rewards<C: Client + Sync>(
client: &C,
source: &Option<Address>,
validator: &Address,
epoch: &Option<Epoch>,
) -> token::Amount {
unwrap_sdk_result(rpc::query_rewards(client, source, validator).await)
unwrap_sdk_result(
rpc::query_rewards(client, source, validator, epoch).await,
)
}

/// Query token total supply.
Expand Down Expand Up @@ -1920,12 +1923,18 @@ pub async fn query_and_print_rewards<N: Namada>(
context: &N,
args: args::QueryRewards,
) {
let (source, validator) = (args.source, args.validator);
let (source, validator, epoch) = (args.source, args.validator, args.epoch);

let rewards = query_rewards(context.client(), &source, &validator).await;
let rewards =
query_rewards(context.client(), &source, &validator, &epoch).await;
display_line!(
context.io(),
"Current rewards available for claim: {} NAM",
"{}: {} NAM",
epoch
.map(|e| format!("Rewards at epoch {}", e))
.unwrap_or_else(
|| "Current rewards available for claim".to_string()
),
rewards.to_string_native()
);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,8 @@ pub struct QueryRewards<C: NamadaTypes = SdkTypes> {
pub source: Option<C::Address>,
/// Address of the validator
pub validator: C::Address,
/// Epoch in which to find rewards
pub epoch: Option<Epoch>,
}

/// Query PoS delegations
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/src/queries/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ where
/// borsh-encoded types, it is safe to check `data.is_empty()` to see if the
/// value was found, except for unit - see `fn query_storage_value` in
/// `apps/src/lib/client/rpc.rs` for unit type handling via `storage_has_key`.
fn storage_value<D, H, V, T>(
pub fn storage_value<D, H, V, T>(
ctx: RequestCtx<'_, D, H, V, T>,
request: &RequestQuery,
storage_key: storage::Key,
Expand Down
Loading
Loading