@@ -13,18 +13,59 @@ mod UserPoolInfoContract {
1313 use starknet :: ContractAddress ;
1414
1515 use carmine_protocol :: types :: pool :: UserPoolInfo ;
16- use carmine_protocol :: types :: pool :: {PoolInfo , PoolTrait };
16+ use carmine_protocol :: types :: pool :: {PoolInfo , Pool };
1717 use carmine_protocol :: erc20_interface :: {IERC20Dispatcher , IERC20DispatcherTrait };
18+ use cubit :: f128 :: types :: fixed :: {Fixed , FixedTrait };
19+
20+ #[generate_trait]
21+ impl PoolImpl of PoolTrait {
22+ fn from_lpt_address (lpt_addr : ContractAddress , amm : IAMMDispatcher ) -> Pool {
23+ amm . get_pool_definition_from_lptoken_address (lpt_addr )
24+ }
25+
26+ fn lpt_addr (self : Pool , amm : IAMMDispatcher ) -> ContractAddress {
27+ amm . get_lptoken_address_for_given_option (
28+ self . quote_token_address, self . base_token_address, self . option_type
29+ )
30+ }
31+
32+ fn lpool_balance (self : Pool , amm : IAMMDispatcher ) -> u256 {
33+ amm . get_lpool_balance (self . lpt_addr (amm ))
34+ }
35+
36+ fn unlocked_capital (self : Pool , amm : IAMMDispatcher ) -> u256 {
37+ amm . get_unlocked_capital (self . lpt_addr (amm ))
38+ }
39+
40+ fn value_of_position (self : Pool , amm : IAMMDispatcher ) -> Fixed {
41+ amm . get_value_of_pool_position (self . lpt_addr (amm ))
42+ }
43+
44+ fn to_PoolInfo (self : Pool , amm : IAMMDispatcher ) -> PoolInfo {
45+ PoolInfo {
46+ pool : self ,
47+ lptoken_address : self . lpt_addr (amm ),
48+ staked_capital : self . lpool_balance (amm ),
49+ unlocked_capital : self . unlocked_capital (amm ),
50+ value_of_pool_position : self . value_of_position (amm )
51+ }
52+ }
53+ }
1854 #[generate_trait]
1955 impl PoolInfoImpl of PoolInfoTrait {
20- fn to_UserPoolInfo (self : PoolInfo , user_address : ContractAddress , amm : IAMMDispatcher ) -> UserPoolInfo {
56+ fn to_UserPoolInfo (
57+ self : PoolInfo , user_address : ContractAddress , amm : IAMMDispatcher
58+ ) -> UserPoolInfo {
2159 let lptoken_balance = IERC20Dispatcher { contract_address : self . lptoken_address }
2260 . balanceOf (user_address );
2361
24- let stake_value = amm . get_underlying_for_lptokens (self . lptoken_address, lptoken_balance );
62+ let stake_value = amm
63+ . get_underlying_for_lptokens (self . lptoken_address, lptoken_balance );
2564
2665 UserPoolInfo {
27- value_of_user_stake : stake_value , size_of_users_tokens : lptoken_balance , pool_info : self
66+ value_of_user_stake : stake_value ,
67+ size_of_users_tokens : lptoken_balance ,
68+ pool_info : self
2869 }
2970 }
3071 }
@@ -47,7 +88,7 @@ mod UserPoolInfoContract {
4788 self : @ ContractState , user : ContractAddress , lpt_addr : ContractAddress
4889 ) -> UserPoolInfo {
4990 let amm = IAMMDispatcher { contract_address : AMM_ADDR . try_into (). unwrap () };
50- let pool_info = PoolTrait :: from_lpt_address (lpt_addr ). to_PoolInfo ();
91+ let pool_info = PoolTrait :: from_lpt_address (lpt_addr , amm ). to_PoolInfo (amm );
5192 pool_info . to_UserPoolInfo (user , amm )
5293 }
5394 }
0 commit comments