pub fn calculate_in_given_out(
    out_reserve: u128,
    in_reserve: u128,
    amount_out: u128
) -> Result<u128, MathError>
Expand description

Calculating amount to be sent to the pool given the amount to be received from the pool and both reserves. Formula : IN_RESERVE * AMOUNT_OUT / (OUT_RESERVE - AMOUNT_OUT) + 1

  • in_reserve - reserve amount of selling asset
  • out_reserve - reserve amount of buying asset
  • amount_out - buy amount

Returns MathError in case of error