-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from propeller-heads/zz/uniswap_v4/add-state-…
…struct feat(uniswap_v4): Implement `UniswapV4State` struct
- Loading branch information
Showing
10 changed files
with
89 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use alloy_primitives::U256; | ||
|
||
use crate::evm::protocol::utils::uniswap::tick_list::{TickInfo, TickList}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct UniswapV4State { | ||
liquidity: u128, | ||
sqrt_price: U256, | ||
lp_fee: i32, | ||
protocol_fees: UniswapV4ProtocolFees, | ||
tick: i32, | ||
ticks: TickList, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct UniswapV4ProtocolFees { | ||
zero2one: i32, | ||
one2zero: i32, | ||
} | ||
|
||
impl UniswapV4ProtocolFees { | ||
pub fn new(zero2one: i32, one2zero: i32) -> Self { | ||
Self { zero2one, one2zero } | ||
} | ||
} | ||
|
||
impl UniswapV4State { | ||
/// Creates a new `UniswapV4State` with specified values. | ||
pub fn new( | ||
liquidity: u128, | ||
sqrt_price: U256, | ||
lp_fee: i32, | ||
protocol_fees: UniswapV4ProtocolFees, | ||
tick: i32, | ||
tick_spacing: i32, | ||
ticks: Vec<TickInfo>, | ||
) -> Self { | ||
let tick_list = TickList::from( | ||
tick_spacing | ||
.try_into() | ||
// even though it's given as int24, tick_spacing must be positive, see here: | ||
// https://github.com/Uniswap/v4-core/blob/a22414e4d7c0d0b0765827fe0a6c20dfd7f96291/src/libraries/TickMath.sol#L25-L28 | ||
.expect("tick_spacing should always be positive"), | ||
ticks, | ||
); | ||
UniswapV4State { liquidity, sqrt_price, lp_fee, protocol_fees, tick, ticks: tick_list } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub(crate) mod uniswap; | ||
|
||
use alloy_primitives::Address; | ||
use tycho_core::Bytes; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub(crate) mod tick_list; | ||
pub(crate) mod tick_math; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters