Skip to content

Commit

Permalink
Update with master
Browse files Browse the repository at this point in the history
  • Loading branch information
tensojka committed Jan 17, 2024
1 parent 6897db7 commit 027cd2c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 282 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Cargo.lock

vendor/
.DS_Store
.snfoundry_cache/
.snfoundry_cache/
account*
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.14.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git#a1caebbfffd00e612c09ed89da006f6c48a92fd9"
8 changes: 4 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
name = "governance"
description = "A flexible monolithic governance contract, developed for use with Carmine Options AMM"
version = "0.2.0"
cairo-version = "2.3.1"
cairo-version = "2.4.0"

# 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" }
starknet = ">=1.1.0"
#snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", commit = "acdd4a573cf6a89647f48124e75074674f844f47"}
cubit = { git = "https://github.com/akhercha/cubit.git", branch = "chore/cairo_upgrade" }
starknet = ">=1.3.0"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", commit = "a1caebbfffd00e612c09ed89da006f6c48a92fd9"}

[[target.starknet-contract]]

Expand Down
7 changes: 4 additions & 3 deletions src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const NEW_PROPOSAL_QUORUM: u128 =
200; // 1/200 of totalSupply required to propose an upgrade. Quorums don't take into account investors. at all, they don't count into total eligible voters, but do vote
const PROPOSAL_VOTING_TIME_BLOCKS: u64 = 2500;
const QUORUM: u128 = 10; // 1/10 of totalSupply required to participate to pass
const MINUS_ONE: felt252 = 0x800000000000011000000000000000000000000000000000000000000000000;
const TEAM_TOKEN_BALANCE: u128 = 1000000000000000000;
Expand All @@ -20,6 +19,8 @@ const BTC_ADDRESS: felt252 = 0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5
// 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;
6 changes: 0 additions & 6 deletions src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ trait IGovernance<TContractState> {
// in component

// OPTIONS / ONE-OFF

fn deploy_new_amm(ref self: TContractState);
}


Expand Down Expand Up @@ -143,9 +141,5 @@ mod Governance {
fn apply_passed_proposal(ref self: ContractState, prop_id: felt252) {
Upgrades::apply_passed_proposal(prop_id)
}

fn deploy_new_amm(ref self: ContractState) {
DeployAMM::deploy_amm()
}
}
}
150 changes: 0 additions & 150 deletions src/deploy_amm.cairo

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod amm_types {
}
mod constants;
mod contract;
mod deploy_amm;
mod merkle_tree;
mod options;
mod proposals;
Expand Down
32 changes: 18 additions & 14 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 @@ -37,11 +39,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 +59,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 +73,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 +92,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 +107,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,7 +127,12 @@ mod Options {
}


fn add_1201_options(eth_lpt_addr: ContractAddress, eth_usdc_lpt_addr: ContractAddress, btc_lpt_addr: ContractAddress, btc_usdc_lpt_addr: ContractAddress) {
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;

let point_five = FixedTrait::ONE() / FixedTrait::from_unscaled_felt(2);
Expand Down
3 changes: 2 additions & 1 deletion src/upgrades.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ mod Upgrades {
match contract_type {
0 => {
let amm_addr: ContractAddress = state.get_amm_address();
IAMMDispatcher { contract_address: amm_addr }.upgrade(impl_hash.try_into().unwrap());
IAMMDispatcher { contract_address: amm_addr }
.upgrade(impl_hash.try_into().unwrap());
},
_ => {
if (contract_type == 1) {
Expand Down
Loading

0 comments on commit 027cd2c

Please sign in to comment.