Skip to content

Commit af8643e

Browse files
tvinagrezizou0x
andauthored
feat: Implement UniswapV4 Native integration (propeller-heads#125)
* feat: initial data structure + ABI & buf models * feat: initial modules: identify new pools and events * feat: map liquidity and balance changes, introduce balance delta calculation from liquidity * feat: map tick deltas * chore: undo weird formatting * chore: undo weird formatting * feat: map fee changes and aggregate data to final block structure * feat: reimplement math natively, remove alloy and univ3sdk dependencies * chore: make clippy happy + misc improvements * chore: add rust generated files from buf & ABI * chore: make clippy happy * feat: add all modules to ethereum-uniswap-v4.yaml * chore: update yaml file to skip unnecessary buf paths * fix: update pb mod.rs * fix: fix hex / utf-8 encoding. working version * fix: simplify error handling, rename yaml file to match chain & formatting * fix: fix ChangeType for sqrt_price_x96 on Initialization * fix: make fee a non-static attribute * fix: add balance_owner to univ4 pool * feat: add uniswap-v4 mainnet yaml * fix(uniswap-v4): miscellaneous fixes for UniswapV4 (propeller-heads#147) * fix(uniswap-v4): correctly decode swap event deltas. Deltas are given from a user debt perspective by the event (negative if received by the pool, positive if sent by the pool). In our usecase we need the opposite of this. This commit uses `.neg()` on the amount to apply them correctly. * fix(uniswap-v4): correctly compute token amounts. We were using `get_sqrt_ratio_at_tick` at the current tick to compute the amounts. This was incorrect because it provides the price at the tick boundary, but we might be mid-tick, which could lead to erroneous balances. We now track the current price (updated by `initialization` and `swap` events) and use it when calculating the amounts. * fix(uniswapv4): do not account for fees in swaps. Previously we were adding fees as balances. But they are actually not part of the TVL and we aren't accounting for fees in the position changes (withdrawals). This commit addresses this and remove the fees from the token balances. * refactor: fix pb mod.rs * refactor: bump version and update sepolia config * ci: make clippy happy * refactor: clean unimath tests * refactor: make logic clearer and improve docstrings --------- Co-authored-by: zizou <111426680+flopell@users.noreply.github.com> --------- Co-authored-by: Zizou <111426680+zizou0x@users.noreply.github.com> Co-authored-by: zizou <111426680+flopell@users.noreply.github.com>
1 parent e413284 commit af8643e

27 files changed

+9541
-148
lines changed

substreams/Cargo.lock

Lines changed: 341 additions & 148 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substreams/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"ethereum-sfrax",
1111
"ethereum-sfraxeth",
1212
"ethereum-uniswap-v3-logs-only",
13+
"ethereum-uniswap-v4"
1314
]
1415
resolver = "2"
1516

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "ethereum-uniswap-v4"
3+
version = "0.1.1"
4+
edition = "2021"
5+
6+
[lib]
7+
name = "ethereum_uniswap_v4"
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
substreams = "0.5.22"
12+
substreams-ethereum = "0.9.9"
13+
prost = "0.11"
14+
ethabi = "18.0.0"
15+
anyhow = "1.0.75"
16+
hex-literal = "0.4.1"
17+
substreams-helper = { git = "https://github.com/propeller-heads/tycho-protocol-sdk.git", rev = "b8aeaa3" }
18+
tycho-substreams = { git = "https://github.com/propeller-heads/tycho-protocol-sdk.git", rev = "b8aeaa3" }
19+
num-bigint = "0.4.4"
20+
hex = "0.4.3"
21+
tiny-keccak = "2.0"
22+
substreams-entity-change = "1.3"
23+
itertools = "0.13.0"
24+
25+
[dev-dependencies]
26+
rstest = "0.24.0"
27+
28+
[target.wasm32-unknown-unknown.dependencies]
29+
getrandom = { version = "0.2", features = ["custom"] }
30+
31+
[build-dependencies]
32+
anyhow = "1.0.75"
33+
substreams-ethereum = "0.9.9"

0 commit comments

Comments
 (0)