Skip to content

Commit

Permalink
feat: add 1901 options
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveVodrazka committed Jan 6, 2024
1 parent 6837449 commit 450b06a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 56 deletions.
10 changes: 8 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ version = 1

[[package]]
name = "cubit"
version = "1.2.0"
source = "git+https://github.com/influenceth/cubit.git#b4590530d5aeae9aabd36740cc2a3d9e6adc5fde"
version = "1.3.0"
source = "git+https://github.com/akhercha/cubit.git?branch=chore%2Fcairo_upgrade#d3869a3f0c47e5ed229bbbfe2fce3fc0510cbc8a"

[[package]]
name = "governance"
version = "0.2.0"
dependencies = [
"cubit",
"snforge_std",
]

[[package]]
name = "snforge_std"
version = "0.13.1"
source = "git+https://github.com/foundry-rs/starknet-foundry.git#22325e4d4e4770ba5068368162a4fc0ed94128bb"
7 changes: 4 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ cairo-version = "2.3.1"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
cubit = { git = "https://github.com/influenceth/cubit.git", commit = "b4590530d5aeae9aabd36740cc2a3d9e6adc5fde" }
cubit = { git = "https://github.com/akhercha/cubit.git", branch = "chore/cairo_upgrade" }
starknet = ">=1.1.0"
#snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", commit = "acdd4a573cf6a89647f48124e75074674f844f47"}
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", commit = "acdd4a573cf6a89647f48124e75074674f844f47" }

[[target.starknet-contract]]
casm = true

[[tool.snforge.fork]]
name = "MAINNET"
Expand All @@ -21,4 +22,4 @@ block_id.tag = "Latest"
[[tool.snforge.fork]]
name = "GOERLI"
url = "https://limited-rpc.nethermind.io/goerli-juno"
block_id.tag = "Latest"
block_id.tag = "Latest"
7 changes: 7 additions & 0 deletions src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ trait IGovernance<TContractState> {
// OPTIONS / ONE-OFF

fn deploy_new_amm(ref self: TContractState);

fn add_1901_options(ref self: TContractState);
}


Expand All @@ -42,6 +44,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 @@ -147,5 +150,9 @@ mod Governance {
fn deploy_new_amm(ref self: ContractState) {
DeployAMM::deploy_amm()
}

fn add_1901_options(ref self: ContractState) {
Options::run_add_1901_options()
}
}
}
10 changes: 3 additions & 7 deletions src/deploy_amm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,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 +84,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
112 changes: 68 additions & 44 deletions src/options.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ 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::constants::{
OPTION_CALL, OPTION_PUT, TRADE_SIDE_LONG, TRADE_SIDE_SHORT, OPTION_TOKEN_CLASS_HASH
};
use governance::traits::{
IAMMDispatcher, IAMMDispatcherTrait, IOptionTokenDispatcher, IOptionTokenDispatcherTrait
};
Expand All @@ -30,18 +32,15 @@ mod Options {
use governance::types::OptionType;
use governance::contract::Governance::proposal_initializer_runContractMemberStateTrait;


fn add_options(mut options: Span<FutureOption>) {
// TODO use block hash from block_hash syscall as salt // actually doable with the new syscall
let governance_address = get_contract_address();
let state = Governance::unsafe_new_contract_state();
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,75 +128,80 @@ 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_1901_options(
eth_lpt_addr: ContractAddress,
eth_usdc_lpt_addr: ContractAddress,
btc_lpt_addr: ContractAddress,
btc_usdc_lpt_addr: ContractAddress
) {
let MATURITY: felt252 = 1705622399;

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-19JAN24-2300-LONG-CALL',
name_short: 'ETHUSDC-19JAN24-2300-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2300),
option_type: OPTION_CALL,
lptoken_address: eth_lpt_addr,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(70)
}
);
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2400-LONG-CALL',
name_short: 'ETHUSDC-12JAN24-2400-SHORT-CALL',
name_long: 'ETHUSDC-19JAN24-2400-LONG-CALL',
name_short: 'ETHUSDC-19JAN24-2400-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2400),
option_type: OPTION_CALL,
lptoken_address: eth_lpt_addr,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(62) + point_five
initial_volatility: FixedTrait::from_unscaled_felt(70) + point_five
}
);
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2500-LONG-CALL',
name_short: 'ETHUSDC-12JAN24-2500-SHORT-CALL',
name_long: 'ETHUSDC-19JAN24-2500-LONG-CALL',
name_short: 'ETHUSDC-19JAN24-2500-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2500),
option_type: OPTION_CALL,
lptoken_address: eth_lpt_addr,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(64)
initial_volatility: FixedTrait::from_unscaled_felt(72)
}
);
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2300-LONG-PUT',
name_short: 'ETHUSDC-12JAN24-2300-SHORT-PUT',
name_long: 'ETHUSDC-19JAN24-2200-LONG-PUT',
name_short: 'ETHUSDC-19JAN24-2200-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2300),
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)
initial_volatility: FixedTrait::from_unscaled_felt(70) + point_five
}
);
to_add
.append(
FutureOption {
name_long: 'ETHUSDC-12JAN24-2200-LONG-PUT',
name_short: 'ETHUSDC-12JAN24-2200-SHORT-PUT',
name_long: 'ETHUSDC-19JAN24-2100-LONG-PUT',
name_short: 'ETHUSDC-19JAN24-2100-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(2200),
strike_price: FixedTrait::from_unscaled_felt(2100),
option_type: OPTION_PUT,
lptoken_address: eth_usdc_lpt_addr,
btc: false,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(72)
}
);

