Skip to content

Commit

Permalink
Isolate problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tensojka committed Nov 3, 2023
1 parent 257a4f1 commit 564d172
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/ilhedge/carmine.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ fn price_option(strike: Fixed, notional: u128, expiry: u64, calls: bool, amm_add
notional.print();
'strike:'.print();
strike.print();
'calls:'.print();
calls.print();
let option = Option_ {
option_side: 0,
maturity: expiry.into(),
Expand Down
37 changes: 18 additions & 19 deletions tests/ilhedge/test_ilhedge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use carmine_protocol::ilhedge::contract::{IILHedgeDispatcher, IILHedgeDispatcher
use carmine_protocol::testing::setup::{Ctx, Dispatchers};
use carmine_protocol::amm_core::amm::{AMM, IAMMDispatcher, IAMMDispatcherTrait};

use debug::PrintTrait;
#[test]
fn test_ilhedge() {
let (ctx, dsps) = deploy_setup();

'hi'.print();
// set spot price
start_mock_call(
PRAGMA_ORACLE_ADDRESS.try_into().unwrap(),
Expand All @@ -24,6 +25,7 @@ fn test_ilhedge() {
}
);
add_needed_options(ctx, dsps);
'hello'.print();

let ilhedge_contract = declare('ILHedge');

Expand All @@ -40,28 +42,25 @@ fn test_ilhedge() {
}

fn add_needed_options(ctx: Ctx, dsps: Dispatchers) {
let FIXED_BASE = 18446744073709551616; // 2**64
let CALL = 0;
let PUT = 1;
add_option_to_amm(ctx, dsps, 1700 * FIXED_BASE, CALL);
add_option_to_amm(ctx, dsps, 1800 * FIXED_BASE, CALL);
add_option_to_amm(ctx, dsps, 1900 * FIXED_BASE, CALL);
add_option_to_amm(ctx, dsps, 2000 * FIXED_BASE, CALL);
add_option_to_amm(ctx, dsps, 1300 * FIXED_BASE, PUT);
add_option_to_amm(ctx, dsps, 1400 * FIXED_BASE, PUT);
add_option_to_amm(ctx, dsps, 1500 * FIXED_BASE, PUT);
add_option_to_amm(ctx, dsps, 1600 * FIXED_BASE, PUT);
add_option_to_amm(ctx, dsps, 1700, CALL);
add_option_to_amm(ctx, dsps, 1800, CALL);
add_option_to_amm(ctx, dsps, 1900, CALL);
add_option_to_amm(ctx, dsps, 2000, CALL);
add_option_to_amm(ctx, dsps, 1300, PUT);
add_option_to_amm(ctx, dsps, 1400, PUT);
// add_option_to_amm(ctx, dsps, 1500, PUT); // already added
add_option_to_amm(ctx, dsps, 1600, PUT);
}

fn add_option_to_amm(ctx: Ctx, dsps: Dispatchers, strike: u128, option_type: u8) {
start_prank(ctx.amm_address, ctx.admin_address);
let FIXED_BASE = 18446744073709551616; // 2**64
let expiry: u64 = 1000000000 + 60 * 60 * 24; // current time plus 24 hours
let LONG = 0;
let SHORT = 1;
let hundred = FixedTrait::from_unscaled_felt(100);

let option_token_contract = declare('OptionToken');
let strike_fixed = FixedTrait::from_unscaled_felt(strike.into());

let mut long_constructor_data: Array<felt252> = ArrayTrait::new();
long_constructor_data.append('OptLong');
Expand All @@ -70,10 +69,10 @@ fn add_option_to_amm(ctx: Ctx, dsps: Dispatchers, strike: u128, option_type: u8)
long_constructor_data.append(ctx.usdc_address.into());
long_constructor_data.append(ctx.eth_address.into());
long_constructor_data.append(option_type.into());
long_constructor_data.append(strike.into());
long_constructor_data.append(strike_fixed.mag.into());
long_constructor_data.append(expiry.into());
long_constructor_data.append(LONG);
let long_option_address = option_token_contract.deploy(@long_constructor_data).unwrap();
let long_option_address = ctx.opt_contract.deploy(@long_constructor_data).unwrap();


let mut short_constructor_data: Array<felt252> = ArrayTrait::new();
Expand All @@ -83,21 +82,21 @@ fn add_option_to_amm(ctx: Ctx, dsps: Dispatchers, strike: u128, option_type: u8)
short_constructor_data.append(ctx.usdc_address.into());
short_constructor_data.append(ctx.eth_address.into());
short_constructor_data.append(option_type.into());
short_constructor_data.append(strike.into());
short_constructor_data.append(strike_fixed.mag.into());
short_constructor_data.append(expiry.into());
short_constructor_data.append(SHORT);
let short_option_address = option_token_contract.deploy(@short_constructor_data).unwrap();
let short_option_address = ctx.opt_contract.deploy(@short_constructor_data).unwrap();


let lpt_addr = if (option_type == 0) {ctx.call_lpt_address}else{ctx.call_lpt_address};
dsps
.amm
.add_option_both_sides(
expiry,
strike,
strike_fixed,
ctx.usdc_address,
ctx.eth_address,
option_type.try_into().unwrap(),
option_type,
lpt_addr,
long_option_address,
short_option_address,
Expand Down

0 comments on commit 564d172

Please sign in to comment.