diff --git a/Scarb.lock b/Scarb.lock index 1ff8c940..690fd022 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -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" diff --git a/Scarb.toml b/Scarb.toml index 8dd0dc64..cf5bdaef 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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" @@ -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" \ No newline at end of file +block_id.tag = "Latest" diff --git a/src/contract.cairo b/src/contract.cairo index 95895991..7bc18835 100644 --- a/src/contract.cairo +++ b/src/contract.cairo @@ -29,6 +29,8 @@ trait IGovernance { // OPTIONS / ONE-OFF fn deploy_new_amm(ref self: TContractState); + + fn add_1901_options(ref self: TContractState); } @@ -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; @@ -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() + } } } diff --git a/src/deploy_amm.cairo b/src/deploy_amm.cairo index d9ddb85a..465173e7 100644 --- a/src/deploy_amm.cairo +++ b/src/deploy_amm.cairo @@ -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'); @@ -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( diff --git a/src/options.cairo b/src/options.cairo index 73cd97f4..1eed9a7f 100644 --- a/src/options.cairo +++ b/src/options.cairo @@ -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 }; @@ -30,6 +32,7 @@ mod Options { use governance::types::OptionType; use governance::contract::Governance::proposal_initializer_runContractMemberStateTrait; + fn add_options(mut options: Span) { // TODO use block hash from block_hash syscall as salt // actually doable with the new syscall let governance_address = get_contract_address(); @@ -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 (); }, }; } @@ -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; @@ -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() @@ -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![]; @@ -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(), @@ -128,8 +128,13 @@ 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); @@ -137,66 +142,66 @@ mod Options { 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) } ); @@ -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) + ); + } }