Skip to content

Commit

Permalink
Merge pull request #4 from PFC-developer/fix/2024-08-07-previous-batches
Browse files Browse the repository at this point in the history
Fix/2024 08 07 previous batches
  • Loading branch information
PFC-developer authored Aug 7, 2024
2 parents f40186f + be754e0 commit 2adf4a2
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 22 deletions.
27 changes: 20 additions & 7 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["contracts/token", "contracts/hub", "contracts/hub-tf", "packages/*"]
members = ["contracts/token", "contracts/hub", "contracts/hub-tf",
"packages/*"]
resolver = '1'

[profile.release.package.pfc-steak]
Expand Down
2 changes: 1 addition & 1 deletion contracts/hub-tf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pfc-steak-hub-tf"
version = "3.0.18"
version = "3.0.19"
authors = ["larry <[email protected]>", "PFC <[email protected]>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand Down
1 change: 1 addition & 0 deletions contracts/hub-tf/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
start_after,
limit,
} => to_json_binary(&queries::unbond_requests_by_user(deps, user, start_after, limit)?),
QueryMsg::Unreconciled {} => to_json_binary(&queries::previous_batches_unreconciled(deps)?),
}
}

Expand Down
9 changes: 4 additions & 5 deletions contracts/hub-tf/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,10 @@ pub fn harvest(deps: DepsMut, env: Env) -> StdResult<Response> {

/// NOTE:
/// 1. When delegation Native denom here, we don't need to use a `SubMsg` to handle the received
/// coins,
/// because we have already withdrawn all claimable staking rewards previously in the same atomic
/// execution.
/// coins, because we have already withdrawn all claimable staking rewards previously in the same
/// atomic execution.
/// 2. Same as with `bond`, in the latest implementation we only delegate staking rewards with the
/// validator that has the smallest delegation amount.
/// validator that has the smallest delegation amount.
pub fn reinvest(deps: DepsMut, env: Env) -> StdResult<Response> {
let state = State::default();
let denom = state.denom.load(deps.storage)?;
Expand Down Expand Up @@ -720,7 +719,7 @@ pub fn reconcile(deps: DepsMut, env: Env) -> StdResult<Response> {
let all_batches = previous_batches()
.idx
.reconciled
.prefix("false".into())
.prefix("false".to_string())
.range(deps.storage, None, None, Order::Ascending)
.map(|item| {
let (_, v) = item?;
Expand Down
12 changes: 12 additions & 0 deletions contracts/hub-tf/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ pub fn previous_batches(
})
.collect()
}
pub fn previous_batches_unreconciled(deps: Deps) -> StdResult<Vec<Batch>> {
state::previous_batches()
.idx
.reconciled
.prefix("false".into())
.range(deps.storage, None, None, Order::Ascending)
.map(|item| {
let (_, v) = item?;
Ok(v)
})
.collect()
}

pub fn unbond_requests_by_batch(
deps: Deps,
Expand Down
2 changes: 1 addition & 1 deletion contracts/hub-tf/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn unbond_requests<'a>()

pub struct PreviousBatchesIndexes<'a> {
// pk goes to second tuple element
pub reconciled: MultiIndex<'a, String, Batch, String>,
pub reconciled: MultiIndex<'a, String, Batch, u64>,
}

impl<'a> IndexList<Batch> for PreviousBatchesIndexes<'a> {
Expand Down
1 change: 1 addition & 0 deletions contracts/hub/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
start_after,
limit,
} => to_json_binary(&queries::unbond_requests_by_user(deps, user, start_after, limit)?),
QueryMsg::Unreconciled {} => to_json_binary(&queries::previous_batches_unreconciled(deps)?),
}
}

Expand Down
7 changes: 3 additions & 4 deletions contracts/hub/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,10 @@ pub fn harvest(deps: DepsMut, env: Env) -> StdResult<Response> {

/// NOTE:
/// 1. When delegation Native denom here, we don't need to use a `SubMsg` to handle the received
/// coins,
/// because we have already withdrawn all claimable staking rewards previously in the same atomic
/// execution.
/// coins, because we have already withdrawn all claimable staking rewards previously in the same
/// atomic execution.
/// 2. Same as with `bond`, in the latest implementation we only delegate staking rewards with the
/// validator that has the smallest delegation amount.
/// validator that has the smallest delegation amount.
pub fn reinvest(deps: DepsMut, env: Env) -> StdResult<Response> {
let state = State::default();
let denom = state.denom.load(deps.storage)?;
Expand Down
15 changes: 15 additions & 0 deletions contracts/hub/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use pfc_steak::hub::{
use crate::{
helpers::{query_cw20_total_supply, query_delegations},
state::State,
types::BooleanKey,
};

const MAX_LIMIT: u32 = 30;
Expand Down Expand Up @@ -110,7 +111,21 @@ pub fn previous_batches(
})
.collect()
}
pub fn previous_batches_unreconciled(deps: Deps) -> StdResult<Vec<Batch>> {
let state = State::default();

state
.previous_batches
.idx
.reconciled
.prefix(BooleanKey::new(false))
.range(deps.storage, None, None, Order::Ascending)
.map(|item| {
let (_, v) = item?;
Ok(v)
})
.collect()
}
pub fn unbond_requests_by_batch(
deps: Deps,
id: u64,
Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ check:
cargo check --target wasm32-unknown-unknown --lib

clippy:
cargo clippy --tests
cargo +nightly clippy --tests

format:
cargo +nightly fmt
Expand All @@ -20,11 +20,11 @@ optimize-arm:
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
--platform linux/arm64 \
cosmwasm/workspace-optimizer-arm64:0.15.1
cosmwasm/optimizer-arm64:0.16.0

optimize-x86:
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
--platform linux/amd64 \
cosmwasm/workspace-optimizer:0.15.1
cosmwasm/optimizer:0.16.0
2 changes: 2 additions & 0 deletions packages/steak/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ pub enum QueryMsg {
State {},
/// The current batch on unbonding requests pending submission. Response: `PendingBatch`
PendingBatch {},
/// list of batches with reconciled == false
Unreconciled {},
/// Query an individual batch that has previously been submitted for unbonding but have not yet
/// fully withdrawn. Response: `Batch`
PreviousBatch(u64),
Expand Down

0 comments on commit 2adf4a2

Please sign in to comment.