Skip to content

Conversation

@0xbigz
Copy link
Member

@0xbigz 0xbigz commented Apr 7, 2022

add k update on update_funding_rate
clean up repeg logic using oracle delay for target_price weight

0xbigz and others added 30 commits January 14, 2022 13:31

pub fn formulaic_k(
market: &mut Market,
mark_price: u128,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

market: &mut Market,
mark_price: u128,
oracle_price_data: &OraclePriceData,
is_oracle_valid: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Ok(())
}

pub fn formulaic_k(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name should be a verb/action e.g. formulaic_update_k

funding_imbalance_cost
.checked_div(2)
.ok_or_else(math_error!())?
} else if market.amm.net_revenue_since_last_funding < (funding_imbalance_cost as i64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casting i128 to i64 can technically fail, so i'd use cast_to_i64.

Also i'd just declare it once instead of casting twice

let funding_imbalance_cost_i64 = cast_to_i64(funding_imbalance_cost)?;

let curve_history = curve_history.unwrap();

// single k scale is capped by .1% increase and .09% decrease (regardless of budget)
let (p_numer, p_denom) = amm::calculate_budgeted_k_scale(market, budget)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does p stand for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p * k_old = k_new (notation from a paper)

@@ -0,0 +1,2296 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete


price_oracle.agg.price = price;
price_oracle.agg.conf = 0;
price_oracle.valid_slot = 228506959; //todo just turned 1->2 for negative delay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete?

Ok(new_peg)
}

pub fn calculate_mm_target_price(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is mm?

Copy link
Member Author

@0xbigz 0xbigz Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amm, updating name

oracle_price_data: &OraclePriceData,
) -> ClearingHouseResult<u128> {
// calculates peg_multiplier that changing to would cost no more than budget
let oracle_delay = oracle_price_data.delay;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

.checked_mul(market.base_asset_amount)
.ok_or_else(math_error!())?
.checked_div(
AMM_TO_QUOTE_PRECISION_RATIO_I128 * cast_to_i128(FUNDING_PAYMENT_PRECISION)?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be a constant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants