Skip to content

Commit

Permalink
Merge pull request #15 from RoboRambo/rambo/upgrade_math_crate
Browse files Browse the repository at this point in the history
math pr change
  • Loading branch information
enthusiastmartin committed Mar 9, 2021
2 parents 9e06e30 + 527663a commit 773d9aa
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions pallets/amm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ decl_module! {
let total_liquidity = Self::total_liquidity(&pair_account);

let amount_b_required = hydra_dx_math::calculate_liquidity_in(asset_a_reserve, asset_b_reserve, amount_a)
// TODO: map errors correctly
.map_err(|error| {
.map_err(|_| {
Error::<T>::AddAssetAmountInvalid
})?;

Expand Down Expand Up @@ -368,8 +367,7 @@ decl_module! {
let asset_b_reserve = T::Currency::free_balance(asset_b, &pair_account);

let liquidity_out = hydra_dx_math::calculate_liquidity_out(asset_a_reserve, asset_b_reserve, liquidity_amount, total_shares)
// TODO: map errors correctly
.map_err(|error| {
.map_err(|_| {
Error::<T>::RemoveAssetAmountInvalid
})?;

Expand Down Expand Up @@ -498,8 +496,7 @@ impl<T: Config> AMM<T::AccountId, AssetId, AssetPair, Balance> for Module<T> {
let asset_a_reserve = T::Currency::free_balance(asset_a, &pair_account);
let asset_b_reserve = T::Currency::free_balance(asset_b, &pair_account);

// TODO: refactor
hydra_dx_math::calculate_spot_price(asset_a_reserve, asset_b_reserve, amount).unwrap()
hydra_dx_math::calculate_spot_price(asset_a_reserve, asset_b_reserve, amount).unwrap_or(Balance::zero())
}

fn validate_sell(
Expand Down Expand Up @@ -538,8 +535,7 @@ impl<T: Config> AMM<T::AccountId, AssetId, AssetPair, Balance> for Module<T> {

let transfer_fee = Self::calculate_fees(amount, discount, &mut hdx_amount)?;

let sale_price = hydra_dx_math::calculate_out_given_in(asset_in_total, asset_out_total, amount - transfer_fee).map_err(|error| {
// TODO: map errors correctly
let sale_price = hydra_dx_math::calculate_out_given_in(asset_in_total, asset_out_total, amount - transfer_fee).map_err(|_| {
Error::<T>::SellAssetAmountInvalid
})?;

Expand All @@ -559,8 +555,7 @@ impl<T: Config> AMM<T::AccountId, AssetId, AssetPair, Balance> for Module<T> {
let asset_reserve = T::Currency::free_balance(assets.asset_in, &hdx_pair_account);

let hdx_fee_spot_price = hydra_dx_math::calculate_spot_price(asset_reserve, hdx_reserve, hdx_amount)
// TODO: map errors correctly
.map_err(|error| {
.map_err(|_| {
Error::<T>::CannotApplyDiscount
})?;

Expand Down Expand Up @@ -662,8 +657,7 @@ impl<T: Config> AMM<T::AccountId, AssetId, AssetPair, Balance> for Module<T> {
);

let buy_price = hydra_dx_math::calculate_in_given_out(asset_out_reserve, asset_in_reserve, amount + transfer_fee)
// TODO: map errors correctly
.map_err(|error| {
.map_err(|_| {
Error::<T>::BuyAssetAmountInvalid
})?;

Expand All @@ -686,8 +680,7 @@ impl<T: Config> AMM<T::AccountId, AssetId, AssetPair, Balance> for Module<T> {
let asset_reserve = T::Currency::free_balance(assets.asset_out, &hdx_pair_account);

let hdx_fee_spot_price = hydra_dx_math::calculate_spot_price(asset_reserve, hdx_reserve, hdx_amount)
// TODO: map errors correctly
.map_err(|error| {
.map_err(|_| {
Error::<T>::CannotApplyDiscount
})?;

Expand Down

0 comments on commit 773d9aa

Please sign in to comment.