Skip to content

Commit

Permalink
chore: migrate config state
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Jun 14, 2024
1 parent 5ac23a2 commit 1092450
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions contracts/alliance-hub/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
use cosmwasm_std::{Addr, DepsMut, Order, Uint128};
use alliance_protocol::alliance_protocol::Config;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Decimal, DepsMut, Order, Timestamp, Uint128};
use cw_asset::AssetInfo;
use cw_storage_plus::Map;
use cw_storage_plus::{Item, Map};

use crate::error::ContractError;
use crate::state::{SHARES, TOTAL_BALANCES_SHARES};
use crate::state::{CONFIG, SHARES, TOTAL_BALANCES_SHARES};

pub(crate) fn migrate_state(deps: DepsMut) -> Result<(), ContractError> {
#[cw_serde]
struct OldConfig {
pub governance: Addr,
pub controller: Addr,
pub oracle: Addr,
pub operator: Addr,
pub last_reward_update_timestamp: Timestamp,
pub alliance_token_denom: String,
pub alliance_token_supply: Uint128,
pub reward_denom: String,
}

const OLD_CONFIG: Item<OldConfig> = Item::new("config");
let old_config = OLD_CONFIG.load(deps.storage)?;

let config = Config {
governance: old_config.governance,
controller: old_config.controller,
oracle: old_config.oracle,
operator: old_config.operator,
take_rate_taker: Addr::unchecked(""),
last_reward_update_timestamp: old_config.last_reward_update_timestamp,
alliance_token_denom: old_config.alliance_token_denom,
alliance_token_supply: old_config.alliance_token_supply,
reward_denom: old_config.reward_denom,
default_yearly_take_rate: Decimal::percent(5),
};

CONFIG.save(deps.storage, &config)?;

const OLD_TOTAL_BALANCES: Map<&AssetInfo, Uint128> = Map::new("total_balances");

let old_map = OLD_TOTAL_BALANCES
Expand Down

0 comments on commit 1092450

Please sign in to comment.