Skip to content

Commit

Permalink
LQT: implement budget appropriation function
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Jan 31, 2025
1 parent eb3624c commit a0ebecb
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
use async_trait::async_trait;
use cnidarium::StateWrite;
use penumbra_sdk_asset::{Value, STAKING_TOKEN_ASSET_ID};
use penumbra_sdk_community_pool::{StateReadExt as _, StateWriteExt as _};
use penumbra_sdk_dex::lp::position;
use penumbra_sdk_distributions::component::{StateReadExt as _, StateWriteExt as _};
use penumbra_sdk_keys::Address;
use penumbra_sdk_num::fixpoint::U128x128;
use penumbra_sdk_num::{fixpoint::U128x128, Amount};

/// Move a fraction of the budget, up to the entire budget, from the community pool.
///
/// This will return the amount pulled (in terms of the staking token).
#[allow(dead_code)]
async fn appropriate_budget(
mut state: impl StateWrite,
fraction: U128x128,
) -> anyhow::Result<Amount> {
// For our purposes, no budget is the same as an explicit budget of 0.
let budget = state
.get_lqt_reward_issuance_for_epoch()
.unwrap_or_default();
// IMO this method should have just expected to begin with.
let portion = fraction
.apply_to_amount(&budget)
.expect(&format!("failed to apply {fraction} to {budget:?}"));
// This fraction may be > 1.0, in which case we need to not over-appropriate
let (new_budget, portion) = match budget.checked_sub(&portion) {
Some(new_budget) => (new_budget, portion),
// portion > budget, so eat the whole budget.
None => (0u64.into(), budget),
};
state.set_lqt_reward_issuance_for_epoch(new_budget);
state
.community_pool_withdraw(Value {
asset_id: *STAKING_TOKEN_ASSET_ID,
amount: portion,
})
.await?;
Ok(portion)
}

#[allow(dead_code)]
#[async_trait]
Expand Down

0 comments on commit a0ebecb

Please sign in to comment.