Skip to content

Commit

Permalink
chore: forward fees from first epoch to the upcoming one
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Jan 27, 2024
1 parent a5528e5 commit a63b43f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 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/liquidity_hub/fee_distributor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fee_distributor"
version = "0.9.1"
version = "0.9.2"
authors = ["Kerber0x <[email protected]>"]
edition.workspace = true
description = "Contract to distribute the fees collected by the Fee Collector."
Expand Down
8 changes: 8 additions & 0 deletions contracts/liquidity_hub/fee_distributor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,13 @@ pub fn migrate(mut deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Respons
.add_attribute("action", "migrate"));
}

#[cfg(feature = "osmosis")]
if storage_version == Version::parse("0.9.1")? {
let fees_refund_messages = migrations::migrate_to_v091_hotfix(deps.branch())?;
return Ok(Response::default()
.add_messages(fees_refund_messages)
.add_attribute("action", "migrate"));
}

Ok(Response::default())
}
34 changes: 34 additions & 0 deletions contracts/liquidity_hub/fee_distributor/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,37 @@ pub fn migrate_to_v091(deps: DepsMut) -> Result<Vec<CosmosMsg>, 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<Vec<CosmosMsg>, 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)
}

0 comments on commit a63b43f

Please sign in to comment.