diff --git a/Cargo.lock b/Cargo.lock index c2ed3f62..04af1ffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -619,7 +619,7 @@ dependencies = [ [[package]] name = "fee_distributor" -version = "0.9.1" +version = "0.9.2" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/contracts/liquidity_hub/fee_distributor/Cargo.toml b/contracts/liquidity_hub/fee_distributor/Cargo.toml index c32358b4..459b95ce 100644 --- a/contracts/liquidity_hub/fee_distributor/Cargo.toml +++ b/contracts/liquidity_hub/fee_distributor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fee_distributor" -version = "0.9.1" +version = "0.9.2" authors = ["Kerber0x "] edition.workspace = true description = "Contract to distribute the fees collected by the Fee Collector." diff --git a/contracts/liquidity_hub/fee_distributor/src/contract.rs b/contracts/liquidity_hub/fee_distributor/src/contract.rs index 6488e0b7..46902f3a 100644 --- a/contracts/liquidity_hub/fee_distributor/src/contract.rs +++ b/contracts/liquidity_hub/fee_distributor/src/contract.rs @@ -193,5 +193,13 @@ pub fn migrate(mut deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result Result, StdError> { Ok(messages) } + +#[cfg(feature = "osmosis")] +/// Fixes the broken state for the first epoch on osmosis. +pub fn migrate_to_v091_hotfix(deps: DepsMut) -> Result, StdError> { + let claimable_epochs = get_claimable_epochs(deps.as_ref())?; + + let mut faulty_epoch = claimable_epochs + .epochs + .into_iter() + .find(|epoch| epoch.id == Uint64::from(1u64)) + .ok_or(StdError::generic_err("Epoch not found"))?; + + let fee_collector_addr = CONFIG.load(deps.storage)?.fee_collector_addr; + + // collect all available funds on faulty epochs and send them back to the fee collector, to be + // redistributed on the next (new) epoch + + let total_fees = asset::aggregate_assets(vec![], faulty_epoch.available.clone())?; + + // set the available fees of this faulty epoch to zero + faulty_epoch.available = vec![]; + + // save the faulty epoch in the state + EPOCHS.save(deps.storage, &faulty_epoch.id.to_be_bytes(), &faulty_epoch)?; + + // create messages to send total_fees back to the fee collector + let mut messages = vec![]; + + for fee in total_fees { + messages.push(fee.into_msg(fee_collector_addr.clone())?); + } + + Ok(messages) +}