|
1 | 1 | use std::io::Write; |
2 | 2 |
|
3 | | -use namada_core::dec::Dec; |
4 | 3 | use namada_core::token::DenominatedAmount; |
| 4 | +use namada_core::uint::Uint; |
5 | 5 |
|
6 | 6 | /// Default value for the native currency code |
7 | 7 | const DEFAULT_NATIVE_CODE: &str = "NAM"; |
@@ -68,6 +68,16 @@ pub fn main() -> std::io::Result<()> { |
68 | 68 | .map_err(std::io::Error::other)? |
69 | 69 | }; |
70 | 70 |
|
| 71 | + // Get the exchange rate for the native token |
| 72 | + print!("Exchange rate USD/{}: ", native_code); |
| 73 | + std::io::stdout().flush()?; |
| 74 | + let mut native_exchange_rate = String::new(); |
| 75 | + stdin.read_line(&mut native_exchange_rate)?; |
| 76 | + let native_exchange_rate = native_exchange_rate |
| 77 | + .trim() |
| 78 | + .parse::<DenominatedAmount>() |
| 79 | + .map_err(std::io::Error::other)?; |
| 80 | + |
71 | 81 | // Let S be the total supply of NAM |
72 | 82 | print!("Native token supply in {}: ", native_code); |
73 | 83 | std::io::stdout().flush()?; |
@@ -113,6 +123,16 @@ pub fn main() -> std::io::Result<()> { |
113 | 123 | .map_err(std::io::Error::other)? |
114 | 124 | }; |
115 | 125 |
|
| 126 | + // Get the exchange rate for the incentivised token |
| 127 | + print!("Exchange rate USD/{}: ", incent_code); |
| 128 | + std::io::stdout().flush()?; |
| 129 | + let mut incent_exchange_rate = String::new(); |
| 130 | + stdin.read_line(&mut incent_exchange_rate)?; |
| 131 | + let incent_exchange_rate = incent_exchange_rate |
| 132 | + .trim() |
| 133 | + .parse::<DenominatedAmount>() |
| 134 | + .map_err(std::io::Error::other)?; |
| 135 | + |
116 | 136 | // Let X be the target amount of TOK locked in the MASP |
117 | 137 | print!("Target locked amount in {}: ", incent_code); |
118 | 138 | std::io::stdout().flush()?; |
@@ -186,14 +206,46 @@ pub fn main() -> std::io::Result<()> { |
186 | 206 | std::io::stdout().flush()?; |
187 | 207 | let mut precision = String::new(); |
188 | 208 | stdin.read_line(&mut precision)?; |
189 | | - let precision = precision |
190 | | - .trim() |
191 | | - .parse::<Dec>() |
| 209 | + let precision = Uint::from_str_radix(precision.trim(), 10) |
192 | 210 | .map_err(std::io::Error::other)?; |
| 211 | + |
| 212 | + // A reward of I*P/X uNAM is obtained for every P TOK locked in the pool |
| 213 | + let reward_per_precision = (inflation.amount().raw_amount() * precision) |
| 214 | + / lock_target.amount().raw_amount(); |
| 215 | + let precision = |
| 216 | + DenominatedAmount::new(precision.into(), incent_decimals.into()); |
| 217 | + let reward_per_precision = DenominatedAmount::new( |
| 218 | + reward_per_precision.into(), |
| 219 | + native_decimals.into(), |
| 220 | + ); |
| 221 | + let precision_usd = precision.checked_mul(incent_exchange_rate).ok_or( |
| 222 | + std::io::Error::other("unable to multiply precision by exchange rate"), |
| 223 | + )?; |
| 224 | + let reward_usd_per_precision = reward_per_precision |
| 225 | + .checked_mul(native_exchange_rate) |
| 226 | + .ok_or(std::io::Error::other( |
| 227 | + "unable to multiply minimum reward by exchange rate", |
| 228 | + ))?; |
| 229 | + let exchanged_reward_rate = reward_usd_per_precision |
| 230 | + .checked_div(precision_usd) |
| 231 | + .ok_or(std::io::Error::other("unable to divide "))?; |
| 232 | + // Summarise the rewards from the perrspective of end-users |
193 | 233 | println!( |
194 | | - "Users holding at least {} {} in the shielded pool will receive \ |
195 | | - rewards.", |
196 | | - precision, incent_code |
| 234 | + "For every {} {} held in the shielded pool, a shielded reward of {} \ |
| 235 | + {} will be distributed every MASP epoch. Concretely this means that \ |
| 236 | + for every {} USD worth of {} held in the shielded pool, a {} \ |
| 237 | + shielded reward worth {} USD will be rewarded. Hence there's \ |
| 238 | + effectively a reward rate of {} when all quantities are expressed in \ |
| 239 | + the same units.", |
| 240 | + precision, |
| 241 | + incent_code, |
| 242 | + reward_per_precision, |
| 243 | + native_code, |
| 244 | + precision_usd, |
| 245 | + incent_code, |
| 246 | + native_code, |
| 247 | + reward_usd_per_precision, |
| 248 | + exchanged_reward_rate, |
197 | 249 | ); |
198 | 250 |
|
199 | 251 | // It must be that S*C/Y >= I, which implies that the reward rate |
|
0 commit comments