From 109245090574a9e2b352f890225913d3457f0ac0 Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Fri, 14 Jun 2024 15:49:28 +0100 Subject: [PATCH] chore: migrate config state --- contracts/alliance-hub/src/migrations.rs | 38 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/contracts/alliance-hub/src/migrations.rs b/contracts/alliance-hub/src/migrations.rs index 8ccbfee..920d0bb 100644 --- a/contracts/alliance-hub/src/migrations.rs +++ b/contracts/alliance-hub/src/migrations.rs @@ -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 = 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