11use starknet :: ContractAddress ;
22use carmine_protocol :: types :: option_ :: OptionWithPremia ;
3+ use carmine_protocol :: types :: pool :: {UserPoolInfo , PoolState };
34
45#[starknet:: interface]
56trait IAuxContract <TContractState > {
67 fn get_all_non_expired_options_with_premia (
78 self : @ TContractState , lpt_addr : ContractAddress
89 ) -> Array <OptionWithPremia >;
10+ fn get_user_pool_info (
11+ self : @ TContractState , user : ContractAddress , lpt_addr : ContractAddress
12+ ) -> UserPoolInfo ;
13+ fn get_pool_state (self : @ TContractState , lpt_addr : ContractAddress ) -> PoolState ;
914}
1015
1116#[starknet:: contract]
@@ -19,10 +24,71 @@ mod AuxContract {
1924 use carmine_protocol :: amm_interface :: IAMM ;
2025 use carmine_protocol :: amm_interface :: {IAMMDispatcher , IAMMDispatcherTrait };
2126
27+ use carmine_protocol :: types :: pool :: {UserPoolInfo , PoolState };
28+ use carmine_protocol :: types :: pool :: {PoolInfo , Pool };
29+ use carmine_protocol :: erc20_interface :: {IERC20Dispatcher , IERC20DispatcherTrait };
30+ use cubit :: f128 :: types :: fixed :: {Fixed , FixedTrait };
31+
2232 use carmine_protocol :: amm_core :: constants :: {
2333 TOKEN_USDC_ADDRESS , TOKEN_ETH_ADDRESS , TOKEN_WBTC_ADDRESS
2434 };
2535
36+
37+ #[generate_trait]
38+ impl PoolImpl of PoolTrait {
39+ fn from_lpt_address (lpt_addr : ContractAddress , amm : IAMMDispatcher ) -> Pool {
40+ amm . get_pool_definition_from_lptoken_address (lpt_addr )
41+ }
42+
43+ fn lpt_addr (self : Pool , amm : IAMMDispatcher ) -> ContractAddress {
44+ amm
45+ . get_lptoken_address_for_given_option (
46+ self . quote_token_address, self . base_token_address, self . option_type
47+ )
48+ }
49+
50+ fn lpool_balance (self : Pool , amm : IAMMDispatcher ) -> u256 {
51+ amm . get_lpool_balance (self . lpt_addr (amm ))
52+ }
53+
54+ fn unlocked_capital (self : Pool , amm : IAMMDispatcher ) -> u256 {
55+ amm . get_unlocked_capital (self . lpt_addr (amm ))
56+ }
57+
58+ fn value_of_position (self : Pool , amm : IAMMDispatcher ) -> Fixed {
59+ amm . get_value_of_pool_position (self . lpt_addr (amm ))
60+ }
61+
62+ fn to_PoolInfo (self : Pool , amm : IAMMDispatcher ) -> PoolInfo {
63+ PoolInfo {
64+ pool : self ,
65+ lptoken_address : self . lpt_addr (amm ),
66+ staked_capital : self . lpool_balance (amm ),
67+ unlocked_capital : self . unlocked_capital (amm ),
68+ value_of_pool_position : self . value_of_position (amm )
69+ }
70+ }
71+ }
72+ #[generate_trait]
73+ impl PoolInfoImpl of PoolInfoTrait {
74+ fn to_UserPoolInfo (
75+ self : PoolInfo , user_address : ContractAddress , amm : IAMMDispatcher
76+ ) -> UserPoolInfo {
77+ let lptoken_balance = IERC20Dispatcher { contract_address : self . lptoken_address }
78+ . balanceOf (user_address );
79+
80+ let stake_value = amm
81+ . get_underlying_for_lptokens (self . lptoken_address, lptoken_balance );
82+
83+ UserPoolInfo {
84+ value_of_user_stake : stake_value ,
85+ size_of_users_tokens : lptoken_balance ,
86+ pool_info : self
87+ }
88+ }
89+ }
90+
91+
2692 #[storage]
2793 struct Storage {}
2894
@@ -68,6 +134,27 @@ mod AuxContract {
68134
69135 arr
70136 }
137+
138+ fn get_user_pool_info (
139+ self : @ ContractState , user : ContractAddress , lpt_addr : ContractAddress
140+ ) -> UserPoolInfo {
141+ let amm = IAMMDispatcher { contract_address : AMM_ADDR . try_into (). unwrap () };
142+ let pool_info = PoolTrait :: from_lpt_address (lpt_addr , amm ). to_PoolInfo (amm );
143+ pool_info . to_UserPoolInfo (user , amm )
144+ }
145+
146+ fn get_pool_state (self : @ ContractState , lpt_addr : ContractAddress ) -> PoolState {
147+ let amm = IAMMDispatcher { contract_address : AMM_ADDR . try_into (). unwrap () };
148+ let locked = amm . get_pool_locked_capital (lpt_addr );
149+ let unlocked = amm . get_unlocked_capital (lpt_addr );
150+ let balance = amm . get_lpool_balance (lpt_addr );
151+ let position = amm . get_value_of_pool_position (lpt_addr );
152+ let value = amm
153+ . get_lptokens_for_underlying (
154+ lpt_addr , 1000000000000000000
155+ ); // 10**18 - get value of size 1
156+
157+ PoolState { locked , unlocked , balance , position , value , }
158+ }
71159 }
72160}
73-
0 commit comments