Skip to content

Commit

Permalink
Merge pull request #8 from CarmineOptions/add-ekubo-pools
Browse files Browse the repository at this point in the history
Add ekubo pools
  • Loading branch information
tensojka authored Oct 25, 2024
2 parents 043390a + 7074ab6 commit 65858fc
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 7 deletions.
117 changes: 117 additions & 0 deletions src/arbitrary_proposal_add_ekubo_pools.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use starknet::ClassHash;

use starknet::ContractAddress;

#[starknet::interface]
trait IArbitraryProposalAddOptions<TContractState> {
fn execute_arbitrary_proposal(ref self: TContractState);
}


#[starknet::contract]
pub mod ArbitraryProposalAddEkuboPools {
use amm_governance::constants::{LP_TOKEN_CLASS_HASH, AMM_CLASS_HASH, OPTION_CALL, OPTION_PUT};
use amm_governance::traits::{
IAMMDispatcher, IAMMDispatcherTrait, IOptionTokenDispatcher, IOptionTokenDispatcherTrait
};

use core::integer::BoundedInt;
use core::traits::{Into, TryInto};

use cubit::f128::types::{Fixed, FixedTrait};
use starknet::ClassHash;
use starknet::ContractAddress;
use starknet::SyscallResult;
use starknet::SyscallResultTrait;
use starknet::syscalls::deploy_syscall;


#[storage]
struct Storage {}

#[derive(starknet::Event, Drop)]
#[event]
enum Event {}

#[constructor]
fn constructor(ref self: ContractState) {}


#[abi(embed_v0)]
impl ArbitraryProposalAddOptions of super::IArbitraryProposalAddOptions<ContractState> {
fn execute_arbitrary_proposal(ref self: ContractState) {
let AMM_ADDRESS: ContractAddress =
0x047472e6755afc57ada9550b6a3ac93129cc4b5f98f51c73e0644d129fd208d9
.try_into()
.unwrap();

let USDC_TOKEN: ContractAddress =
0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8
.try_into()
.unwrap();

let EKUBO_TOKEN: ContractAddress =
0x075afe6402ad5a5c20dd25e10ec3b3986acaa647b77e4ae24b0cbc9a54a27a87
.try_into()
.unwrap();

// Create amm dispatcher
let amm = IAMMDispatcher { contract_address: AMM_ADDRESS };

// Upgrade AMM to newest class hash
amm.upgrade(AMM_CLASS_HASH.try_into().unwrap());

// Deploy new lp tokens
let lptoken_class = LP_TOKEN_CLASS_HASH.try_into().unwrap();

// Ekubo Call Calldata
let mut ekubo_call_lpt_calldata = array![];
ekubo_call_lpt_calldata.append('Carmine EKUBO/USDC call pool'); // Name
ekubo_call_lpt_calldata.append('C-EKUBOUSDC-C'); // Symbol
ekubo_call_lpt_calldata.append(AMM_ADDRESS.into()); // Owner

// Ekubo Put Calldata
let mut ekubo_put_lpt_calldata = array![];
ekubo_put_lpt_calldata.append('Carmine EKUBO/USDC put pool'); // Name
ekubo_put_lpt_calldata.append('C-EKUBOUSDC-P'); // Symbol
ekubo_put_lpt_calldata.append(AMM_ADDRESS.into()); // Owner

// Call deploy
let call_deploy_retval = deploy_syscall(
lptoken_class, 'ekubousdc call', ekubo_call_lpt_calldata.span(), false
);
let (call_lpt_address, _) = call_deploy_retval.unwrap_syscall();
// Put deploy
let put_deploy_retval = deploy_syscall(
lptoken_class, 'ekubousdc put', ekubo_put_lpt_calldata.span(), false
);
let (put_lpt_address, _) = put_deploy_retval.unwrap_syscall();

// Add the lptokens to the AMM
let call_voladjspd = FixedTrait::new_unscaled(10_000, false);
let put_voladjspd = FixedTrait::new_unscaled(20_000, false);

// Call
amm
.add_lptoken(
USDC_TOKEN,
EKUBO_TOKEN,
OPTION_CALL,
call_lpt_address,
call_voladjspd,
BoundedInt::<u256>::max()
);

// Put
amm
.add_lptoken(
USDC_TOKEN,
EKUBO_TOKEN,
OPTION_PUT,
put_lpt_address,
put_voladjspd,
BoundedInt::<u256>::max()
);
}
}
}
2 changes: 1 addition & 1 deletion src/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const TRADE_SIDE_SHORT: felt252 = 1;
pub const LP_TOKEN_CLASS_HASH: felt252 =
0x06d15bc862ce48375ec98fea84d76ca67b7ac5978d80c848fa5496108783fbc2;
pub const AMM_CLASS_HASH: felt252 =
0x045fb686c8875f31966e7308d71c03e9ae78f9566a61870a2b616dc225dd3313;
0x0217863fdd0f365bff051411a5a1c792bb24e21c80f6bb4d297cef5ceb6d22f5;
pub const OPTION_TOKEN_CLASS_HASH: felt252 =
0x07fc0b6ecc96a698cdac8c4ae447816d73bffdd9603faacffc0a8047149d02ed;

Expand Down
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod arbitrary_proposal_add_ekubo_pools;
mod arbitrary_proposal_add_options;
pub mod carm;
pub mod constants;
Expand Down
9 changes: 5 additions & 4 deletions src/traits.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use amm_governance::types::{OptionType, OptionSide, Option_};
use amm_governance::types::{OptionType, OptionSide, Option_, Pool};
use cubit::f128::types::{Fixed, FixedTrait};
use starknet::{ContractAddress, ClassHash};

Expand Down Expand Up @@ -158,9 +158,9 @@ pub trait IAMM<TContractState> {
base_token_address: ContractAddress,
option_type: OptionType,
) -> ContractAddress;
// fn get_pool_definition_from_lptoken_address(
// self: @TContractState, lptoken_addres: ContractAddress
// ) -> Pool;
fn get_pool_definition_from_lptoken_address(
self: @TContractState, lptoken_addres: ContractAddress
) -> Pool;
fn get_option_volatility(
self: @TContractState, lptoken_address: ContractAddress, maturity: u64, strike_price: Fixed,
) -> Fixed;
Expand Down Expand Up @@ -212,6 +212,7 @@ pub trait IAMM<TContractState> {
fn set_pragma_required_checkpoints(ref self: TContractState);
fn upgrade(ref self: TContractState, new_implementation: ClassHash);
fn transfer_ownership(ref self: TContractState, new_owner: ContractAddress);
fn owner(self: @TContractState) -> ContractAddress;
}

#[starknet::interface]
Expand Down
7 changes: 7 additions & 0 deletions src/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ pub struct Option_ {
pub base_token_address: ContractAddress,
pub option_type: OptionType
}

#[derive(Copy, Drop, Serde)]
pub struct Pool {
pub quote_token_address: ContractAddress,
pub base_token_address: ContractAddress,
pub option_type: OptionType,
}
Loading

0 comments on commit 65858fc

Please sign in to comment.