Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit b9fba00

Browse files
authored
Merge pull request #201 from confio/fix/vesting-undelegations
Add undelegations processing to migration handler
2 parents a8c4fe7 + 7c73785 commit b9fba00

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

contracts/tg4-stake/src/claim.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ use itertools::Itertools;
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
77

8+
use crate::msg::Undelegation;
9+
use crate::state::CONFIG;
810
use cosmwasm_std::{
9-
Addr, BlockInfo, CustomQuery, Decimal, Deps, Order, StdResult, Storage, Uint128,
11+
coin, Addr, BlockInfo, CustomQuery, Decimal, Deps, Order, StdResult, Storage, Uint128,
1012
};
1113
use cw_storage_plus::{Bound, Index, IndexList, IndexedMap, MultiIndex, PrefixBound};
14+
use tg_bindings::TgradeMsg;
15+
use tg_bindings::TgradeMsg::Undelegate;
1216
use tg_utils::Expiration;
1317

1418
// settings for pagination
@@ -315,3 +319,22 @@ impl<'a> Claims<'a> {
315319
.collect()
316320
}
317321
}
322+
323+
// Helper to repair the auto-release claims bug (#198)
324+
pub fn process_pending_undelegations<Q: CustomQuery>(
325+
deps: Deps<Q>,
326+
undelegations: &[Undelegation],
327+
) -> StdResult<Vec<TgradeMsg>> {
328+
let cfg = CONFIG.load(deps.storage)?;
329+
let msgs = undelegations
330+
.iter()
331+
.map(|undelegation| {
332+
let amount = coin(undelegation.amount.into(), cfg.denom.clone());
333+
Undelegate {
334+
funds: amount,
335+
recipient: undelegation.addr.clone(),
336+
}
337+
})
338+
.collect();
339+
Ok(msgs)
340+
}

contracts/tg4-stake/src/contract.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cosmwasm_std::{
77
use std::cmp::min;
88
use std::ops::Sub;
99

10+
use crate::claim::process_pending_undelegations;
1011
use cw2::set_contract_version;
1112
use cw_storage_plus::Bound;
1213
use cw_utils::{ensure_from_older_version, maybe_addr};
@@ -756,7 +757,12 @@ pub fn migrate(
756757
Ok(cfg)
757758
})?;
758759

759-
Ok(Response::new())
760+
if let Some(undelegations) = msg.undelegations {
761+
let msgs = process_pending_undelegations(deps.as_ref(), &undelegations)?;
762+
Ok(Response::new().add_messages(msgs))
763+
} else {
764+
Ok(Response::new())
765+
}
760766
}
761767

762768
#[cfg(test)]

contracts/tg4-stake/src/msg.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,20 @@ pub struct ClaimsResponse {
135135
pub claims: Vec<Claim>,
136136
}
137137

138+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
139+
pub struct Undelegation {
140+
pub addr: String,
141+
pub amount: Uint128,
142+
}
143+
138144
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
139145
#[serde(rename_all = "snake_case")]
140146
pub struct MigrateMsg {
141147
pub tokens_per_point: Option<Uint128>,
142148
pub min_bond: Option<Uint128>,
143149
pub unbonding_period: Option<u64>,
144150
pub auto_return_limit: Option<u64>,
151+
pub undelegations: Option<Vec<Undelegation>>,
145152
}
146153

147154
#[cfg(test)]

0 commit comments

Comments
 (0)