Skip to content

Commit

Permalink
Prevent YIsZero error in v2 price calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOsiris committed May 8, 2023
1 parent f85831c commit 2b787df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/amm/uniswap_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,17 @@ impl UniswapV2Pool {
};

if base_token == self.token_a {
div_uu(r_1, r_0)
if r_0.is_zero() {
Ok(U128_0X10000000000000000)
} else {
div_uu(r_1, r_0)
}
} else {
div_uu(r_0, r_1)
if r_1.is_zero() {
Ok(U128_0X10000000000000000)
} else {
div_uu(r_0, r_1)
}
}
}

Expand Down

0 comments on commit 2b787df

Please sign in to comment.