diff --git a/contracts/tg4-stake/src/claim.rs b/contracts/tg4-stake/src/claim.rs index 2c60b47..0b28204 100644 --- a/contracts/tg4-stake/src/claim.rs +++ b/contracts/tg4-stake/src/claim.rs @@ -5,10 +5,14 @@ use itertools::Itertools; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +use crate::msg::Undelegation; +use crate::state::CONFIG; use cosmwasm_std::{ - Addr, BlockInfo, CustomQuery, Decimal, Deps, Order, StdResult, Storage, Uint128, + coin, Addr, BlockInfo, CustomQuery, Decimal, Deps, Order, StdResult, Storage, Uint128, }; use cw_storage_plus::{Bound, Index, IndexList, IndexedMap, MultiIndex, PrefixBound}; +use tg_bindings::TgradeMsg; +use tg_bindings::TgradeMsg::Undelegate; use tg_utils::Expiration; // settings for pagination @@ -315,3 +319,22 @@ impl<'a> Claims<'a> { .collect() } } + +// Helper to repair the auto-release claims bug (#198) +pub fn process_pending_undelegations( + deps: Deps, + undelegations: &[Undelegation], +) -> StdResult> { + let cfg = CONFIG.load(deps.storage)?; + let msgs = undelegations + .iter() + .map(|undelegation| { + let amount = coin(undelegation.amount.into(), cfg.denom.clone()); + Undelegate { + funds: amount, + recipient: undelegation.addr.clone(), + } + }) + .collect(); + Ok(msgs) +} diff --git a/contracts/tg4-stake/src/contract.rs b/contracts/tg4-stake/src/contract.rs index 70c0553..2812a40 100644 --- a/contracts/tg4-stake/src/contract.rs +++ b/contracts/tg4-stake/src/contract.rs @@ -7,6 +7,7 @@ use cosmwasm_std::{ use std::cmp::min; use std::ops::Sub; +use crate::claim::process_pending_undelegations; use cw2::set_contract_version; use cw_storage_plus::Bound; use cw_utils::{ensure_from_older_version, maybe_addr}; @@ -756,7 +757,12 @@ pub fn migrate( Ok(cfg) })?; - Ok(Response::new()) + if let Some(undelegations) = msg.undelegations { + let msgs = process_pending_undelegations(deps.as_ref(), &undelegations)?; + Ok(Response::new().add_messages(msgs)) + } else { + Ok(Response::new()) + } } #[cfg(test)] diff --git a/contracts/tg4-stake/src/msg.rs b/contracts/tg4-stake/src/msg.rs index 4b9d9af..13d7095 100644 --- a/contracts/tg4-stake/src/msg.rs +++ b/contracts/tg4-stake/src/msg.rs @@ -135,6 +135,12 @@ pub struct ClaimsResponse { pub claims: Vec, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct Undelegation { + pub addr: String, + pub amount: Uint128, +} + #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] #[serde(rename_all = "snake_case")] pub struct MigrateMsg { @@ -142,6 +148,7 @@ pub struct MigrateMsg { pub min_bond: Option, pub unbonding_period: Option, pub auto_return_limit: Option, + pub undelegations: Option>, } #[cfg(test)]