Fixes to vesting-related migration
This commit is contained in:
@@ -56,6 +56,8 @@ fn migrate_operator(
|
||||
|
||||
fn is_proxy_vesting(proxy: Option<&Addr>, vesting_contract: &str) -> bool {
|
||||
if let Some(proxy) = proxy {
|
||||
// bypass for my local network where I just imported contract state to fresh contract
|
||||
// return true;
|
||||
if proxy.as_ref() == vesting_contract {
|
||||
return true;
|
||||
}
|
||||
@@ -132,30 +134,18 @@ fn migrate_delegator(
|
||||
.expect("failed to serialize mixnode migration msg");
|
||||
response.messages.push(SubMsg::new(wasm_msg));
|
||||
} else {
|
||||
let mut to_address = delegation.owner.to_string();
|
||||
let mut make_bank_msg = true;
|
||||
// if the specified proxy matches the vesting contract address -> treat it as "proper" undelegation
|
||||
// and send tokens back there
|
||||
if let Some(proxy) = delegation.proxy {
|
||||
to_address = proxy.to_string();
|
||||
if proxy == vesting_contract {
|
||||
make_bank_msg = false;
|
||||
let vesting_track = VestingContractExecuteMsg::TrackUndelegation {
|
||||
owner: delegation.owner.to_string(),
|
||||
mix_identity: delegation.node_identity,
|
||||
amount: delegation.amount.clone(),
|
||||
};
|
||||
let wasm_msg = wasm_execute(
|
||||
vesting_contract,
|
||||
&vesting_track,
|
||||
vec![delegation.amount.clone()],
|
||||
)?;
|
||||
response.messages.push(SubMsg::new(wasm_msg));
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise just send tokens back to the user / different proxy
|
||||
if make_bank_msg {
|
||||
if is_proxy_vesting(delegation.proxy.as_ref(), vesting_contract) {
|
||||
let vesting_track = VestingContractExecuteMsg::TrackUndelegation {
|
||||
owner: delegation.owner.to_string(),
|
||||
mix_identity: delegation.node_identity.clone(),
|
||||
amount: delegation.amount.clone(),
|
||||
};
|
||||
let wasm_msg = wasm_execute(vesting_contract, &vesting_track, vec![delegation.amount])?;
|
||||
response.messages.push(SubMsg::new(wasm_msg));
|
||||
} else {
|
||||
let to_address = delegation.proxy.unwrap_or(delegation.owner).into_string();
|
||||
let return_tokens = BankMsg::Send {
|
||||
to_address,
|
||||
amount: vec![delegation.amount],
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::traits::{
|
||||
};
|
||||
use crate::vesting::{populate_vesting_periods, Account};
|
||||
use cosmwasm_std::{
|
||||
coin, entry_point, to_binary, BankMsg, Coin, Deps, DepsMut, Env, MessageInfo, Order,
|
||||
coin, entry_point, to_binary, BankMsg, Coin, Deps, DepsMut, Env, Event, MessageInfo, Order,
|
||||
QueryResponse, Response, StdResult, Timestamp, Uint128,
|
||||
};
|
||||
use cw_storage_plus::Bound;
|
||||
@@ -63,7 +63,7 @@ fn update_delegation_to_v2(
|
||||
|
||||
// this MUST succeed since we know this delegation was created via vesting contract...
|
||||
let account = account_from_address(&owner, deps.storage, deps.api)?;
|
||||
let storage_prefix = (account.storage_key(), node_identity);
|
||||
let storage_prefix = (account.storage_key(), node_identity.clone());
|
||||
let old_data = OLD_DELEGATIONS
|
||||
.prefix(storage_prefix.clone())
|
||||
.range(deps.storage, None, None, Order::Ascending)
|
||||
|
||||
@@ -52,10 +52,8 @@ pub fn remove_delegation(
|
||||
key: (u32, IdentityKey, BlockTimestampSecs),
|
||||
storage: &mut dyn Storage,
|
||||
) -> Result<(), ContractError> {
|
||||
Err(ContractError::MaintenanceMode)
|
||||
//
|
||||
// DELEGATIONS.remove(storage, key);
|
||||
// Ok(())
|
||||
OLD_DELEGATIONS.remove(storage, key);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_account(address: &Addr, storage: &mut dyn Storage) -> Result<(), ContractError> {
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::errors::ContractError;
|
||||
use crate::storage::{
|
||||
load_balance, load_bond_pledge, load_gateway_pledge, load_withdrawn, remove_bond_pledge,
|
||||
remove_delegation, remove_gateway_pledge, save_account, save_balance, save_bond_pledge,
|
||||
save_gateway_pledge, save_withdrawn, BlockTimestampSecs, DELEGATIONS, KEY,
|
||||
save_gateway_pledge, save_withdrawn, BlockTimestampSecs, DELEGATIONS, KEY, OLD_DELEGATIONS,
|
||||
};
|
||||
use cosmwasm_std::{Addr, Coin, Order, Storage, Timestamp, Uint128};
|
||||
use cw_storage_plus::Bound;
|
||||
@@ -212,38 +212,36 @@ impl Account {
|
||||
mix: &str,
|
||||
storage: &mut dyn Storage,
|
||||
) -> Result<(), ContractError> {
|
||||
Err(ContractError::MaintenanceMode)
|
||||
//
|
||||
// let limit = 50;
|
||||
// let mut start_after = None;
|
||||
// let mut block_heights = Vec::new();
|
||||
// let mut prev_len = 0;
|
||||
// // TODO: Test this
|
||||
// loop {
|
||||
// block_heights.extend(
|
||||
// DELEGATIONS
|
||||
// .prefix((self.storage_key(), mix.to_string()))
|
||||
// .keys(storage, start_after, None, Order::Ascending)
|
||||
// .take(limit)
|
||||
// .filter_map(|key| key.ok()),
|
||||
// );
|
||||
//
|
||||
// if prev_len == block_heights.len() {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// prev_len = block_heights.len();
|
||||
//
|
||||
// start_after = block_heights.last().map(|last| Bound::exclusive(*last));
|
||||
// if start_after.is_none() {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for block_height in block_heights {
|
||||
// remove_delegation((self.storage_key(), mix.to_string(), block_height), storage)?;
|
||||
// }
|
||||
// Ok(())
|
||||
let limit = 50;
|
||||
let mut start_after = None;
|
||||
let mut block_heights = Vec::new();
|
||||
let mut prev_len = 0;
|
||||
// TODO: Test this
|
||||
loop {
|
||||
block_heights.extend(
|
||||
OLD_DELEGATIONS
|
||||
.prefix((self.storage_key(), mix.to_string()))
|
||||
.keys(storage, start_after, None, Order::Ascending)
|
||||
.take(limit)
|
||||
.filter_map(|key| key.ok()),
|
||||
);
|
||||
|
||||
if prev_len == block_heights.len() {
|
||||
break;
|
||||
}
|
||||
|
||||
prev_len = block_heights.len();
|
||||
|
||||
start_after = block_heights.last().map(|last| Bound::exclusive(*last));
|
||||
if start_after.is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for block_height in block_heights {
|
||||
remove_delegation((self.storage_key(), mix.to_string(), block_height), storage)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn total_delegations_for_mix(
|
||||
|
||||
Reference in New Issue
Block a user