Expand All @@ -205,56 +210,75 @@ mod Options {
to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-44000-LONG-CALL',
name_short: 'BTCUSD-12JAN24-44000-SHORT-CALL',
name_long: 'BTCUSD-19JAN24-44000-LONG-CALL',
name_short: 'BTCUSD-19JAN24-44000-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(44000),
option_type: OPTION_CALL,
lptoken_address: btc_lpt_addr,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(62) + point_five
initial_volatility: FixedTrait::from_unscaled_felt(74) + point_five
}
);
to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-45000-LONG-CALL',
name_short: 'BTCUSD-12JAN24-45000-SHORT-CALL',
name_long: 'BTCUSD-19JAN24-45000-LONG-CALL',
name_short: 'BTCUSD-19JAN24-45000-SHORT-CALL',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(45000),
option_type: OPTION_CALL,
lptoken_address: btc_lpt_addr,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(63) + point_five
initial_volatility: FixedTrait::from_unscaled_felt(75)
}
);
to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-43000-LONG-PUT',
name_short: 'BTCUSD-12JAN24-43000-SHORT-PUT',
name_long: 'BTCUSD-19JAN24-43000-LONG-PUT',
name_short: 'BTCUSD-19JAN24-43000-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(43000),
option_type: OPTION_PUT,
lptoken_address: btc_usdc_lpt_addr,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(74)
}
);
to_add
.append(
FutureOption {
name_long: 'BTCUSD-12JAN24-42000-LONG-PUT',
name_short: 'BTCUSD-12JAN24-42000-SHORT-PUT',
name_long: 'BTCUSD-19JAN24-42000-LONG-PUT',
name_short: 'BTCUSD-19JAN24-42000-SHORT-PUT',
maturity: MATURITY,
strike_price: FixedTrait::from_unscaled_felt(42000),
option_type: OPTION_PUT,
lptoken_address: btc_usdc_lpt_addr,
btc: true,
initial_volatility: FixedTrait::from_unscaled_felt(62)
initial_volatility: FixedTrait::from_unscaled_felt(75)
}
);

add_options(to_add.span())
}

fn run_add_1901_options() {
let mut state = Governance::unsafe_new_contract_state();

assert(!state.proposal_initializer_run.read(46), 'prop already initialized');
state.proposal_initializer_run.write(46, true);

let amm_address = state.get_amm_address();

// LP_ADDRESSES are ETH/USDC CALL, ETH/USDC PUT, BTC/USDC CALL, BTC/USDC PUT
let lp_addresses = IAMMDispatcher { contract_address: amm_address }
.get_all_lptoken_addresses();

assert(lp_addresses.len() == 4, 'unexpected lp_addresses length');

add_1901_options(
*lp_addresses.at(0), *lp_addresses.at(1), *lp_addresses.at(2), *lp_addresses.at(3)
);
}
}

0 comments on commit 450b06a

Please sign in to comment.