@@ -8,6 +8,7 @@ pub type StakeId = (VaultId, AccountId);
88pub struct IdealRewardPool {
99 exchange_rate : BTreeMap < CurrencyId , FixedU128 > ,
1010 secure_threshold : BTreeMap < VaultId , FixedU128 > ,
11+ accept_new_issues : BTreeMap < VaultId , bool > ,
1112 commission : BTreeMap < VaultId , FixedU128 > ,
1213 collateral : BTreeMap < StakeId , u128 > ,
1314 rewards : BTreeMap < AccountId , ( FixedU128 , FixedU128 ) > ,
@@ -72,6 +73,10 @@ impl IdealRewardPool {
7273 . map ( |( stake_id, _) | self . stake ( stake_id) )
7374 . fold ( Zero :: zero ( ) , |x : FixedU128 , y : FixedU128 | x + y) ;
7475
76+ if total_stake. is_zero ( ) {
77+ return self ;
78+ }
79+
7580 for ( stake_id, _) in self . collateral . iter ( ) {
7681 let stake = self . stake ( stake_id) ;
7782 let reward = ( stake * reward) / total_stake;
@@ -95,6 +100,12 @@ impl IdealRewardPool {
95100 self
96101 }
97102
103+ pub fn accept_new_issues ( & mut self , vault : & VaultId , accept_new_issues : bool ) -> & mut Self {
104+ log:: debug!( "accept_new_issues {:?}" , accept_new_issues) ;
105+ self . accept_new_issues . insert ( vault. clone ( ) , accept_new_issues) ;
106+ self
107+ }
108+
98109 pub fn get_total_reward_for ( & self , account : & crate :: AccountId ) -> u128 {
99110 self . rewards
100111 . get ( account)
@@ -132,9 +143,13 @@ impl IdealRewardPool {
132143
133144 pub fn stake ( & self , ( vault_id, nominator_id) : & StakeId ) -> FixedU128 {
134145 let currency_id = vault_id. collateral_currency ( ) ;
135- let threshold = self . secure_threshold [ vault_id] ;
136- let exchange_rate = self . exchange_rate [ & currency_id] ;
137- let collateral = self . collateral [ & ( vault_id. clone ( ) , nominator_id. clone ( ) ) ] ;
138- FixedU128 :: from ( collateral) / threshold / exchange_rate
146+ if !self . accept_new_issues . get ( vault_id) . unwrap_or ( & true ) {
147+ Zero :: zero ( )
148+ } else {
149+ let threshold = self . secure_threshold [ vault_id] ;
150+ let exchange_rate = self . exchange_rate [ & currency_id] ;
151+ let collateral = self . collateral [ & ( vault_id. clone ( ) , nominator_id. clone ( ) ) ] ;
152+ FixedU128 :: from ( collateral) / threshold / exchange_rate
153+ }
139154 }
140155}
0 commit comments