Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
nikanor.goreglyad committed Jul 18, 2024
1 parent 49d7961 commit b293a0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/amm_core/amm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ mod AMM {
volatility_adjustment_speed: Fixed,
max_lpool_bal: u256,
) {
self.ownable.assert_only_owner();

self.re_guard.start();
LiquidityPool::add_lptoken(
Expand All @@ -329,7 +328,6 @@ mod AMM {
option_token_address_short: ContractAddress,
initial_volatility: Fixed,
) {
self.ownable.assert_only_owner();

self.re_guard.start();
Options::add_option_both_sides(
Expand Down
6 changes: 4 additions & 2 deletions src/amm_core/pricing/lookup_table_cdf.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use array::ArrayTrait;
use array::SpanTrait;


const CDF_LOOKUP_TABLE: Array<u128> = array![
fn get_std_normal_cdf_table() -> Array<u128> {
array![
9223372036854775808_u128,
9252808702943967232_u128,
9282244898050897920_u128,
Expand Down Expand Up @@ -2004,4 +2005,5 @@ const CDF_LOOKUP_TABLE: Array<u128> = array![
18446744073709539328_u128,
18446744073709539328_u128,
18446744073709539328_u128
].span()
]
}
8 changes: 4 additions & 4 deletions src/amm_core/pricing/option_pricing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod OptionPricing {
use array::ArrayTrait;
use array::SpanTrait;

use carmine_protocol::amm_core::pricing::lookup_table_cdf::CDF_LOOKUP_TABLE;
use carmine_protocol::amm_core::pricing::lookup_table_cdf::get_std_normal_cdf_table;

const CONST_A: u128 = 4168964160658358665; // 0.226 * 2**64
const CONST_B: u128 = 11805916207174113034; // 0.64 * 2**64
Expand Down Expand Up @@ -84,16 +84,16 @@ mod OptionPricing {
}

fn std_normal_cdf(x: Fixed) -> Fixed {
let std_normal_cdf_table = CDF_LOOKUP_TABLE;
let std_normal_cdf_table = get_std_normal_cdf_table();
if x.sign {
let dist_symmetric_value = std_normal_cdf(x.abs());
return (FixedTrait::ONE() - dist_symmetric_value);
};
let scaled_x = x * FixedTrait::new(4000, false);
let scaled_x = x * FixedTrait::new(2000, false);
let index_fixed = scaled_x / FixedTrait::new(147573952589676412928, false); // 2^67
let index: usize = index_fixed.mag.try_into().unwrap();
// let max_index = std_normal_cdf_table.len() - 1;
let max_index: usize = 4000;
let max_index: usize = 2000;
let safe_index = if index > max_index { max_index } else { index };
let cdf_value = *std_normal_cdf_table.at(safe_index);
let result = FixedTrait::new(cdf_value, false);
Expand Down

0 comments on commit b293a0f

Please sign in to comment.