|
1 | 1 | use std::cmp::Ordering;
|
2 | 2 | use std::collections::{BTreeMap, HashMap, HashSet};
|
| 3 | +use std::u32; |
3 | 4 |
|
4 | 5 | use cosmwasm_std::{
|
5 | 6 | coin, ensure_eq, to_json_binary, Coin, CosmosMsg, CustomQuery, DepsMut, DistributionMsg, Env,
|
@@ -74,7 +75,7 @@ impl VirtualStakingContract<'_> {
|
74 | 75 | pub fn instantiate(
|
75 | 76 | &self,
|
76 | 77 | ctx: InstantiateCtx<VirtualStakeCustomQuery>,
|
77 |
| - max_retrieve: u16, |
| 78 | + max_retrieve: u32, |
78 | 79 | tombstoned_unbond_enable: bool,
|
79 | 80 | ) -> Result<Response<VirtualStakeCustomMsg>, ContractError> {
|
80 | 81 | nonpayable(&ctx.info)?;
|
@@ -622,6 +623,52 @@ impl VirtualStakingApi for VirtualStakingContract<'_> {
|
622 | 623 | Ok(Response::new().add_messages(msgs))
|
623 | 624 | }
|
624 | 625 |
|
| 626 | + fn handle_close_channel( |
| 627 | + &self, |
| 628 | + ctx: ExecCtx<Self::QueryC>, |
| 629 | + ) -> Result<Response<VirtualStakeCustomMsg>, Self::Error> { |
| 630 | + nonpayable(&ctx.info)?; |
| 631 | + let ExecCtx { deps, env, info } = ctx; |
| 632 | + let config = self.config.load(deps.storage)?; |
| 633 | + ensure_eq!(info.sender, config.converter, ContractError::Unauthorized); // only the converter can call this |
| 634 | + |
| 635 | + let all_delegations = TokenQuerier::new(&deps.querier) |
| 636 | + .all_delegations(env.contract.address.to_string(), u32::MAX)?; |
| 637 | + |
| 638 | + let mut msgs = vec![VirtualStakeMsg::DeleteAllScheduledTasks {}]; |
| 639 | + for delegation in all_delegations.delegations.iter() { |
| 640 | + let amount = Coin { |
| 641 | + denom: config.denom.clone(), |
| 642 | + amount: delegation.amount, |
| 643 | + }; |
| 644 | + msgs.push(VirtualStakeMsg::UpdateDelegation { |
| 645 | + amount: amount.clone(), |
| 646 | + is_deduct: true, |
| 647 | + delegator: delegation.delegator.clone(), |
| 648 | + validator: delegation.validator.clone(), |
| 649 | + }); |
| 650 | + msgs.push(VirtualStakeMsg::Unbond { |
| 651 | + amount, |
| 652 | + validator: delegation.validator.clone(), |
| 653 | + }); |
| 654 | + self.bond_requests |
| 655 | + .save(deps.storage, &delegation.validator, &Uint128::zero())?; |
| 656 | + } |
| 657 | + |
| 658 | + let requests: Vec<(String, Uint128)> = self |
| 659 | + .bond_requests |
| 660 | + .range( |
| 661 | + deps.as_ref().storage, |
| 662 | + None, |
| 663 | + None, |
| 664 | + cosmwasm_std::Order::Ascending, |
| 665 | + ) |
| 666 | + .collect::<Result<_, _>>()?; |
| 667 | + self.bonded.save(deps.storage, &requests)?; |
| 668 | + |
| 669 | + Ok(Response::new().add_messages(msgs)) |
| 670 | + } |
| 671 | + |
625 | 672 | // FIXME: need to handle custom message types and queries
|
626 | 673 | /**
|
627 | 674 | * This is called once per epoch to withdraw all rewards and rebalance the bonded tokens.
|
|
0 commit comments