Skip to content

Commit

Permalink
Backup work
Browse files Browse the repository at this point in the history
  • Loading branch information
tensojka committed Nov 4, 2023
1 parent 564d172 commit d20d4b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/amm_core/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ mod State {
state.new_option_position.read((lptoken_address, option_side, maturity, strike_price.mag))
}

use debug::PrintTrait;
fn set_option_position(
lptoken_address: LPTAddress,
option_side: OptionSide,
Expand Down
2 changes: 1 addition & 1 deletion src/ilhedge/carmine.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn price_option(strike: Fixed, notional: u128, expiry: u64, calls: bool, amm_add
notional.print();
'strike:'.print();
strike.print();
'calls:'.print();
'calls?:'.print();
calls.print();
let option = Option_ {
option_side: 0,
Expand Down
5 changes: 5 additions & 0 deletions src/ilhedge/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mod ILHedge {
use option::OptionTrait;
use traits::{Into, TryInto};

use debug::PrintTrait;

use starknet::ContractAddress;
use starknet::ClassHash;
use starknet::{get_caller_address, get_contract_address};
Expand Down Expand Up @@ -185,12 +187,15 @@ mod ILHedge {
match strikes_puts.pop_front() {
Option::Some(strike_pair) => {
let (tobuy, tohedge) = *strike_pair;
'tobuy(in puts):'.print();
tobuy.print();
// compute how much portf value would be at each hedged strike
// converts the excess to the hedge result asset (calls -> convert to eth)
// for each strike
let portf_val_puts = compute_portfolio_value(
curr_price, notional, false, tohedge
); // value of second asset is precisely as much as user put in, expecting conversion
'computed portf val puts'.print();
assert(portf_val_puts > FixedTrait::ZERO(), 'portf val puts < 0?');
assert(
portf_val_puts < (convert_from_int_to_Fixed(notional, 18) * curr_price),
Expand Down
10 changes: 7 additions & 3 deletions tests/ilhedge/test_ilhedge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,26 @@ fn test_ilhedge() {
assert(ilhedge_address.into() != 0, 'ilhedge addr 0');
let ilhedge = IILHedgeDispatcher { contract_address: ilhedge_address };
let expiry = 1000000000 + 60 * 60 * 24; // current time plus 24 hours, taken from setup
let (pricecalls, priceputs) = ilhedge.price_hedge(10000000000000, ctx.usdc_address, ctx.eth_address, expiry);
let (pricecalls, priceputs) = ilhedge.price_hedge(1000000000000000000, ctx.usdc_address, ctx.eth_address, expiry);
'pricecalls:'.print();
pricecalls.print();
assert(pricecalls == 69, 'pricecalls wut');
'priceputs:'.print();
priceputs.print();
assert(priceputs == 42, 'priceputs wut');
}

fn add_needed_options(ctx: Ctx, dsps: Dispatchers) {
let CALL = 0;
let PUT = 1;
add_option_to_amm(ctx, dsps, 1600, 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) {
Expand Down Expand Up @@ -88,7 +92,7 @@ fn add_option_to_amm(ctx: Ctx, dsps: Dispatchers, strike: u128, option_type: u8)
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};
let lpt_addr = if (option_type == 0) {ctx.call_lpt_address}else{ctx.put_lpt_address};
dsps
.amm
.add_option_both_sides(
Expand Down

0 comments on commit d20d4b9

Please sign in to comment.