Skip to content

Commit

Permalink
Merge pull request #216 from 0xDmtri/main
Browse files Browse the repository at this point in the history
feature(Uniswap):  impl .get_token_out()
  • Loading branch information
0xKitsune authored Sep 10, 2024
2 parents a55f895 + bc94826 commit a4edb40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/amm/uniswap_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ impl UniswapV2Pool {
Ok(token1)
}

pub fn get_token_out(&self, token_in: Address) -> Address {
if self.token_a == token_in {
self.token_b
} else {
self.token_a
}
}

/// Calculates the price of the base token in terms of the quote token.
///
/// Returned as a Q64 fixed point number.
Expand Down
9 changes: 9 additions & 0 deletions src/amm/uniswap_v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,15 @@ impl UniswapV3Pool {

Ok(token_1)
}

pub fn get_token_out(&self, token_in: Address) -> Address {
if self.token_a == token_in {
self.token_b
} else {
self.token_a
}
}

/* Legend:
sqrt(price) = sqrt(y/x)
L = sqrt(x*y)
Expand Down

0 comments on commit a4edb40

Please sign in to comment.