Skip to content

Commit

Permalink
feat: add options 2 Feb 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveVodrazka committed Jan 17, 2024
1 parent a07b799 commit 88a1742
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 82 deletions.
11 changes: 9 additions & 2 deletions src/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ const USDC_ADDRESS: felt252 = 0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5
const ETH_ADDRESS: felt252 = 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7;
const BTC_ADDRESS: felt252 = 0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac;

const LP_ETH_USDC_CALL: felt252 = 0x70cad6be2c3fc48c745e4a4b70ef578d9c79b46ffac4cd93ec7b61f951c7c5c;
const LP_ETH_USDC_PUT: felt252 = 0x466e3a6731571cf5d74c5b0d9c508bfb71438de10f9a13269177b01d6f07159;
const LP_BTC_USDC_CALL: felt252 = 0x35db72a814c9b30301f646a8fa8c192ff63a0dc82beb390a36e6e9eba55b6db;
const LP_BTC_USDC_PUT: felt252 = 0x1bf27366077765c922f342c8de257591d1119ebbcbae7a6c4ff2f50ede4c54c;

// CLASS HASHES

// corresponds to commit 7b7db57419fdb25b93621fbea6a845005f7725d0 in protocol-cairo1 repo, branch audit-fixes
const LP_TOKEN_CLASS_HASH: felt252 = 0x06d15bc862ce48375ec98fea84d76ca67b7ac5978d80c848fa5496108783fbc2;
const LP_TOKEN_CLASS_HASH: felt252 =
0x06d15bc862ce48375ec98fea84d76ca67b7ac5978d80c848fa5496108783fbc2;
const AMM_CLASS_HASH: felt252 = 0x045fb686c8875f31966e7308d71c03e9ae78f9566a61870a2b616dc225dd3313;
const OPTION_TOKEN_CLASS_HASH: felt252 = 0x07fc0b6ecc96a698cdac8c4ae447816d73bffdd9603faacffc0a8047149d02ed;
const OPTION_TOKEN_CLASS_HASH: felt252 =
0x07fc0b6ecc96a698cdac8c4ae447816d73bffdd9603faacffc0a8047149d02ed;
7 changes: 4 additions & 3 deletions src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait IGovernance<TContractState> {

// OPTIONS / ONE-OFF

fn deploy_new_amm(ref self: TContractState);
fn add_020224_options(ref self: TContractState);
}


Expand All @@ -42,6 +42,7 @@ mod Governance {
use governance::upgrades::Upgrades;
use governance::deploy_amm::DeployAMM;
use governance::airdrop::airdrop as airdrop_component;
use governance::options::Options;

use starknet::ContractAddress;

Expand Down Expand Up @@ -144,8 +145,8 @@ mod Governance {
Upgrades::apply_passed_proposal(prop_id)
}

fn deploy_new_amm(ref self: ContractState) {
DeployAMM::deploy_amm()
fn add_020224_options(ref self: ContractState) {
Options::add_020224_options()
}
}
}
13 changes: 4 additions & 9 deletions src/deploy_amm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ mod DeployAMM {
use integer::BoundedInt;


use governance::amm_types::basic::{OptionType, OptionSide};
use governance::amm_types::basic::OptionType;
use governance::contract::Governance;
use governance::contract::Governance::proposal_initializer_runContractMemberStateTrait;
use governance::contract::Governance::amm_addressContractMemberStateTrait;
use governance::options::Options;
use governance::constants::{
AMM_CLASS_HASH, LP_TOKEN_CLASS_HASH, ETH_ADDRESS, USDC_ADDRESS, BTC_ADDRESS
};
Expand All @@ -26,9 +25,9 @@ mod DeployAMM {
fn deploy_amm() {
let amm_class: ClassHash = AMM_CLASS_HASH.try_into().unwrap();
let voladjspd_eth_call_lpt: felt252 = 15; // TODO check, no increase??
let voladjspd_eth_put_lpt: felt252 =
25000; // also BTC put pool
let voladjspd_btc_call_lpt: Fixed = FixedTrait::ONE() / FixedTrait::from_unscaled_felt(2); // 0.5 BTC voladjspd for btc call pool
let voladjspd_eth_put_lpt: felt252 = 25000; // also BTC put pool
let voladjspd_btc_call_lpt: Fixed = FixedTrait::ONE()
/ FixedTrait::from_unscaled_felt(2); // 0.5 BTC voladjspd for btc call pool

let mut state = Governance::unsafe_new_contract_state();
assert(!state.proposal_initializer_run.read(45), 'prop already initialized');
Expand Down Expand Up @@ -84,10 +83,6 @@ mod DeployAMM {
);

set_trading_halt_permissions(amm);

Options::add_1201_options(
eth_call_lpt_addr, eth_put_lpt_addr, btc_call_lpt_addr, btc_put_lpt_addr
);
}

fn deploy_lptoken(
Expand Down
142 changes: 74 additions & 68 deletions src/options.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ mod Options {

use cubit::f128::types::{Fixed, FixedTrait};

use governance::contract::Governance::{amm_address, proposal_initializer_run};
use governance::constants::{OPTION_CALL, OPTION_PUT, TRADE_SIDE_LONG, TRADE_SIDE_SHORT, OPTION_TOKEN_CLASS_HASH};
use governance::contract::Governance;
use governance::contract::Governance::{
amm_address, proposal_initializer_run, proposal_initializer_runContractMemberStateTrait
};
use governance::constants::{
OPTION_CALL, OPTION_PUT, TRADE_SIDE_LONG, TRADE_SIDE_SHORT, OPTION_TOKEN_CLASS_HASH,
LP_ETH_USDC_CALL, LP_ETH_USDC_PUT, LP_BTC_USDC_CALL, LP_BTC_USDC_PUT
};
use governance::traits::{
IAMMDispatcher, IAMMDispatcherTrait, IOptionTokenDispatcher, IOptionTokenDispatcherTrait
};
use governance::types::OptionSide;
use governance::contract::Governance;
use governance::types::OptionType;
use governance::contract::Governance::proposal_initializer_runContractMemberStateTrait;
use governance::types::{OptionSide, OptionType};

fn add_options(mut options: Span<FutureOption>) {
// TODO use block hash from block_hash syscall as salt // actually doable with the new syscall
Expand All @@ -37,11 +40,7 @@ mod Options {
let amm_address = state.get_amm_address();
loop {
match options.pop_front() {
Option::Some(option) => {
add_option(
governance_address, amm_address, option
);
},
Option::Some(option) => { add_option(governance_address, amm_address, option); },
Option::None(()) => { break (); },
};
}
Expand All @@ -61,9 +60,7 @@ mod Options {
}

fn add_option(
governance_address: ContractAddress,
amm_address: ContractAddress,
option: @FutureOption
governance_address: ContractAddress, amm_address: ContractAddress, option: @FutureOption
) {
let o = *option;

Expand All @@ -77,7 +74,7 @@ mod Options {
} else {
ETH_addr
};

// Yes, this 'overflows', but it's expected and wanted.
let custom_salt: felt252 = 42
+ o.strike_price.mag.into()
Expand All @@ -96,7 +93,9 @@ mod Options {
optoken_long_calldata.append(o.strike_price.mag.into());
optoken_long_calldata.append(o.maturity);
optoken_long_calldata.append(TRADE_SIDE_LONG);
let deploy_retval = deploy_syscall(opt_class_hash, custom_salt+1, optoken_long_calldata.span(), false);
let deploy_retval = deploy_syscall(
opt_class_hash, custom_salt + 1, optoken_long_calldata.span(), false
);
let (optoken_long_addr, _) = deploy_retval.unwrap_syscall();

let mut optoken_short_calldata = array![];
Expand All @@ -109,10 +108,11 @@ mod Options {
optoken_short_calldata.append(o.strike_price.mag.into());
optoken_short_calldata.append(o.maturity);
optoken_short_calldata.append(TRADE_SIDE_SHORT);
let deploy_retval = deploy_syscall(opt_class_hash, custom_salt+2, optoken_short_calldata.span(), false);
let deploy_retval = deploy_syscall(
opt_class_hash, custom_salt + 2, optoken_short_calldata.span(), false
);
let (optoken_short_addr, _) = deploy_retval.unwrap_syscall();


IAMMDispatcher { contract_address: amm_address }
.add_option_both_sides(
o.maturity.try_into().unwrap(),
Expand All @@ -128,130 +128,136 @@ mod Options {
}


fn add_1201_options(eth_lpt_addr: ContractAddress, eth_usdc_lpt_addr: ContractAddress, btc_lpt_addr: ContractAddress, btc_usdc_lpt_addr: ContractAddress) {
let MATURITY: felt252 = 1705017599;
fn add_020224_options() {
let eth_usdc_call_address = LP_ETH_USDC_CALL.try_into().unwrap();
let eth_usdc_put_address = LP_ETH_USDC_PUT.try_into().unwrap();
let btc_usdc_call_address = LP_BTC_USDC_CALL.try_into().unwrap();
let btc_usdc_put_address = LP_BTC_USDC_PUT.try_into().unwrap();

// Thu Feb 01 2024 23:59:59 GMT+0000
let MATURITY: felt252 = 1706831999;

let point_five = FixedTrait::ONE() / FixedTrait::from_unscaled_felt(2);

let mut to_add = ArrayTrait::<FutureOption>::new();
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2300-LONG-CALL',
name_short: 'ETHUSDC-12JAN24-2300-SHORT-CALL',
name_long: 'ETHUSDC-02FEB24-2600-LONG-CALL',
name_short: 'ETHUSDC-02FEB24-2600-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2300),
strike_price: FixedTrait::from_unscaled_felt(2600),
option_type: OPTION_CALL,
lptoken_address: eth_lpt_addr,
lptoken_address: eth_usdc_call_address,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(51)
}
);
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2400-LONG-CALL',
name_short: 'ETHUSDC-12JAN24-2400-SHORT-CALL',
name_long: 'ETHUSDC-02FEB24-2700-LONG-CALL',
name_short: 'ETHUSDC-02FEB24-2700-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2400),
strike_price: FixedTrait::from_unscaled_felt(2700),
option_type: OPTION_CALL,
lptoken_address: eth_lpt_addr,
lptoken_address: eth_usdc_call_address,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(62) + point_five
initial_volatility: FixedTrait::from_unscaled_felt(51)
}
);
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2500-LONG-CALL',
name_short: 'ETHUSDC-12JAN24-2500-SHORT-CALL',
name_long: 'ETHUSDC-02FEB24-2500-LONG-PUT',
name_short: 'ETHUSDC-02FEB24-2500-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2500),
option_type: OPTION_CALL,
lptoken_address: eth_lpt_addr,
option_type: OPTION_PUT,
lptoken_address: eth_usdc_put_address,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(64)
initial_volatility: FixedTrait::from_unscaled_felt(51) + point_five
}
);
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2300-LONG-PUT',
name_short: 'ETHUSDC-12JAN24-2300-SHORT-PUT',
name_long: 'ETHUSDC-02FEB24-2400-LONG-PUT',
name_short: 'ETHUSDC-02FEB24-2400-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2300),
strike_price: FixedTrait::from_unscaled_felt(2400),
option_type: OPTION_PUT,
lptoken_address: eth_usdc_lpt_addr,
lptoken_address: eth_usdc_put_address,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(53)
}
);

// BITCOIN

to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2200-LONG-PUT',
name_short: 'ETHUSDC-12JAN24-2200-SHORT-PUT',
name_long: 'BTCUSD-02FEB24-43000-LONG-CALL',
name_short: 'BTCUSD-02FEB24-43000-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2200),
option_type: OPTION_PUT,
lptoken_address: eth_usdc_lpt_addr,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(62)
strike_price: FixedTrait::from_unscaled_felt(43000),
option_type: OPTION_CALL,
lptoken_address: btc_usdc_call_address,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(48)
}
);

// BITCOIN

to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-44000-LONG-CALL',
name_short: 'BTCUSD-12JAN24-44000-SHORT-CALL',
name_long: 'BTCUSD-02FEB24-44000-LONG-CALL',
name_short: 'BTCUSD-02FEB24-44000-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(44000),
option_type: OPTION_CALL,
lptoken_address: btc_lpt_addr,
lptoken_address: btc_usdc_call_address,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(62) + point_five
initial_volatility: FixedTrait::from_unscaled_felt(48)
}
);
to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-45000-LONG-CALL',
name_short: 'BTCUSD-12JAN24-45000-SHORT-CALL',
name_long: 'BTCUSD-02FEB24-45000-LONG-CALL',
name_short: 'BTCUSD-02FEB24-45000-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(45000),
option_type: OPTION_CALL,
lptoken_address: btc_lpt_addr,
lptoken_address: btc_usdc_call_address,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(63) + point_five
initial_volatility: FixedTrait::from_unscaled_felt(48)
}
);
to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-43000-LONG-PUT',
name_short: 'BTCUSD-12JAN24-43000-SHORT-PUT',
name_long: 'BTCUSD-02FEB24-42000-LONG-PUT',
name_short: 'BTCUSD-02FEB24-42000-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(43000),
strike_price: FixedTrait::from_unscaled_felt(42000),
option_type: OPTION_PUT,
lptoken_address: btc_usdc_lpt_addr,
lptoken_address: btc_usdc_put_address,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(49)
}
);
to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-42000-LONG-PUT',
name_short: 'BTCUSD-12JAN24-42000-SHORT-PUT',
name_long: 'BTCUSD-02FEB24-41000-LONG-PUT',
name_short: 'BTCUSD-02FEB24-41000-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(42000),
strike_price: FixedTrait::from_unscaled_felt(41000),
option_type: OPTION_PUT,
lptoken_address: btc_usdc_lpt_addr,
lptoken_address: btc_usdc_put_address,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(50)
}
);

Expand Down

0 comments on commit 88a1742

Please sign in to comment.