Skip to content

Commit

Permalink
fix(CL pair): added migration for pair info (astroport-fi#43)
Browse files Browse the repository at this point in the history
* Added pair type migration for CL pool
  • Loading branch information
P-Yevhenii authored Apr 3, 2023
1 parent b241fe9 commit 0b00509
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/pair_concentrated/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astroport-pair-concentrated"
version = "1.1.3"
version = "1.1.4"
authors = ["Astroport"]
edition = "2021"
description = "The Astroport concentrated liquidity pair"
Expand Down
3 changes: 2 additions & 1 deletion contracts/pair_concentrated/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use astroport::token::InstantiateMsg as TokenInstantiateMsg;

use crate::error::ContractError;
use crate::math::{calc_d, get_xcp};
use crate::migration::migrate_config;
use crate::state::{
store_precisions, AmpGamma, Config, PoolParams, PoolState, Precisions, PriceState, CONFIG,
OWNERSHIP_PROPOSAL,
Expand Down Expand Up @@ -828,7 +829,7 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, C

match contract_version.contract.as_ref() {
"astroport-pair-concentrated" => match contract_version.version.as_ref() {
"1.0.0" | "1.1.0" | "1.1.1" | "1.1.2" => {}
"1.0.0" | "1.1.0" | "1.1.1" | "1.1.2" => migrate_config(deps.storage)?,
_ => return Err(ContractError::MigrationError {}),
},
_ => return Err(ContractError::MigrationError {}),
Expand Down
1 change: 1 addition & 0 deletions contracts/pair_concentrated/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pub mod state;
pub mod consts;
pub mod error;
pub mod math;
mod migration;
pub mod queries;
pub mod utils;
78 changes: 78 additions & 0 deletions contracts/pair_concentrated/src/migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use astroport::asset::{AssetInfo, PairInfo};
use astroport::factory::PairType;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, StdError, Storage, Uint128};
use cw_storage_plus::Item;

use crate::state::{Config, CONFIG};
use crate::state::{PoolParams, PoolState};

pub(crate) fn migrate_config(storage: &mut dyn Storage) -> Result<(), StdError> {
#[cw_serde]
pub enum OldPairType {
/// XYK pair type
Xyk {},
/// Stable pair type
Stable {},
/// Concentrated pair type
Concentrated {},
/// Custom pair type
Custom(String),
}

#[cw_serde]
pub struct OldPairInfo {
/// Asset information for the assets in the pool
pub asset_infos: Vec<AssetInfo>,
/// Pair contract address
pub contract_addr: Addr,
/// Pair LP token address
pub liquidity_token: Addr,
/// The pool type (xyk, stableswap etc) available in [`PairType`]
pub pair_type: OldPairType,
}

/// This structure stores the main config parameters for a constant product pair contract.
#[cw_serde]
pub struct OldConfig {
/// The pair information stored in a [`PairInfo`] struct
pub pair_info: OldPairInfo,
/// The factory contract address
pub factory_addr: Addr,
/// The last timestamp when the pair contract updated the asset cumulative prices
pub block_time_last: u64,
/// The vector contains cumulative prices for each pair of assets in the pool
pub cumulative_prices: Vec<(AssetInfo, AssetInfo, Uint128)>,
/// Pool parameters
pub pool_params: PoolParams,
/// Pool state
pub pool_state: PoolState,
/// Pool's owner
pub owner: Option<Addr>,
}

/// Stores the config struct at the given key
pub const OLD_CONFIG: Item<OldConfig> = Item::new("config");

let old_config = OLD_CONFIG.load(storage)?;
let pair_info = PairInfo {
asset_infos: old_config.pair_info.asset_infos,
contract_addr: old_config.pair_info.contract_addr,
liquidity_token: old_config.pair_info.liquidity_token,
pair_type: PairType::Custom("concentrated".to_string()),
};

let new_config = Config {
pair_info,
factory_addr: old_config.factory_addr,
block_time_last: old_config.block_time_last,
cumulative_prices: old_config.cumulative_prices,
pool_params: old_config.pool_params,
pool_state: old_config.pool_state,
owner: old_config.owner,
};

CONFIG.save(storage, &new_config)?;

Ok(())
}

0 comments on commit 0b00509

Please sign in to comment.