@@ -175,7 +175,6 @@ impl YieldVault {
175175
176176 /// Read the total underlying assets represented by the vault.
177177 pub fn total_assets ( env : Env ) -> i128 {
178- Self :: get_state ( & env) . total_assets
179178 let idle_assets = env. storage ( ) . instance ( ) . get :: < _ , i128 > ( & DataKey :: TotalAssets ) . unwrap_or ( 0 ) ;
180179
181180 let strategy_assets = if let Some ( strategy_addr) = Self :: strategy ( env. clone ( ) ) {
@@ -630,8 +629,6 @@ impl YieldVault {
630629 // Transfer assets from user to vault
631630 token_client. transfer ( & user, & env. current_contract_address ( ) , & amount) ;
632631
633- token_client. transfer ( & user, & env. current_contract_address ( ) , & amount) ;
634-
635632 // Update state
636633 let ta = Self :: total_assets ( env. clone ( ) ) ;
637634 env. storage ( )
@@ -711,14 +708,10 @@ impl YieldVault {
711708 . set ( & DataKey :: TotalShares , & Self :: checked_sub ( ts, shares) ?) ;
712709
713710 env. storage ( ) . instance ( ) . set (
714- & DataKey :: ShareBalance ( user . clone ( ) ) ,
711+ & user_key ,
715712 & Self :: checked_sub ( user_shares, shares) ?,
716713 ) ;
717714
718- env. storage ( )
719- . instance ( )
720- . set ( & user_key, & ( user_shares - shares) ) ;
721-
722715 env. events ( ) . publish (
723716 ( symbol_short ! ( "withdraw" ) , user) ,
724717 ( assets_to_return, shares) ,
@@ -748,6 +741,7 @@ impl YieldVault {
748741
749742 // Update idle assets
750743 env. storage ( ) . instance ( ) . set ( & DataKey :: TotalAssets , & ( idle_ta - amount) ) ;
744+ Ok ( ( ) )
751745 }
752746
753747 /// Recall funds from the strategy.
@@ -784,6 +778,8 @@ impl YieldVault {
784778 . instance ( )
785779 . get :: < _ , i128 > ( & DataKey :: TotalAssets )
786780 . unwrap_or ( 0 ) ;
781+ // Update total assets state
782+ let ta = env. storage ( ) . instance ( ) . get :: < _ , i128 > ( & DataKey :: TotalAssets ) . unwrap_or ( 0 ) ;
787783 env. storage ( ) . instance ( ) . set ( & DataKey :: TotalAssets , & ( ta + amount) ) ;
788784
789785 let mut state = Self :: get_state ( & env) ;
@@ -796,12 +792,7 @@ impl YieldVault {
796792 ) ;
797793 }
798794
799- /// Legacy admin function retained for compatibility.
800- pub fn accrue_yield ( env : Env , amount : i128 ) {
801- Self :: distribute_yield ( env, amount) ;
802- }
803-
804- pub fn report_benji_yield ( env : Env , strategy : Address , amount : i128 ) {
795+ pub fn report_benji_yield ( env : Env , strategy : Address , amount : i128 ) -> Result < ( ) , VaultError > {
805796 strategy. require_auth ( ) ;
806797 if amount <= 0 {
807798 return Err ( VaultError :: InvalidAmount ) ;
@@ -810,7 +801,7 @@ impl YieldVault {
810801 let token_addr = Self :: token ( env. clone ( ) ) ;
811802 let token_client = token:: Client :: new ( & env, & token_addr) ;
812803
813- token_client. transfer ( & admin , & env. current_contract_address ( ) , & amount) ;
804+ token_client. transfer ( & strategy , & env. current_contract_address ( ) , & amount) ;
814805
815806 let ta = Self :: total_assets ( env. clone ( ) ) ;
816807 env. storage ( )
0 commit comments